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.Web.WebBuilders;
|
30
|
|
using ShowX.Model;
|
31
|
|
using ShowX.Config;
|
32
|
|
using ShowX.Web.WebControls;
|
33
|
|
using ShowX.Web.WebBuilders.ItemTemplates;
|
34
|
|
|
35
|
|
namespace ShowX.Web.WebBuilders
|
36
|
|
{
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
public class DataGridBuilder {
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
Type type;
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
ShowX.Web.WebControls.DataGrid owner;
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
35
|
public DataGridBuilder(Type type, ShowX.Web.WebControls.DataGrid owner)
|
58
|
|
{
|
59
|
35
|
this.type = type;
|
60
|
35
|
this.owner = owner;
|
61
|
|
}
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
0
|
public Type Type { get { return this.type; }}
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
0
|
public System.Web.UI.WebControls.DataGrid DataGrid { get { return this.owner; }}
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
35
|
public void BuildColumns()
|
77
|
|
{
|
78
|
|
|
79
|
35
|
PropertyInfo pInfo = Configuration.Session.MappingHandler.GetPK(type);
|
80
|
|
|
81
|
35
|
owner.Columns.Add(GenIDColumn(pInfo));
|
82
|
|
|
83
|
|
|
84
|
35
|
DataGridColumn col = GenViewColumnForPK(pInfo);
|
85
|
|
|
86
|
35
|
if (col != null) {
|
87
|
|
|
88
|
0
|
col.SortExpression = pInfo.Name;
|
89
|
0
|
owner.Columns.Add(col);
|
90
|
|
}
|
91
|
|
|
92
|
35
|
IViewCollection viewCollection = Configuration.Session
|
93
|
|
.MappingHandler.GetViews(type);
|
94
|
|
|
95
|
35
|
IView activeView = ((viewCollection != null) &&
|
96
|
|
(viewCollection.Views.Count > 0))
|
97
|
|
? viewCollection.Views[owner.ActiveView] as IView
|
98
|
|
: null;
|
99
|
|
|
100
|
35
|
foreach (PropertyInfo pi in Configuration.Session.MappingHandler
|
101
|
|
.GetAllShowXProperties(type)) {
|
102
|
|
|
103
|
245
|
IPropertyMap propertyMap = Configuration.Session
|
104
|
|
.MappingHandler.GetPropertyMap(pi);
|
105
|
|
|
106
|
245
|
if (activeView != null && !activeView.Properties
|
107
|
|
.Contains(propertyMap.Name)) continue;
|
108
|
|
|
109
|
245
|
if (propertyMap is IForeignIdentifierMap)
|
110
|
0
|
owner.Columns.Add(GenViewColumnForFK(pi));
|
111
|
245
|
else if (propertyMap is ICollectionMap)
|
112
|
35
|
owner.Columns.Add(GenViewColumnForCol(pi));
|
113
|
|
else
|
114
|
210
|
owner.Columns.Add(GenViewColumnForField(pi));
|
115
|
|
|
116
|
245
|
if (col != null) {
|
117
|
|
|
118
|
0
|
col.SortExpression = pi.Name;
|
119
|
0
|
owner.Columns.Add(col);
|
120
|
|
}
|
121
|
|
}
|
122
|
|
|
123
|
0
|
if ((owner.DataGridOps & DataGridOps.None) != 0) return;
|
124
|
|
|
125
|
35
|
if ((owner.DataGridOps & DataGridOps.All) != 0 ||
|
126
|
|
((owner.DataGridOps & DataGridOps.InplaceEditing)
|
127
|
|
!= 0)) {
|
128
|
|
|
129
|
35
|
EditCommandColumn ecc = new EditCommandColumn();
|
130
|
35
|
ecc.EditText = "Edit";
|
131
|
35
|
ecc.UpdateText = "Update";
|
132
|
35
|
ecc.CancelText = "Cancel";
|
133
|
35
|
owner.Columns.Add(ecc);
|
134
|
|
}
|
135
|
|
|
136
|
35
|
if ((owner.DataGridOps & (DataGridOps.All|DataGridOps.Deletion))
|
137
|
|
!= 0) {
|
138
|
|
|
139
|
35
|
ButtonColumn bc = new ButtonColumn();
|
140
|
35
|
bc.CommandName = "Delete";
|
141
|
35
|
bc.Text = "Delete";
|
142
|
35
|
owner.Columns.Add(bc);
|
143
|
|
}
|
144
|
|
}
|
145
|
|
|
146
|
|
|
147
|
|
|
148
|
|
|
149
|
|
|
150
|
|
|
151
|
|
|
152
|
35
|
protected DataGridColumn GenViewColumnForPK(PropertyInfo pInfo)
|
153
|
|
{
|
154
|
35
|
IIdentifierMap dbpk = Configuration.Session.MappingHandler
|
155
|
|
.GetPropertyMap(pInfo) as IIdentifierMap;
|
156
|
|
|
157
|
35
|
if (!dbpk.Show) return null;
|
158
|
|
|
159
|
0
|
BoundColumn bc = new BoundColumn();
|
160
|
0
|
bc.ReadOnly = true;
|
161
|
|
|
162
|
0
|
if (dbpk.SubstituteAttr != "") {
|
163
|
|
|
164
|
|
PropertyInfo sustAttrMethod = Configuration.Session
|
165
|
|
.MappingHandler.GetShowXPropertyByName(type,dbpk.SubstituteAttr);
|
166
|
|
|
167
|
|
IPropertyMap dbAttr = Configuration.Session.MappingHandler
|
168
|
|
.GetPropertyMap(sustAttrMethod);
|
169
|
|
|
170
|
|
bc.DataField = sustAttrMethod.Name;
|
171
|
|
bc.HeaderText = dbAttr.Heading;
|
172
|
|
}
|
173
|
|
else {
|
174
|
|
|
175
|
|
bc.DataField = pInfo.Name;
|
176
|
|
bc.HeaderText = dbpk.Heading;
|
177
|
|
}
|
178
|
|
|
179
|
0
|
return bc;
|
180
|
|
}
|
181
|
|
|
182
|
|
|
183
|
|
|
184
|
|
|
185
|
|
|
186
|
|
|
187
|
|
|
188
|
0
|
protected TemplateColumn GenViewColumnForFK(PropertyInfo pInfo)
|
189
|
|
{
|
190
|
|
IForeignIdentifierMap dbfk = Configuration.Session.MappingHandler
|
191
|
|
.GetPropertyMap(pInfo) as IForeignIdentifierMap;
|
192
|
|
|
193
|
|
PropertyInfo pi = Configuration.Session.MappingHandler
|
194
|
|
.GetPK(pInfo.PropertyType);
|
195
|
|
|
196
|
|
IIdentifierMap dbpk = Configuration.Session.MappingHandler
|
197
|
|
.GetPropertyMap(pi) as IIdentifierMap;
|
198
|
|
|
199
|
|
TemplateColumn tc = new TemplateColumn();
|
200
|
|
tc.HeaderText = dbfk.Heading;
|
201
|
|
tc.ItemTemplate = new TextTemplate(pInfo.Name + "."
|
202
|
|
+ dbpk.SubstituteAttr);
|
203
|
|
tc.EditItemTemplate = new FKEditTemplate(pInfo);
|
204
|
|
|
205
|
|
return tc;
|
206
|
|
}
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
|
|
211
|
|
|
212
|
|
|
213
|
|
|
214
|
|
|
215
|
210
|
protected DataGridColumn GenViewColumnForField(PropertyInfo pInfo)
|
216
|
|
{
|
217
|
210
|
IPropertyMap dbattr = Configuration.Session.MappingHandler
|
218
|
|
.GetPropertyMap(pInfo);
|
219
|
|
|
220
|
0
|
if (!dbattr.Show) return null;
|
221
|
|
|
222
|
210
|
DataGridColumn result = null;
|
223
|
|
|
224
|
210
|
if (dbattr is IXPercentMap) {
|
225
|
|
|
226
|
|
|
227
|
0
|
IXPercentMap xp = dbattr as IXPercentMap;
|
228
|
|
|
229
|
0
|
if (xp.ShowLikePercent) {
|
230
|
|
|
231
|
|
TemplateColumn tc = new TemplateColumn();
|
232
|
|
tc.ItemTemplate = new PercentItemTemplate(pInfo);
|
233
|
|
tc.EditItemTemplate = new PercentItemTemplate(pInfo);
|
234
|
|
|
235
|
|
tc.HeaderText = dbattr.Heading;
|
236
|
|
|
237
|
|
return tc;
|
238
|
|
}
|
239
|
|
|
240
|
|
|
241
|
|
|
242
|
|
|
243
|
|
|
244
|
|
|
245
|
|
|
246
|
|
|
247
|
|
|
248
|
|
|
249
|
|
|
250
|
|
|
251
|
|
|
252
|
|
}
|
253
|
|
|
254
|
210
|
if (dbattr.IsPassword) {
|
255
|
|
|
256
|
35
|
TemplateColumn tc = new TemplateColumn();
|
257
|
35
|
tc.ItemTemplate = new ItemTemplate(pInfo);
|
258
|
35
|
tc.EditItemTemplate = new EditItemTemplate(pInfo);
|
259
|
35
|
tc.HeaderText = dbattr.Heading;
|
260
|
|
|
261
|
35
|
return tc;
|
262
|
|
}
|
263
|
175
|
if (!pInfo.PropertyType.IsByRef) {
|
264
|
|
|
265
|
175
|
TemplateColumn tc = new TemplateColumn();
|
266
|
175
|
tc.ItemTemplate = new ItemTemplate(pInfo);
|
267
|
|
|
268
|
175
|
if (dbattr.ReadOnly)
|
269
|
35
|
tc.EditItemTemplate = new ItemTemplate(pInfo);
|
270
|
|
else
|
271
|
140
|
tc.EditItemTemplate = new EditItemTemplate(pInfo);
|
272
|
|
|
273
|
175
|
tc.HeaderText = dbattr.Heading;
|
274
|
175
|
result = tc;
|
275
|
|
}
|
276
|
|
else {
|
277
|
|
|
278
|
0
|
result = GenViewColumnForPK(pInfo);
|
279
|
|
}
|
280
|
|
|
281
|
175
|
result.SortExpression = dbattr.Name;
|
282
|
175
|
result.HeaderText = dbattr.Heading;
|
283
|
|
|
284
|
175
|
return result;
|
285
|
|
}
|
286
|
|
|
287
|
|
|
288
|
|
|
289
|
|
|
290
|
|
|
291
|
|
|
292
|
|
|
293
|
|
|
294
|
35
|
protected DataGridColumn GenViewColumnForCol(PropertyInfo pInfo)
|
295
|
|
{
|
296
|
35
|
ICollectionMap collmap = Configuration.Session.MappingHandler
|
297
|
|
.GetPropertyMap(pInfo) as ICollectionMap;
|
298
|
|
|
299
|
35
|
TemplateColumn tc = new TemplateColumn();
|
300
|
35
|
tc.HeaderText = collmap.Heading;
|
301
|
35
|
tc.ItemTemplate = new CollectionItemTemplate(pInfo);
|
302
|
35
|
tc.EditItemTemplate = new CollectionEditItemTemplate(pInfo);
|
303
|
|
|
304
|
35
|
return tc;
|
305
|
|
}
|
306
|
|
|
307
|
|
|
308
|
|
|
309
|
|
|
310
|
|
|
311
|
|
|
312
|
|
|
313
|
|
|
314
|
|
|
315
|
|
|
316
|
|
|
317
|
|
|
318
|
35
|
protected TemplateColumn GenIDColumn(PropertyInfo pInfo)
|
319
|
|
{
|
320
|
35
|
TemplateColumn tc = new TemplateColumn();
|
321
|
35
|
tc.ItemTemplate = new ItemTemplate(pInfo);
|
322
|
35
|
tc.Visible = false;
|
323
|
|
|
324
|
35
|
return tc;
|
325
|
|
}
|
326
|
|
}
|
327
|
|
}
|
328
|
|
|