This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
Form1.cs
79 lines (64 loc) · 2.44 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#region #reference
using System.Windows.Forms;
using System;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...
#endregion #reference
namespace RuntimeBindingToMdbDatabase {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
#region #code
private SqlDataSource BindToData() {
// Create a data source with the required connection parameters.
Access97ConnectionParameters connectionParameters =
new Access97ConnectionParameters("../../nwind.mdb", "", "");
SqlDataSource ds = new SqlDataSource(connectionParameters);
// Create an SQL query to access the Products table.
CustomSqlQuery query = new CustomSqlQuery();
query.Name = "customQuery";
query.Sql = "SELECT * FROM Products";
// Add the query to the collection and return the data source.
ds.Queries.Add(query);
// Make the data source structure displayed
// in the Field List of an End-User Report Designer.
ds.RebuildResultSchema();
return ds;
}
private XtraReport CreateReport() {
// Create a new report instance.
XtraReport report = new XtraReport();
// Assign the data source to the report.
report.DataSource = BindToData();
report.DataMember = "customQuery";
// Add a detail band to the report.
DetailBand detailBand = new DetailBand();
detailBand.Height = 50;
report.Bands.Add(detailBand);
// Create a new label.
XRLabel label = new XRLabel { WidthF = 300 };
// Specify the label's binding depending on the data binding mode.
if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings)
label.DataBindings.Add("Text", null, "customQuery.ProductName");
else label.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
// Add the label to the detail band.
detailBand.Controls.Add(label);
return report;
}
private void button1_Click(object sender, EventArgs e) {
// Show the report's print preview.
ReportPrintTool printTool = new ReportPrintTool(CreateReport());
printTool.ShowPreview();
}
private void button2_Click(object sender, EventArgs e) {
// Open the report in an End-User Designer.
ReportDesignTool designTool = new ReportDesignTool(CreateReport());
designTool.ShowRibbonDesignerDialog();
}
#endregion #code
}
}