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.Collections;
|
26
|
|
using System.Reflection;
|
27
|
|
using System.Web.UI;
|
28
|
|
using System.Web.UI.WebControls;
|
29
|
|
using System.ComponentModel;
|
30
|
|
using ShowX.Web.WebBuilders.ItemTemplates;
|
31
|
|
using ShowX.Model;
|
32
|
|
using ShowX.Config;
|
33
|
|
|
34
|
|
namespace ShowX.Web.WebControls
|
35
|
|
{
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
public enum ElemOps {
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
Add,
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
|
Query
|
49
|
|
}
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
public class AdminElementEventArgs : EventArgs
|
56
|
|
{
|
57
|
|
object addedElement;
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
3
|
public AdminElementEventArgs(object addedElement)
|
64
|
|
{
|
65
|
3
|
this.addedElement = addedElement;
|
66
|
|
}
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
0
|
public object AddedElement
|
72
|
|
{
|
73
|
|
get { return this.addedElement; }
|
74
|
|
}
|
75
|
|
}
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
public delegate void OnQueryResultEventHandler(ArrayList elems);
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
|
public delegate void OnAddElemEventHandler(object sender, AdminElementEventArgs e);
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
[DefaultProperty("Text"),
|
92
|
|
ToolboxData("<{0}:AdminElement runat=server></{0}:AdminElement>")]
|
93
|
|
public class AdminElement : System.Web.UI.WebControls.DataList
|
94
|
|
{
|
95
|
|
TableItemStyle childControlStyle;
|
96
|
|
|
97
|
|
object context;
|
98
|
|
|
99
|
|
#region Private methods
|
100
|
|
|
101
|
4
|
private void execAdd(DataListCommandEventArgs e)
|
102
|
|
{
|
103
|
4
|
ArrayList values = new ArrayList();
|
104
|
4
|
bool validated = true;
|
105
|
|
|
106
|
4
|
System.Web.UI.WebControls.Table table = e.Item.Controls[0] as
|
107
|
|
System.Web.UI.WebControls.Table;
|
108
|
|
|
109
|
4
|
foreach (TableRow row in table.Rows) {
|
110
|
|
|
111
|
0
|
if (row.Cells.Count != 2) continue;
|
112
|
|
|
113
|
32
|
if (row.Cells[1].Controls[0] is TextField) {
|
114
|
|
|
115
|
12
|
TextField tf = row.Cells[1].Controls[0] as TextField;
|
116
|
|
|
117
|
12
|
if (tf.Validate(XContext)) {
|
118
|
9
|
values.Add(tf.InputText);
|
119
|
|
}
|
120
|
|
else
|
121
|
3
|
validated = false;
|
122
|
|
|
123
|
|
}
|
124
|
20
|
else if (row.Cells[1].Controls[0] is
|
125
|
|
ShowX.Web.WebControls.CheckBoxList) {
|
126
|
|
|
127
|
4
|
ShowX.Web.WebControls.CheckBoxList cblist = row.Cells[1]
|
128
|
|
.Controls[0] as ShowX.Web.WebControls.CheckBoxList;
|
129
|
4
|
ArrayList sel = new ArrayList();
|
130
|
|
|
131
|
4
|
foreach (ListItem li in cblist.Items) {
|
132
|
|
|
133
|
12
|
if (li.Selected)
|
134
|
8
|
sel.Add(Configuration.Session.MethodCaller
|
135
|
|
.InvokeMethodGetXByID(cblist.CollectionMap
|
136
|
|
.ContainedType,XContext,int.Parse(li.Value)));
|
137
|
|
}
|
138
|
|
|
139
|
4
|
if (cblist.Validate(XContext))
|
140
|
3
|
values.Add(sel);
|
141
|
|
else
|
142
|
1
|
validated = false;
|
143
|
|
}
|
144
|
16
|
else if (row.Cells[1].Controls[0] is ShowX.Web.WebControls
|
145
|
|
.Calendar) {
|
146
|
|
|
147
|
4
|
ShowX.Web.WebControls.Calendar calendar = row.Cells[1].Controls[0]
|
148
|
|
as ShowX.Web.WebControls.Calendar;
|
149
|
|
|
150
|
4
|
if (calendar.Validate(XContext))
|
151
|
3
|
values.Add(calendar.SelectedDate);
|
152
|
|
else
|
153
|
1
|
validated = false;
|
154
|
|
}
|
155
|
12
|
else if (row.Cells[1].Controls[0] is CheckBox)
|
156
|
4
|
values.Add((row.Cells[1].Controls[0] as CheckBox).Checked);
|
157
|
8
|
else if (row.Cells[1].Controls[0] is ChangePassword) {
|
158
|
|
|
159
|
4
|
ChangePassword cp = row.Cells[1].Controls[0] as ChangePassword;
|
160
|
|
|
161
|
4
|
if (cp.Validate(XContext))
|
162
|
3
|
values.Add(cp.Password);
|
163
|
|
else
|
164
|
1
|
validated = false;
|
165
|
|
}
|
166
|
4
|
else if ((row.Cells[1].Controls.Count == 2)
|
167
|
|
&& (row.Cells[1].Controls[0] is DropDownList)) {
|
168
|
|
|
169
|
|
|
170
|
0
|
DropDownList ddl = row.Cells[1].Controls[0] as DropDownList;
|
171
|
0
|
Literal fkPropertyName = row.Cells[1].Controls[1] as Literal;
|
172
|
|
|
173
|
0
|
int selfkId = int.Parse(ddl.SelectedValue);
|
174
|
|
|
175
|
0
|
PropertyInfo pInfo = Configuration.Session.MappingHandler
|
176
|
|
.GetFK(Type,fkPropertyName.Text);
|
177
|
|
|
178
|
0
|
object fkInstance = Configuration.Session.MethodCaller
|
179
|
|
.InvokeMethodGetXByID(pInfo.PropertyType,XContext,selfkId);
|
180
|
|
|
181
|
0
|
values.Add(fkInstance);
|
182
|
|
}
|
183
|
|
}
|
184
|
|
|
185
|
4
|
if (validated) {
|
186
|
|
|
187
|
3
|
object added = Configuration.Session.MethodCaller
|
188
|
|
.InvokeMethodAddX(Type,XContext,values.ToArray());
|
189
|
|
|
190
|
3
|
if (OnAddElement != null)
|
191
|
3
|
OnAddElement(this,new AdminElementEventArgs(added));
|
192
|
|
}
|
193
|
|
}
|
194
|
|
|
195
|
0
|
private void execSearch(DataListCommandEventArgs e)
|
196
|
|
{
|
197
|
|
ArrayList matchElems = Configuration.Session.MethodCaller
|
198
|
|
.InvokeMethodGetAllX(this.Type,XContext);
|
199
|
|
|
200
|
|
ArrayList DBFields = Configuration.Session.MappingHandler
|
201
|
|
.GetAllShowXProperties(this.Type);
|
202
|
|
int DBFieldsIndex = 0;
|
203
|
|
|
204
|
|
System.Web.UI.WebControls.Table table = e.Item.Controls[0] as
|
205
|
|
System.Web.UI.WebControls.Table;
|
206
|
|
|
207
|
|
foreach (TableRow row in table.Rows) {
|
208
|
|
|
209
|
|
if (row.Cells.Count != 2) continue;
|
210
|
|
if (DBFieldsIndex >= DBFields.Count) break;
|
211
|
|
|
212
|
|
|
213
|
|
|
214
|
|
|
215
|
|
IPropertyMap dbAttr = Configuration.Session.MappingHandler
|
216
|
|
.GetPropertyMap(DBFields[DBFieldsIndex] as PropertyInfo);
|
217
|
|
|
218
|
|
while (!dbAttr.EditOnInsert && (DBFieldsIndex < DBFields.Count)) {
|
219
|
|
|
220
|
|
DBFieldsIndex++;
|
221
|
|
|
222
|
|
|
223
|
|
|
224
|
|
|
225
|
|
dbAttr = Configuration.Session.MappingHandler
|
226
|
|
.GetPropertyMap(DBFields[DBFieldsIndex] as PropertyInfo);
|
227
|
|
}
|
228
|
|
|
229
|
|
if (row.Cells[1].Controls[0] is TextField) {
|
230
|
|
|
231
|
|
TextField tf = row.Cells[1].Controls[0] as TextField;
|
232
|
|
|
233
|
|
if (tf.InputText != "") {
|
234
|
|
|
235
|
|
matchElems = filterMatching(matchElems,tf.InputText,
|
236
|
|
DBFields[DBFieldsIndex] as PropertyInfo);
|
237
|
|
}
|
238
|
|
}
|
239
|
|
else if (row.Cells[1].Controls[0] is CheckBox) {
|
240
|
|
|
241
|
|
matchElems = filterMatching(matchElems,
|
242
|
|
(row.Cells[1].Controls[0] as CheckBox).Checked,
|
243
|
|
DBFields[DBFieldsIndex] as PropertyInfo);
|
244
|
|
|
245
|
|
}
|
246
|
|
else if (row.Cells[1].Controls[0] is ChangePassword) {
|
247
|
|
|
248
|
|
ChangePassword cp = row.Cells[1].Controls[0] as ChangePassword;
|
249
|
|
|
250
|
|
|
251
|
|
|
252
|
|
|
253
|
|
|
254
|
|
}
|
255
|
|
else if ((row.Cells[1].Controls.Count == 2)
|
256
|
|
&& (row.Cells[1].Controls[0] is DropDownList)) {
|
257
|
|
|
258
|
|
|
259
|
|
DropDownList ddl = row.Cells[1].Controls[0] as DropDownList;
|
260
|
|
Literal fkPropertyName = row.Cells[1].Controls[1] as Literal;
|
261
|
|
|
262
|
|
int selfkId = int.Parse(ddl.SelectedValue);
|
263
|
|
|
264
|
|
PropertyInfo pInfo = Configuration.Session.MappingHandler
|
265
|
|
.GetFK(Type,fkPropertyName.Text);
|
266
|
|
|
267
|
|
object fkInstance = Configuration.Session.MethodCaller
|
268
|
|
.InvokeMethodGetXByID(pInfo.PropertyType,XContext,selfkId);
|
269
|
|
|
270
|
|
|
271
|
|
}
|
272
|
|
|
273
|
|
DBFieldsIndex++;
|
274
|
|
}
|
275
|
|
|
276
|
|
if (matchElems.Count != 0) {
|
277
|
|
|
278
|
|
OnQueryResult(matchElems);
|
279
|
|
}
|
280
|
|
}
|
281
|
|
|
282
|
0
|
private ArrayList filterMatching(ArrayList matchElems,string textToMatch,
|
283
|
|
PropertyInfo pInfo) {
|
284
|
|
ArrayList result = new ArrayList();
|
285
|
|
|
286
|
|
foreach(Object o in matchElems) {
|
287
|
|
|
288
|
|
string propResult = o.GetType().InvokeMember(
|
289
|
|
pInfo.Name,BindingFlags.GetProperty,null,o,null).ToString();
|
290
|
|
|
291
|
|
if (propResult == textToMatch)
|
292
|
|
result.Add(o);
|
293
|
|
}
|
294
|
|
|
295
|
|
return result;
|
296
|
|
}
|
297
|
|
|
298
|
0
|
private ArrayList filterMatching(ArrayList matchElems,bool condToMatch,
|
299
|
|
PropertyInfo pInfo) {
|
300
|
|
ArrayList result = new ArrayList();
|
301
|
|
|
302
|
|
foreach(Object o in matchElems) {
|
303
|
|
|
304
|
|
bool propResult = Convert.ToBoolean(o.GetType().InvokeMember(
|
305
|
|
pInfo.Name,BindingFlags.GetProperty,null,o,null));
|
306
|
|
|
307
|
|
if (propResult == condToMatch)
|
308
|
|
result.Add(o);
|
309
|
|
}
|
310
|
|
|
311
|
|
return result;
|
312
|
|
}
|
313
|
|
|
314
|
|
|
315
|
|
#endregion
|
316
|
|
|
317
|
|
|
318
|
|
|
319
|
|
|
320
|
|
|
321
|
|
public object XContext
|
322
|
|
{
|
323
|
60
|
get
|
324
|
|
{
|
325
|
60
|
return this.context;
|
326
|
|
}
|
327
|
0
|
set { this.context = value; }
|
328
|
|
}
|
329
|
|
|
330
|
|
|
331
|
|
|
332
|
|
|
333
|
|
public event OnQueryResultEventHandler OnQueryResult;
|
334
|
|
|
335
|
|
|
336
|
|
|
337
|
|
|
338
|
|
public event OnAddElemEventHandler OnAddElement;
|
339
|
|
|
340
|
|
|
341
|
|
|
342
|
|
|
343
|
|
[Bindable(true), Category("Business"), DefaultValue("")]
|
344
|
|
public Type Type
|
345
|
|
{
|
346
|
78
|
get { return (Type)(ViewState["ShowXObjectBrowserType"]); }
|
347
|
6
|
set
|
348
|
|
{
|
349
|
6
|
ViewState["ShowXObjectBrowserType"] = value;
|
350
|
6
|
this.ChildControlsCreated = false;
|
351
|
6
|
this.CreateChildControls();
|
352
|
|
}
|
353
|
|
}
|
354
|
|
|
355
|
|
|
356
|
|
|
357
|
|
|
358
|
|
[Bindable(true), Category("Business"), DefaultValue("")]
|
359
|
|
public ElemOps ElemOps
|
360
|
|
{
|
361
|
25
|
get { return (ElemOps)(ViewState["ShowXObjectElemOps"]); }
|
362
|
6
|
set { ViewState["ShowXObjectElemOps"] = value; }
|
363
|
|
}
|
364
|
|
|
365
|
|
|
366
|
|
|
367
|
|
|
368
|
|
[Bindable(true), Category("Style"), Browsable(true)]
|
369
|
|
[PersistenceMode(PersistenceMode.InnerProperty),
|
370
|
|
TemplateContainer(typeof(AdminElement))]
|
371
|
|
public TableItemStyle ChildControlStyle
|
372
|
|
{
|
373
|
275
|
get {
|
374
|
275
|
if (childControlStyle == null)
|
375
|
0
|
childControlStyle = new TableItemStyle();
|
376
|
|
|
377
|
275
|
return childControlStyle;
|
378
|
|
}
|
379
|
25
|
set {
|
380
|
25
|
childControlStyle = value;
|
381
|
|
}
|
382
|
|
}
|
383
|
|
|
384
|
|
|
385
|
|
|
386
|
|
|
387
|
25
|
protected override void CreateChildControls()
|
388
|
|
{
|
389
|
0
|
if (Type == null || ChildControlsCreated) return;
|
390
|
|
|
391
|
25
|
this.EditItemIndex = 0;
|
392
|
|
|
393
|
25
|
switch (ElemOps) {
|
394
|
|
|
395
|
|
case ElemOps.Add:
|
396
|
|
|
397
|
25
|
this.EditItemTemplate = new AddItemTemplate(Type,this);
|
398
|
25
|
break;
|
399
|
|
|
400
|
|
case ElemOps.Query:
|
401
|
|
|
402
|
0
|
this.EditItemTemplate = new SearchItemTemplate(Type,this);
|
403
|
0
|
break;
|
404
|
|
}
|
405
|
|
|
406
|
25
|
ChildControlsCreated = true;
|
407
|
|
|
408
|
25
|
ArrayList datasource = new ArrayList();
|
409
|
25
|
datasource.Add(Configuration.Session.MethodCaller.InvokeMethodNewX(Type));
|
410
|
25
|
this.DataSource = datasource;
|
411
|
25
|
this.DataBind();
|
412
|
|
|
413
|
25
|
this.ItemCommand += new DataListCommandEventHandler(dl_ItemCommand);
|
414
|
|
}
|
415
|
|
|
416
|
4
|
private void dl_ItemCommand(object source, DataListCommandEventArgs e)
|
417
|
|
{
|
418
|
4
|
switch(e.CommandName) {
|
419
|
|
|
420
|
1
|
case "Add": execAdd(e); break;
|
421
|
0
|
case "Search": execSearch(e); break;
|
422
|
|
}
|
423
|
|
}
|
424
|
|
}
|
425
|
|
}
|
426
|
|
|