-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathReportHelper.cs
More file actions
63 lines (60 loc) · 3.28 KB
/
ReportHelper.cs
File metadata and controls
63 lines (60 loc) · 3.28 KB
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
using DevExpress.XtraReports.UI;
using System;
using System.Drawing;
namespace GridExportingWithReports.Helpers {
public class ReportHelper {
public static void CreateReport(XtraReport report, string[] fields) {
PageHeaderBand pageHeader = new PageHeaderBand() { HeightF = 23, Name = "pageHeaderBand" };
int tableWidth = (int)(report.PageWidth - report.Margins.Left - report.Margins.Right);
XRTable headerTable = XRTable.CreateTable(
new Rectangle(0, // rect X
0, // rect Y
tableWidth, // width
40), // height
1, // table row count
0); // table column count
headerTable.Borders = DevExpress.XtraPrinting.BorderSide.All;
headerTable.BackColor = Color.Gainsboro;
headerTable.Font = new Font("Verdana", 10, FontStyle.Bold);
headerTable.Rows.FirstRow.Width = tableWidth;
headerTable.BeginInit();
foreach (string field in fields) {
XRTableCell cell = new XRTableCell();
cell.Width = 100;
cell.Text = field;
cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
headerTable.Rows.FirstRow.Cells.Add(cell);
}
headerTable.EndInit();
headerTable.AdjustSize();
pageHeader.Controls.Add(headerTable);
DetailBand detail = new DetailBand() { HeightF = 23, Name = "detailBand" };
XRTable detailTable = XRTable.CreateTable(
new Rectangle(0, // rect X
0, // rect Y
tableWidth, // width
40), // height
1, // table row count
0); // table column count
detailTable.Width = tableWidth;
detailTable.Rows.FirstRow.Width = tableWidth;
detailTable.Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom;
detailTable.BeginInit();
foreach (string field in fields) {
XRTableCell cell = new XRTableCell();
ExpressionBinding binding = new ExpressionBinding("BeforePrint", "Text", String.Format("[{0}]", field));
cell.ExpressionBindings.Add(binding);
cell.Width = 100;
cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
if (field.Contains("Date"))
cell.TextFormatString = "{0:MM/dd/yyyy}";
detailTable.Rows.FirstRow.Cells.Add(cell);
}
detailTable.Font = new Font("Verdana", 8F);
detailTable.EndInit();
detailTable.AdjustSize();
detail.Controls.Add(detailTable);
report.Bands.AddRange(new Band[] { detail, pageHeader });
}
}
}