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.Collections;
|
27
|
|
using System.Web.UI;
|
28
|
|
using System.Web.UI.WebControls;
|
29
|
|
using ShowX.Model;
|
30
|
|
using ShowX.Web.WebControls;
|
31
|
|
using ShowX.Config;
|
32
|
|
|
33
|
|
namespace ShowX.Web.WebBuilders.ItemTemplates
|
34
|
|
{
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
public abstract class ElemTemplate : ITemplate {
|
39
|
|
|
40
|
|
Type type;
|
41
|
|
Hashtable DDLFKMapping;
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
protected AdminElement owner;
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
25
|
public ElemTemplate(Type type, AdminElement owner)
|
54
|
|
{
|
55
|
25
|
this.type = type;
|
56
|
25
|
DDLFKMapping = new Hashtable();
|
57
|
25
|
this.owner = owner;
|
58
|
|
}
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
25
|
public void InstantiateIn(System.Web.UI.Control container)
|
65
|
|
{
|
66
|
25
|
System.Web.UI.Control control = null;
|
67
|
25
|
System.Web.UI.WebControls.Label lc = null;
|
68
|
|
|
69
|
25
|
Table table = new Table();
|
70
|
25
|
TableRow tableRow = null;
|
71
|
25
|
TableCell tableCell = null;
|
72
|
|
|
73
|
25
|
foreach (PropertyInfo pi in Configuration.Session.MappingHandler
|
74
|
|
.GetAllShowXProperties(type)) {
|
75
|
|
|
76
|
175
|
IPropertyMap dbAttr = Configuration.Session.MappingHandler
|
77
|
|
.GetPropertyMap(pi);
|
78
|
|
|
79
|
0
|
if (!dbAttr.EditOnInsert) continue;
|
80
|
|
|
81
|
175
|
tableRow = new TableRow();
|
82
|
175
|
table.Rows.Add(tableRow);
|
83
|
|
|
84
|
175
|
tableCell = new TableCell();
|
85
|
175
|
tableCell.VerticalAlign = VerticalAlign.Top;
|
86
|
175
|
tableRow.Cells.Add(tableCell);
|
87
|
|
|
88
|
175
|
lc = new System.Web.UI.WebControls.Label();
|
89
|
175
|
lc.ControlStyle.MergeWith(owner.ItemStyle);
|
90
|
175
|
lc.Text = dbAttr.Heading;
|
91
|
|
|
92
|
175
|
tableCell.Controls.Add(lc);
|
93
|
|
|
94
|
175
|
tableCell = new TableCell();
|
95
|
175
|
tableCell.VerticalAlign = VerticalAlign.Top;
|
96
|
175
|
tableRow.Cells.Add(tableCell);
|
97
|
|
|
98
|
175
|
if (Configuration.Session.MappingHandler
|
99
|
|
.GetPropertyMap(pi) is ICollectionMap) {
|
100
|
|
|
101
|
25
|
control = new ShowX.Web.WebControls.CheckBoxList(pi);
|
102
|
25
|
(control as ShowX.Web.WebControls.CheckBoxList).Validators
|
103
|
|
.AddRange(Configuration.Session.MappingHandler
|
104
|
|
.GetValidators(pi));
|
105
|
25
|
(control as ShowX.Web.WebControls.CheckBoxList)
|
106
|
|
.MergeControlStyle(owner.ChildControlStyle);
|
107
|
|
|
108
|
25
|
ICollectionMap colmap = Configuration.Session.MappingHandler
|
109
|
|
.GetPropertyMap(pi) as ICollectionMap;
|
110
|
|
|
111
|
25
|
PropertyInfo fkpi = Configuration.Session.MappingHandler
|
112
|
|
.GetPK(colmap.ContainedType);
|
113
|
|
|
114
|
25
|
IIdentifierMap imap = Configuration.Session.MappingHandler
|
115
|
|
.GetPropertyMap(fkpi) as IIdentifierMap;
|
116
|
|
|
117
|
25
|
string idProp = (imap.SubstituteAttr == "")
|
118
|
|
? imap.Name : imap.SubstituteAttr;
|
119
|
|
|
120
|
25
|
ArrayList allValues = Configuration.Session.MethodCaller
|
121
|
|
.InvokeMethodGetAllX(colmap.ContainedType,owner.XContext);
|
122
|
|
|
123
|
25
|
foreach(object o in allValues) {
|
124
|
|
|
125
|
75
|
(control as ShowX.Web.WebControls.CheckBoxList)
|
126
|
|
.Items.Add(new ListItem(
|
127
|
|
DataBinder.Eval(o,idProp).ToString(),
|
128
|
|
DataBinder.Eval(o,imap.Name).ToString()));
|
129
|
|
}
|
130
|
|
}
|
131
|
150
|
else if (Configuration.Session.MappingHandler
|
132
|
|
.GetPropertyMap(pi) is IForeignIdentifierMap) {
|
133
|
|
|
134
|
0
|
control = new DropDownList();
|
135
|
0
|
(control as DropDownList).ControlStyle
|
136
|
|
.MergeWith(owner.ChildControlStyle);
|
137
|
0
|
DDLFKMapping.Add(control,pi);
|
138
|
0
|
control.DataBinding += new EventHandler(control_DataBinding);
|
139
|
0
|
tableCell.Controls.Add(control);
|
140
|
0
|
control = new Literal();
|
141
|
0
|
(control as Literal).Text = pi.Name;
|
142
|
0
|
control.Visible = false;
|
143
|
|
}
|
144
|
|
else {
|
145
|
|
|
146
|
150
|
if (pi.PropertyType == typeof(System.Boolean)) {
|
147
|
|
|
148
|
25
|
control = new CheckBox();
|
149
|
25
|
(control as CheckBox).ControlStyle
|
150
|
|
.MergeWith(owner.ChildControlStyle);
|
151
|
|
}
|
152
|
125
|
else if (pi.PropertyType == typeof(System.DateTime)) {
|
153
|
|
|
154
|
25
|
ShowX.Web.WebControls.Calendar date = new ShowX.Web
|
155
|
|
.WebControls.Calendar(pi);
|
156
|
25
|
date.DataBinding += new EventHandler(date_DataBinding);
|
157
|
25
|
date.MergeControlStyle(owner.ChildControlStyle);
|
158
|
|
|
159
|
25
|
control = date;
|
160
|
|
}
|
161
|
100
|
else if (dbAttr.IsPassword) {
|
162
|
|
|
163
|
25
|
control = new ChangePassword();
|
164
|
|
|
165
|
25
|
(control as ChangePassword).Validators.AddRange(
|
166
|
|
Configuration.Session.MappingHandler.GetValidators(pi));
|
167
|
|
|
168
|
25
|
(control as ChangePassword).MergeControlStyle(owner
|
169
|
|
.ChildControlStyle);
|
170
|
25
|
(control as ChangePassword).MergeTextStyle(owner
|
171
|
|
.ChildControlStyle);
|
172
|
|
|
173
|
|
}
|
174
|
|
else {
|
175
|
|
|
176
|
75
|
control = new TextField();
|
177
|
|
|
178
|
75
|
if (dbAttr.ItemStyle == ItemStyle.TextArea) {
|
179
|
|
|
180
|
0
|
(control as TextField).TextMode = TextBoxMode.MultiLine;
|
181
|
0
|
(control as TextField).Width = Unit.Pixel(400);
|
182
|
0
|
(control as TextField).Height = Unit.Pixel(200);
|
183
|
|
}
|
184
|
|
|
185
|
75
|
(control as TextField).Validators.AddRange(
|
186
|
|
Configuration.Session.MappingHandler.GetValidators(pi));
|
187
|
|
|
188
|
75
|
(control as TextField).MergeControlStyle(owner
|
189
|
|
.ChildControlStyle);
|
190
|
75
|
(control as TextField).MergeTextStyle(owner
|
191
|
|
.ItemStyle);
|
192
|
|
}
|
193
|
|
}
|
194
|
|
|
195
|
175
|
tableCell.Controls.Add(control);
|
196
|
|
}
|
197
|
|
|
198
|
25
|
tableRow = new TableRow();
|
199
|
25
|
table.Rows.Add(tableRow);
|
200
|
|
|
201
|
25
|
BuildButtons(tableRow);
|
202
|
|
|
203
|
25
|
container.Controls.Add(table);
|
204
|
|
}
|
205
|
|
|
206
|
|
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
|
public abstract void BuildButtons(TableRow tableRow);
|
211
|
|
|
212
|
0
|
private void control_DataBinding(object sender, EventArgs e)
|
213
|
|
{
|
214
|
|
DropDownList ddl;
|
215
|
|
ddl = (DropDownList) sender;
|
216
|
|
|
217
|
|
PropertyInfo pInfo = DDLFKMapping[sender] as PropertyInfo;
|
218
|
|
|
219
|
|
ArrayList values = Configuration.Session.MethodCaller
|
220
|
|
.InvokeMethodGetAllX(pInfo.PropertyType,owner.XContext);
|
221
|
|
|
222
|
|
PropertyInfo pi = Configuration.Session.MappingHandler
|
223
|
|
.GetPK(pInfo.PropertyType);
|
224
|
|
|
225
|
|
IIdentifierMap dbpk = Configuration.Session.MappingHandler
|
226
|
|
.GetPropertyMap(pi) as IIdentifierMap;
|
227
|
|
|
228
|
|
object aux;
|
229
|
|
|
230
|
|
for (int i = 0; i < values.Count; i++) {
|
231
|
|
|
232
|
|
aux = DataBinder.Eval(values[i],dbpk.SubstituteAttr);
|
233
|
|
ddl.Items.Add(aux.ToString());
|
234
|
|
|
235
|
|
aux = DataBinder.Eval(values[i],pi.Name);
|
236
|
|
ddl.Items[i].Value = aux.ToString();
|
237
|
|
|
238
|
|
}
|
239
|
|
}
|
240
|
|
|
241
|
25
|
private void date_DataBinding(object sender, EventArgs e)
|
242
|
|
{
|
243
|
25
|
ShowX.Web.WebControls.Calendar date;
|
244
|
25
|
date = (ShowX.Web.WebControls.Calendar)sender;
|
245
|
|
|
246
|
|
|
247
|
25
|
DataListItem container = (DataListItem) date.NamingContainer;
|
248
|
|
|
249
|
25
|
ShowX.Web.WebControls.AdminElement admin = container.Parent
|
250
|
|
as ShowX.Web.WebControls.AdminElement;
|
251
|
25
|
date.MergeControlStyle(admin.ChildControlStyle);
|
252
|
|
}
|
253
|
|
}
|
254
|
|
}
|
255
|
|
|