-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomWebDocumentViewerReportResolver.cs
95 lines (91 loc) · 3.8 KB
/
CustomWebDocumentViewerReportResolver.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
using DevExpress.DataAccess.ObjectBinding;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.WebDocumentViewer;
namespace Reporting_ObjectDS_Mvc
{
public class CustomWebDocumentViewerReportResolver : IWebDocumentViewerReportResolver
{
public XtraReport Resolve(string reportEntry)
{
if (reportEntry.StartsWith("EmployeeReport"))
{
XtraReport rep = CreateReport(reportEntry);
rep.DataSource = CreateObjectDataSource(reportEntry);
return rep;
}
return new XtraReport();
}
private object CreateObjectDataSource(string reportName)
{
if (reportName == "EmployeeReport")
{
ObjectDataSource dataSource = new ObjectDataSource();
dataSource.Name = "EmployeeObjectDS";
dataSource.DataSource = typeof(Employees.EmployeeList);
dataSource.Constructor = ObjectConstructorInfo.Default;
dataSource.DataMember = "Items";
return dataSource;
}
else
if (reportName.EndsWith("7"))
{
ObjectDataSource dataSource = new ObjectDataSource();
dataSource.Name = "EmployeeObjectDS";
dataSource.DataSource = typeof(Employees.EmployeeList);
// Specify the parameter's default value.
var parameter = new Parameter("noOfItems", typeof(int), 7);
dataSource.Constructor = new ObjectConstructorInfo(parameter);
dataSource.DataMember = "Items";
return dataSource;
}
else
if (reportName.EndsWith("Parameter"))
{
ObjectDataSource dataSource = new ObjectDataSource();
dataSource.Name = "EmployeeObjectDS";
dataSource.DataSource = typeof(Employees.EmployeeList);
// Map data source parameter to report's parameter.
var parameter = new Parameter()
{
Name = "noOfItems",
Type = typeof(DevExpress.DataAccess.Expression),
Value = new DevExpress.DataAccess.Expression("?parameterNoOfItems", typeof(int))
};
dataSource.Constructor = new ObjectConstructorInfo(parameter);
dataSource.DataMember = "Items";
return dataSource;
}
else
{
ObjectDataSource dataSource = new ObjectDataSource();
dataSource.Name = "EmployeeObjectDS";
dataSource.DataSource = typeof(Employees.EmployeeList);
var parameterNoOfItems = new Parameter("noOfItems", typeof(int), 12);
dataSource.Parameters.Add(parameterNoOfItems);
dataSource.DataMember = "GetData";
dataSource.Constructor = ObjectConstructorInfo.Default;
return dataSource;
}
}
private XtraReport CreateReport(string reportEntry)
{
if (reportEntry.Contains("Parameter"))
{
XtraReport report = new PredefinedReports.EmployeeReport();
DevExpress.XtraReports.Parameters.Parameter param =
new DevExpress.XtraReports.Parameters.Parameter()
{
Name = "parameterNoOfItems",
Type = typeof(int),
Value = 5
};
param.Description = "Number of Items";
report.Parameters.Add(param);
report.RequestParameters = false;
return report;
}
else
return new PredefinedReports.EmployeeReport();
}
}
}