-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInstantReportWizardCustomizationService.cs
78 lines (72 loc) · 3.72 KB
/
InstantReportWizardCustomizationService.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
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.ReportDesigner.DataContracts;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.XtraReports.Wizards;
using ReportWizardCustomizationServiceMvcExample.PredefinedReports;
using System;
using System.Linq;
using System.Threading.Tasks;
public class InstantReportWizardCustomizationService : ReportWizardCustomizationService {
public enum CustomReportType {
CustomLabelReport,
InstantReport
}
public override XtraReport TryCreateCustomReport(XtraReportModel model, object dataSource, string dataMember, CustomWizardData customWizardData, XtraReport report) {
if (Enum.TryParse(customWizardData.ReportTemplateID, out CustomReportType customReportType)) {
if (customReportType == CustomReportType.InstantReport) {
return new InstantReport() {
Name = customWizardData.ReportTemplateID,
DisplayName = customWizardData.ReportTemplateID
};
}
else if (customReportType == CustomReportType.CustomLabelReport) {
var labelReport = new LabelReport();
labelReport.ApplyCustomData(customWizardData.Data);
return labelReport;
}
}
return base.TryCreateCustomReport(model, dataSource, dataMember, customWizardData, report);
}
public override Task<XtraReport> TryCreateCustomReportAsync(XtraReportModel model, object dataSource, string dataMember, CustomWizardData customWizardData, XtraReport report) {
return Task.FromResult(TryCreateCustomReport(model, dataSource, dataMember, customWizardData, report));
}
public override void CustomizeReportTypeList(ReportWizardTemplateCollection predefinedTypes) {
predefinedTypes.Remove(predefinedTypes.Where(x => x.ID == nameof(ReportType.CrossTab)).First());
predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
CanInstantlyFinish = true,
ID = nameof(CustomReportType.InstantReport),
Text = "Instant Report",
ImageTemplateName = "instant-report"
});
predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
CanInstantlyFinish = true,
ID = nameof(CustomReportType.InstantReport),
Text = "Instant Report",
ImageClassName = "instant-report-image"
});
predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
ID = nameof(CustomReportType.CustomLabelReport),
Text = "Custom Label Report",
ImageTemplateName = "dxrd-svg-wizard-LabelReport"
});
}
public override Task CustomizeReportTypeListAsync(ReportWizardTemplateCollection predefinedTypes) {
CustomizeReportTypeList(predefinedTypes);
return Task.CompletedTask;
}
public override void CustomizeReportOnFinish(XtraReport report) {
if (report.Bands.GetBandByType(typeof(ReportHeaderBand)) == null)
report.Bands.Add(new ReportHeaderBand() {
Controls = {
new XRLabel() {
Text = string.Format("Instant Report {0:MMM dd}", System.DateTime.Today),
SizeF= new System.Drawing.SizeF(650F, 100F),
Font = new DevExpress.Drawing.DXFont("Arial", 24)
} }
}); ; ;
}
public override Task CustomizeReportOnFinishAsync(XtraReport report) {
CustomizeReportOnFinish(report);
return Task.CompletedTask;
}
}