-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomReportProvider.cs
81 lines (79 loc) · 3 KB
/
CustomReportProvider.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
using DevExpress.DataAccess.Sql;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.Services;
using DevExpress.XtraReports.UI;
using System.Drawing;
namespace ReportAtRuntimeMvcApp.Services
{
public class CustomReportProvider : DevExpress.XtraReports.Services.IReportProvider
{
public XtraReport GetReport(string id, ReportProviderContext context)
{
if (string.IsNullOrEmpty(id))
return null;
switch (id)
{
case "TestReport":
return CreateProductsReport();
}
return new XtraReport();
}
XtraReport CreateProductsReport()
{
XtraReport report = new XtraReport();
ReportHeaderBand headerBand = new ReportHeaderBand()
{
HeightF = 80
};
report.Bands.Add(headerBand);
headerBand.Controls.Add(new XRLabel()
{
Text = "Categories Report",
SizeF = new SizeF(650, 80),
TextAlignment = TextAlignment.BottomCenter,
Font = new Font("Arial", 36)
});
DetailBand detailBand = new DetailBand();
report.Bands.Add(detailBand);
XRPictureBox pbPicture = new XRPictureBox()
{
LocationF = new PointF(10, 10),
SizeF = new SizeF(190, 90),
Sizing = ImageSizeMode.ZoomImage
};
pbPicture.ExpressionBindings.Add(new ExpressionBinding("Image", "Picture"));
detailBand.Controls.Add(pbPicture);
XRLabel lbCategoryName = new XRLabel()
{
LocationF = new PointF(200, 10),
SizeF = new SizeF(440, 50),
TextAlignment = TextAlignment.BottomLeft,
Font = new Font("Arial", 24)
};
lbCategoryName.ExpressionBindings.Add(new ExpressionBinding("Text", "CategoryName"));
detailBand.Controls.Add(lbCategoryName);
XRLabel lbDescription = new XRLabel()
{
LocationF = new PointF(200, 60),
SizeF = new SizeF(440, 40),
TextAlignment = TextAlignment.TopLeft,
Font = new Font("Arial", 14, FontStyle.Italic)
};
lbDescription.ExpressionBindings.Add(new ExpressionBinding("Text", "Description"));
detailBand.Controls.Add(lbDescription);
report.DataSource = CreateDataSource();
report.DataMember = "Categories";
return report;
}
private object CreateDataSource()
{
var ds = new SqlDataSource("nwind");
SelectQuery query = SelectQueryFluentBuilder.AddTable("Categories")
.SelectAllColumns()
.Build("Categories");
ds.Queries.Add(query);
ds.Fill();
return ds;
}
}
}