1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
#endregion
|
23
|
|
|
24
|
|
using System;
|
25
|
|
using System.Reflection;
|
26
|
|
using System.Web.UI;
|
27
|
|
using System.Web.UI.WebControls;
|
28
|
|
using ShowX.Config;
|
29
|
|
using ShowX.Model;
|
30
|
|
using ShowX.Web.WebControls;
|
31
|
|
using Calendar = ShowX.Web.WebControls.Calendar;
|
32
|
|
using DataGrid = ShowX.Web.WebControls.DataGrid;
|
33
|
|
|
34
|
|
namespace ShowX.Web.WebBuilders.ItemTemplates
|
35
|
|
{
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
class EditItemTemplate : ITemplate {
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
protected PropertyInfo propertyInfo;
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
175
|
public EditItemTemplate(PropertyInfo propertyInfo)
|
52
|
|
{
|
53
|
175
|
this.propertyInfo = propertyInfo;
|
54
|
|
}
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
20
|
public void InstantiateIn(Control container)
|
62
|
|
{
|
63
|
20
|
IPropertyMap dbattr = Configuration.Session.MappingHandler
|
64
|
|
.GetPropertyMap(propertyInfo);
|
65
|
|
|
66
|
20
|
if (propertyInfo.PropertyType == typeof(Boolean)) {
|
67
|
|
|
68
|
4
|
CheckBox cb = new CheckBox();
|
69
|
4
|
cb.DataBinding += new EventHandler(cb_DataBinding);
|
70
|
4
|
container.Controls.Add(cb);
|
71
|
|
}
|
72
|
16
|
else if (propertyInfo.PropertyType == typeof(DateTime)) {
|
73
|
|
|
74
|
4
|
Calendar date = new Calendar(propertyInfo);
|
75
|
4
|
date.DataBinding += new EventHandler(date_DataBinding);
|
76
|
|
|
77
|
4
|
container.Controls.Add(date);
|
78
|
|
}
|
79
|
12
|
else if (dbattr.IsPassword) {
|
80
|
|
|
81
|
4
|
ChangePassword cp = new ChangePassword();
|
82
|
|
|
83
|
4
|
container.Controls.Add(cp);
|
84
|
4
|
cp.DataBinding += new EventHandler(cp_DataBinding);
|
85
|
|
|
86
|
4
|
cp.Validators.AddRange(Configuration.Session
|
87
|
|
.MappingHandler.GetValidators(propertyInfo));
|
88
|
|
|
89
|
|
}
|
90
|
|
else {
|
91
|
|
|
92
|
8
|
TextField tf = new TextField();
|
93
|
|
|
94
|
8
|
tf.DataBinding += new EventHandler(tf_DataBinding);
|
95
|
8
|
tf.Width = Unit.Percentage(100);
|
96
|
8
|
container.Controls.Add(tf);
|
97
|
|
|
98
|
8
|
tf.Validators.AddRange(Configuration.Session.MappingHandler
|
99
|
|
.GetValidators(propertyInfo));
|
100
|
|
}
|
101
|
|
}
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
8
|
private void tf_DataBinding(object sender, EventArgs e)
|
110
|
|
{
|
111
|
8
|
TextField tf;
|
112
|
8
|
tf = (TextField) sender;
|
113
|
8
|
DataGridItem container = (DataGridItem) tf.NamingContainer;
|
114
|
8
|
tf.InputText += DataBinder.Eval(container.DataItem,propertyInfo.Name);
|
115
|
|
|
116
|
8
|
DataGrid dg = container.Parent.Parent
|
117
|
|
as DataGrid;
|
118
|
|
|
119
|
8
|
int pos = container.DataSetIndex - dg.PageSize*dg.CurrentPageIndex;
|
120
|
|
|
121
|
8
|
tf.MergeTextStyle((pos % 2 == 0) ? dg.ItemStyle : dg.AlternatingItemStyle);
|
122
|
8
|
tf.MergeControlStyle(dg.ChildControlStyle);
|
123
|
|
}
|
124
|
|
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
4
|
private void cb_DataBinding(object sender, EventArgs e)
|
132
|
|
{
|
133
|
4
|
CheckBox cb;
|
134
|
4
|
cb = (CheckBox) sender;
|
135
|
4
|
DataGridItem container = (DataGridItem) cb.NamingContainer;
|
136
|
4
|
cb.Checked = Convert.ToBoolean(
|
137
|
|
DataBinder.Eval(container.DataItem,propertyInfo.Name));
|
138
|
|
}
|
139
|
|
|
140
|
4
|
private void cp_DataBinding(object sender, EventArgs e)
|
141
|
|
{
|
142
|
4
|
ChangePassword cp;
|
143
|
4
|
cp = (ChangePassword) sender;
|
144
|
4
|
DataGridItem container = (DataGridItem) cp.NamingContainer;
|
145
|
4
|
DataGrid dg = container.Parent.Parent
|
146
|
|
as DataGrid;
|
147
|
|
|
148
|
4
|
int pos = container.DataSetIndex - dg.PageSize*dg.CurrentPageIndex;
|
149
|
|
|
150
|
4
|
cp.MergeTextStyle((pos % 2 == 0) ? dg.ItemStyle : dg.AlternatingItemStyle);
|
151
|
4
|
cp.MergeControlStyle(dg.ChildControlStyle);
|
152
|
|
}
|
153
|
|
|
154
|
4
|
private void date_DataBinding(object sender, EventArgs e)
|
155
|
|
{
|
156
|
4
|
Calendar date;
|
157
|
4
|
date = (Calendar)sender;
|
158
|
4
|
DataGridItem container = (DataGridItem) date.NamingContainer;
|
159
|
|
|
160
|
4
|
DataGrid dg = container.Parent.Parent
|
161
|
|
as DataGrid;
|
162
|
|
|
163
|
4
|
DateTime selDate = Convert.ToDateTime(
|
164
|
|
DataBinder.Eval(container.DataItem,propertyInfo.Name));
|
165
|
|
|
166
|
4
|
if (dg.DateTimeFormat == "")
|
167
|
4
|
date.SelectedDate = selDate.ToString();
|
168
|
|
else
|
169
|
0
|
date.SelectedDate = selDate.ToString(dg.DateTimeFormat);
|
170
|
|
|
171
|
4
|
date.MergeControlStyle(dg.ChildControlStyle);
|
172
|
|
}
|
173
|
|
}
|
174
|
|
}
|
175
|
|
|