Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
NumberControlDemo.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System; using System.Collections.Generic; using System.Linq; using EnterpriseWebLibrary.EnterpriseWebFramework; using EnterpriseWebLibrary.WebSessionState; using Humanizer; namespace EnterpriseWebLibrary.WebSite.TestPages { partial class NumberControlDemo: EwfPage { partial class Info { public override string ResourceName => "Number Control"; } protected override void loadData() { ph.AddControlsReturnThis( FormState.ExecuteWithDataModificationsAndDefaultAction( PostBack.CreateFull().ToCollection(), () => { var table = FormItemBlock.CreateFormItemTable( formItems: getControls().Select( ( getter, i ) => getter( ( i + 1 ).ToString() ) ) ); table.IncludeButtonWithThisText = "Submit"; return table; } ), FormItemBlock.CreateFormItemTable( heading: "Independent Controls", formItems: getIndependentControls().Select( ( getter, i ) => getter( "I-" + ( i + 1 ).ToString() ) ) ) ); } private IReadOnlyCollection<Func<string, FormItem>> getControls() => new[] { get( "Standard", null ), get( "[1,2] with .25 step", null, minValue: 1, maxValue: 2, valueStep: .25m ), get( "Placeholder", NumberControlSetup.Create( placeholder: "Type here" ) ), get( "Birthday year auto-fill", NumberControlSetup.Create( autoFillTokens: "bday-year" ) ), get( "Auto-complete", NumberControlSetup.CreateAutoComplete( TestService.GetInfo() ) ), id => { var pb = PostBack.CreateIntermediate( null, id: id ); return FormState.ExecuteWithDataModificationsAndDefaultAction( FormState.Current.DataModifications.Append( pb ), () => get( "Separate value-changed action", NumberControlSetup.Create( valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); }, new Func<Func<string, FormItem>>( () => { var pmv = new PageModificationValue<decimal?>(); return get( "Page modification", NumberControlSetup.Create( pageModificationValue: pmv ), pageModificationValue: pmv ); } )(), get( "Read-only", NumberControlSetup.CreateReadOnly() ), getImprecise( "Imprecise", null ), getImprecise( "Imprecise [1,2] with .25 step", null, minValue: 1, maxValue: 2, valueStep: .25m ), id => { var pb = PostBack.CreateIntermediate( null, id: id ); return FormState.ExecuteWithDataModificationsAndDefaultAction( FormState.Current.DataModifications.Append( pb ), () => getImprecise( "Imprecise with separate value-changed action", ImpreciseNumberControlSetup.Create( valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); }, new Func<Func<string, FormItem>>( () => { var pmv = new PageModificationValue<decimal>(); return getImprecise( "Imprecise with page modification", ImpreciseNumberControlSetup.Create( pageModificationValue: pmv ), pageModificationValue: pmv ); } )(), getImprecise( "Imprecise read-only", ImpreciseNumberControlSetup.CreateReadOnly() ) }; private IReadOnlyCollection<Func<string, FormItem>> getIndependentControls() => new Func<string, FormItem>[] { id => { var pb = PostBack.CreateFull( id: id ); return FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Standard", null )( id ) ); }, id => { var pb = PostBack.CreateFull( id: id ); return FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Auto-complete, triggers action when item selected", NumberControlSetup.CreateAutoComplete( TestService.GetInfo(), triggersActionWhenItemSelected: true ) )( id ) ); }, id => { var pb = PostBack.CreateFull( id: id ); return FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Auto-complete, triggers action when item selected or value changed", NumberControlSetup.CreateAutoComplete( TestService.GetInfo(), triggersActionWhenItemSelected: true, valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); } }; private Func<string, FormItem> get( string label, NumberControlSetup setup, PageModificationValue<decimal?> pageModificationValue = null, decimal? minValue = null, decimal? maxValue = null, decimal? valueStep = null ) => id => new NumberControl( null, true, setup: setup, minValue: minValue, maxValue: maxValue, valueStep: valueStep, validationMethod: ( postBackValue, validator ) => AddStatusMessage( StatusMessageType.Info, "{0}: {1}".FormatWith( id, postBackValue ) ) ).ToFormItem( label: "{0}. {1}".FormatWith( id, label ) .ToComponents() .Concat( pageModificationValue != null ? new LineBreak().ToCollection<PhrasingComponent>() .Append( new SideComments( "Value: ".ToComponents() .Concat( pageModificationValue.ToGenericPhrasingContainer( v => v?.Normalize().ToString() ?? "", valueExpression => "{0}.toString()".FormatWith( valueExpression ) ) ) .Materialize() ) ) : Enumerable.Empty<PhrasingComponent>() ) .Materialize() ); private Func<string, FormItem> getImprecise( string label, ImpreciseNumberControlSetup setup, PageModificationValue<decimal> pageModificationValue = null, decimal? minValue = null, decimal? maxValue = null, decimal? valueStep = null ) => id => new ImpreciseNumberControl( .25m, minValue ?? 0, maxValue ?? 1, setup: setup, valueStep: valueStep, validationMethod: ( postBackValue, validator ) => AddStatusMessage( StatusMessageType.Info, "{0}: {1}".FormatWith( id, postBackValue ) ) ).ToFormItem( label: "{0}. {1}".FormatWith( id, label ) .ToComponents() .Concat( pageModificationValue != null ? new LineBreak().ToCollection<PhrasingComponent>() .Append( new SideComments( "Value: ".ToComponents() .Concat( pageModificationValue.ToGenericPhrasingContainer( v => v.Normalize().ToString(), valueExpression => "{0}.toString()".FormatWith( valueExpression ) ) ) .Materialize() ) ) : Enumerable.Empty<PhrasingComponent>() ) .Materialize() ); } }