-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefault.aspx.cs
126 lines (115 loc) · 4.85 KB
/
Default.aspx.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DXWebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
InitializeReportDesigner();
}
private void InitializeReportDesigner()
{
string reportParameterName = "reportParameter1";
// The data source parameter name should match the name of the variable passed to the data source constructor.
string dataSourceParameterName = "p1";
var objectDS = GenerateObjectDataSource(reportParameterName, dataSourceParameterName);
// Uncomment the following line to register the object data source
// (if end-users are allowed to create new reports bound to this data source).
// ASPxReportDesigner1.DataSources.Add("ObjectDataSource1", objectDS);
ASPxReportDesigner1.OpenReport(GenerateReport("reportParameter1", objectDS));
}
private XtraReport GenerateReport(string parameterName, object dataSource)
{
XtraReport report = new XtraReport();
report.DataSource = dataSource;
report.Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
{
Name = parameterName,
Type = typeof(int),
Value = 5 // Specify the default value for the report parameter.
});
report.RequestParameters = false;
CreateReportControls(parameterName, report);
return report;
}
private object GenerateObjectDataSource(string reportParamName, string dataSourceParamName)
{
DevExpress.DataAccess.ObjectBinding.ObjectDataSource objds = new DevExpress.DataAccess.ObjectBinding.ObjectDataSource();
objds.Name = "ObjectDataSource1";
objds.DataMember = "Items";
objds.DataSource = typeof(DemoModel);
// Uncomment the following line to explicitly specify the object data source parameter value.
// var p = new DevExpress.DataAccess.ObjectBinding.Parameter("p1", typeof(int), 3);
// The following code maps a data source parameter to the report parameter.
var p = new DevExpress.DataAccess.ObjectBinding.Parameter(
dataSourceParamName,
typeof(DevExpress.DataAccess.Expression),
new DevExpress.DataAccess.Expression("[Parameters." + reportParamName + "]", typeof(int)));
objds.Constructor = new DevExpress.DataAccess.ObjectBinding.ObjectConstructorInfo(p);
return objds;
}
private static void CreateReportControls(string parameterName, XtraReport report)
{
var pageHeader = new PageHeaderBand();
var paramValueLbl = new XRLabel()
{
Name = "label1",
Borders = DevExpress.XtraPrinting.BorderSide.Bottom,
Font = new System.Drawing.Font("Calibri", 18f),
SizeF = new System.Drawing.SizeF(200, 50),
LocationF = new System.Drawing.PointF(5, 5)
};
paramValueLbl.ExpressionBindings.Add(
new DevExpress.XtraReports.UI.ExpressionBinding("Text", "?" + parameterName));
paramValueLbl.TextFormatString = "Parameter value: {0}";
pageHeader.Controls.Add(paramValueLbl);
report.Bands.Add(pageHeader);
var detail1 = new DetailBand();
var xrLabel1 = new XRLabel()
{
Name = "label1",
Font = new System.Drawing.Font("Calibri", 18f),
SizeF = new System.Drawing.SizeF(200, 50),
LocationF = new System.Drawing.PointF(0, 0)
};
xrLabel1.ExpressionBindings.Add(
new DevExpress.XtraReports.UI.ExpressionBinding("Text", "[Name]"));
xrLabel1.TextFormatString = "Name: {0}";
detail1.Controls.Add(xrLabel1);
report.Bands.Add(detail1);
}
}
public class DemoModel
{
public ItemList Items { get; set; }
public DemoModel(int p1)
{
Items = new ItemList(p1);
}
}
public class ItemList : List<Item>
{
public ItemList()
: this(10)
{
}
public ItemList(int itemNumber)
{
for (int i = 0; i < itemNumber; i++)
{
Add(new Item() { Name = i.ToString() });
}
}
}
public class Item
{
public string Name { get; set; }
}
}