-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChoosePageSettingsPage.cs
95 lines (80 loc) · 3.84 KB
/
ChoosePageSettingsPage.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 System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing.Printing;
using System.Linq;
using DevExpress.Data.WizardFramework;
using DevExpress.DataAccess.Wizard.Presenters;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.XtraReports.Wizards;
namespace CustomReportWizard {
class ChoosePageSettingsPage<TModel> : WizardPageBase<IChoosePageSettingsPageView, TModel>, IWizardPage<XtraReportModel>
where TModel : CustomReportModel { XtraReportModel IWizardPage<XtraReportModel>.Model
{ get { return Model; } set { Model = (TModel)value; } }
public ChoosePageSettingsPage(IChoosePageSettingsPageView view) : base(view) { }
public override bool FinishEnabled { get { return Model.ReportType == ReportType.Empty; } }
public override bool MoveNextEnabled { get { return Model.ReportType != ReportType.Empty; } }
public override Type GetNextPageType() { return Model.ReportType == ReportType.Empty
? null
: typeof(ChooseDataSourceTypePage<XtraReportModel>); }
public override void Begin() {
View.PaperKind = Model.PaperKind;
View.Portrait = Model.Portrait;
View.PageMargins = Model.PageMargins;
}
public override void Commit() {
Model.PaperKind = View.PaperKind;
Model.Portrait = View.Portrait;
Model.PageMargins = View.PageMargins;
}
}
interface IChoosePageSettingsPageView {
PaperKind PaperKind { get; set; }
bool Portrait { get; set; }
Margins PageMargins { get; set; }
}
[POCOViewModel(ImplementIDataErrorInfo = true)]
public class ChoosePageSettingsPageViewModel : DevExpress.Xpf.DataAccess.DataSourceWizard.WizardPageBase,
IChoosePageSettingsPageView {
public override string Description { get { return "Choose the required page settings."; } }
public virtual IEnumerable<PaperKindViewInfo> AvailablePaperKinds {get; protected set;}
public virtual PaperKindViewInfo SelectedPaperKind { get; set; }
public virtual bool Portrait { get; set; }
[Range(0,300)]
public virtual int LeftMargin { get; set; }
[Range(0, 300)]
public virtual int RightMargin { get; set; }
[Range(0, 300)]
public virtual int TopMargin { get; set; }
[Range(0, 300)]
public virtual int BottomMargin { get; set; }
PaperKind IChoosePageSettingsPageView.PaperKind {
get { return (PaperKind)SelectedPaperKind.Id; }
set { SetPaperKind(value); }
}
Margins IChoosePageSettingsPageView.PageMargins {
get { return new Margins(LeftMargin, RightMargin, TopMargin, BottomMargin); }
set { SetMargins(value); }
}
public ChoosePageSettingsPageViewModel() {
var printerSettings = new PrinterSettings();
AvailablePaperKinds = printerSettings.PaperSizes.Cast<PaperSize>().Select(paperSize => {
return new PaperKindViewInfo() {
Id = (int)paperSize.Kind,
DisplayName = paperSize.PaperName,
SizeText = string.Format("{0}x{1}", paperSize.Width, paperSize.Height) };
}).ToArray();
}
void SetPaperKind(PaperKind value) {
var info = AvailablePaperKinds.SingleOrDefault(x => (PaperKind)x.Id == value)
?? AvailablePaperKinds.Single(x => (PaperKind)x.Id == PaperKind.Letter);
SelectedPaperKind = info;
}
void SetMargins(Margins value) {
LeftMargin = value.Left;
RightMargin = value.Right;
TopMargin = value.Top;
BottomMargin = value.Bottom;
}
}
}