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 ShowX.Model;
|
30
|
|
using ShowX.Config;
|
31
|
|
|
32
|
|
namespace ShowX.Web.WebBuilders.ItemTemplates
|
33
|
|
{
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
|
public class CollectionEditItemTemplate : ITemplate
|
38
|
|
{
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
PropertyInfo propertyInfo;
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
35
|
public CollectionEditItemTemplate(PropertyInfo pInfo)
|
49
|
|
{
|
50
|
35
|
this.propertyInfo = pInfo;
|
51
|
|
}
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
4
|
public void InstantiateIn(System.Web.UI.Control container)
|
59
|
|
{
|
60
|
4
|
ShowX.Web.WebControls.CheckBoxList cblist = new ShowX.Web
|
61
|
|
.WebControls.CheckBoxList(this.propertyInfo);
|
62
|
4
|
cblist.DataBinding += new EventHandler(TemplateControl_DataBinding);
|
63
|
4
|
container.Controls.Add(cblist);
|
64
|
4
|
cblist.Width = Unit.Percentage(100);
|
65
|
|
|
66
|
4
|
cblist.Validators.AddRange(Configuration.Session
|
67
|
|
.MappingHandler.GetValidators(propertyInfo));
|
68
|
|
|
69
|
|
}
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
4
|
private void TemplateControl_DataBinding(object sender, System.EventArgs e)
|
78
|
|
{
|
79
|
4
|
ICollectionMap colmap = Configuration.Session.MappingHandler
|
80
|
|
.GetPropertyMap(propertyInfo) as ICollectionMap;
|
81
|
|
|
82
|
4
|
ShowX.Web.WebControls.CheckBoxList cblist;
|
83
|
4
|
cblist = (ShowX.Web.WebControls.CheckBoxList) sender;
|
84
|
|
|
85
|
4
|
DataGridItem container = (DataGridItem) cblist.NamingContainer;
|
86
|
|
|
87
|
4
|
ShowX.Web.WebControls.DataGrid dg = container.Parent.Parent
|
88
|
|
as ShowX.Web.WebControls.DataGrid;
|
89
|
|
|
90
|
4
|
cblist.MergeControlStyle(dg.ChildControlStyle);
|
91
|
|
|
92
|
4
|
ICollection values = DataBinder.Eval(container.DataItem,
|
93
|
|
propertyInfo.Name) as ICollection;
|
94
|
|
|
95
|
4
|
PropertyInfo pi = Configuration.Session.MappingHandler
|
96
|
|
.GetPK(colmap.ContainedType);
|
97
|
|
|
98
|
4
|
IIdentifierMap imap = Configuration.Session.MappingHandler
|
99
|
|
.GetPropertyMap(pi) as IIdentifierMap;
|
100
|
|
|
101
|
4
|
string idProp = (imap.SubstituteAttr == "")
|
102
|
|
? imap.Name : imap.SubstituteAttr;
|
103
|
|
|
104
|
4
|
ArrayList allValues = Configuration.Session.MethodCaller
|
105
|
|
.InvokeMethodGetAllX(colmap.ContainedType,dg.XContext);
|
106
|
|
|
107
|
4
|
foreach(object o in allValues) {
|
108
|
|
|
109
|
12
|
cblist.Items.Add(new ListItem(
|
110
|
|
DataBinder.Eval(o,idProp).ToString(),
|
111
|
|
DataBinder.Eval(o,imap.Name).ToString()));
|
112
|
|
|
113
|
12
|
foreach (object o1 in values) {
|
114
|
|
|
115
|
|
|
116
|
20
|
if (DataBinder.Eval(o,imap.Name).ToString() ==
|
117
|
|
DataBinder.Eval(o1,imap.Name).ToString()) {
|
118
|
|
|
119
|
8
|
cblist.Items[cblist.Items.Count-1].Selected = true;
|
120
|
8
|
break;
|
121
|
|
}
|
122
|
|
}
|
123
|
|
}
|
124
|
|
}
|
125
|
|
}
|
126
|
|
}
|
127
|
|
|