-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
92 lines (83 loc) · 3.5 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
80
81
82
83
84
85
86
87
88
89
90
91
92
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraReports.ReportGeneration;
using DevExpress.XtraReports.UI;
using System.Data;
namespace ConvertGridToReportExample
{
public partial class Form1 : RibbonForm
{
public Form1()
{
InitializeComponent();
// This line of code is generated by Data Source Configuration Wizard
// Fill the SqlDataSource asynchronously
sqlDataSource1.FillAsync();
}
private void btnShowPreview_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
XtraReport1 report = CreateReportFromGrid();
ReportPrintTool printTool = new ReportPrintTool(report);
printTool.ShowPreviewDialog(this.GetActiveLookAndFeel());
}
private void btnShowReportDesigner_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
XtraReport1 report = CreateReportFromGrid();
ReportDesignTool designTool = new ReportDesignTool(report);
designTool.ShowDesignerDialog(this.GetActiveLookAndFeel());
}
private XtraReport1 CreateReportFromGrid()
{
object dSource;
string dMember;
if (chkOnlyExpRecords.Checked)
{
dSource = FillDatasetFromGrid();
dMember = null;
}
else
{
dSource = sqlDataSource1;
dMember = sqlDataSource1.Queries[0].Name;
}
XtraReport1 report = new XtraReport1(dSource, dMember, gridView);
return report;
}
private DataTable FillDatasetFromGrid()
{
int rowHandle;
DataTable dTable = new DataTable();
foreach (GridColumn c in gridView.Columns)
dTable.Columns.Add(c.FieldName, c.ColumnType);
for (int r = 0; r < gridView.RowCount; r++)
{
rowHandle = gridView.GetVisibleRowHandle(r);
if (!gridView.IsGroupRow(rowHandle))
{
object[] rowValues = new object[dTable.Columns.Count];
for (int c = 0; c < dTable.Columns.Count; c++)
rowValues[c] = gridView.GetRowCellValue(rowHandle, dTable.Columns[c].ColumnName);
dTable.Rows.Add(rowValues);
}
}
return dTable;
}
private void btnReportGeneratorPreview_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
ReportGenerationOptions options = new ReportGenerationOptions()
{
PrintVerticalLines = DevExpress.Utils.DefaultBoolean.True,
PrintHorizontalLines = DevExpress.Utils.DefaultBoolean.True
};
XtraReport report = ReportGenerator.GenerateReport(gridView, options);
ReportPrintTool printTool = new ReportPrintTool(report);
printTool.ShowPreviewDialog(this.GetActiveLookAndFeel());
}
private void btnReportGeneratorDesigner_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
XtraReport report = ReportGenerator.GenerateReport(gridView);
ReportDesignTool designTool = new ReportDesignTool(report);
designTool.ShowDesignerDialog(this.GetActiveLookAndFeel());
}
}
}