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.Config;
|
30
|
|
using ShowX.Model;
|
31
|
|
using DataGrid = ShowX.Web.WebControls.DataGrid;
|
32
|
|
|
33
|
|
namespace ShowX.Web.WebBuilders.ItemTemplates
|
34
|
|
{
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
class FKEditTemplate : ITemplate {
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
PropertyInfo propertyInfo;
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
0
|
public FKEditTemplate(PropertyInfo propertyInfo)
|
51
|
|
{
|
52
|
|
this.propertyInfo = propertyInfo;
|
53
|
|
}
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
0
|
public void InstantiateIn(Control container)
|
61
|
|
{
|
62
|
|
DropDownList ddl = new DropDownList();
|
63
|
|
ddl.DataBinding += new EventHandler(TemplateControl_DataBinding);
|
64
|
|
container.Controls.Add(ddl);
|
65
|
|
ddl.Width = Unit.Percentage(100);
|
66
|
|
|
67
|
|
Literal lc = new Literal();
|
68
|
|
lc.Text += propertyInfo.Name;
|
69
|
|
lc.Visible = false;
|
70
|
|
container.Controls.Add(lc);
|
71
|
|
}
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
0
|
private void TemplateControl_DataBinding(object sender, EventArgs e)
|
80
|
|
{
|
81
|
|
PropertyInfo pi = Configuration.Session.MappingHandler
|
82
|
|
.GetPK(propertyInfo.PropertyType);
|
83
|
|
|
84
|
|
IIdentifierMap dbpk = Configuration.Session.MappingHandler
|
85
|
|
.GetPropertyMap(pi) as IIdentifierMap;
|
86
|
|
|
87
|
|
DropDownList ddl;
|
88
|
|
ddl = (DropDownList) sender;
|
89
|
|
DataGridItem container = (DataGridItem) ddl.NamingContainer;
|
90
|
|
|
91
|
|
DataGrid dg = container.Parent.Parent
|
92
|
|
as DataGrid;
|
93
|
|
|
94
|
|
ddl.ControlStyle.MergeWith(dg.ChildControlStyle);
|
95
|
|
|
96
|
|
ArrayList values = Configuration.Session.MethodCaller
|
97
|
|
.InvokeMethodGetAllX(propertyInfo.PropertyType,dg.XContext);
|
98
|
|
|
99
|
|
object aux = DataBinder.Eval(container.DataItem,
|
100
|
|
propertyInfo.Name + "."+ pi.Name);
|
101
|
|
int id = int.Parse(aux.ToString());
|
102
|
|
int currId = 0;
|
103
|
|
|
104
|
|
for (int i = 0; i < values.Count; i++) {
|
105
|
|
|
106
|
|
aux = DataBinder.Eval(values[i],dbpk.SubstituteAttr);
|
107
|
|
ddl.Items.Add(aux.ToString());
|
108
|
|
|
109
|
|
aux = DataBinder.Eval(values[i],pi.Name);
|
110
|
|
currId = int.Parse(aux.ToString());
|
111
|
|
ddl.Items[i].Value = aux.ToString();
|
112
|
|
|
113
|
|
if (id == currId)
|
114
|
|
ddl.SelectedIndex = i;
|
115
|
|
}
|
116
|
|
}
|
117
|
|
}
|
118
|
|
}
|
119
|
|
|