cyq.dataV4.5.5批量设置值更新

4.x版本默认还没有这个函数,这里为方便使用,更新了下这个函数,不过暂时只有webform的,win的还没有弄也不会弄,谁会弄也麻烦告下小弟。win的也一块放上来了,不过没有测试。

MActionUI.cs中增加函数:

cyq.dataV4.5.5批量设置值更新
 1 /// <summary>
 2         /// 批量设置值
 3         /// </summary>
 4         public void SetToAll(object page)
 5         {
 6             List<string> PrefixList;
 7             if (autoPrefixList == null)
 8             {
 9                 PrefixList = new List<string> { "txt", "ddl", "chb" };
10             }
11             else
12             {
13                 PrefixList = autoPrefixList;
14             }
15             MDataColumn mdc = _Row.Columns;
16             for (int i = 0; i < mdc.Count; i++)
17             {
18                 string key = mdc[i].ColumnName; //获取到列名
19                 string value = _Row[key].Value.ToString(); //对应值
20                 if (page is Control)
21                 {
22                     foreach (string autoPrefix in PrefixList)
23                     {
24                         Control control = ((Control)page).FindControl(autoPrefix + key);
25                         if (control != null)
26                         {
27                             if (control is HtmlInputText)
28                             {
29                                 HtmlInputText txt = (HtmlInputText)control;
30                                 txt.Value = value;
31                             }
32                             if (control is TextBox)
33                             {
34                                 TextBox txt2 = (TextBox)control;
35                                 txt2.Text = value;
36                             }
37                             if (control is DropDownList)
38                             {
39                                 DropDownList txt3 = (DropDownList)control;
40                                 txt3.SelectedValue = value;
41                             }
42                             if (control is HtmlSelect)
43                             {
44                                 HtmlSelect txt4 = (HtmlSelect)control;
45                                 txt4.Value = value;
46                             }
47                             if (control is HtmlInputHidden)
48                             {
49                                 HtmlInputHidden txt5 = (HtmlInputHidden)control;
50                                 txt5.Value = value;
51                             }
52                             if (control is HtmlInputPassword)
53                             {
54                                 HtmlInputPassword txt6 = (HtmlInputPassword)control;
55                                 txt6.Value = value;
56                             }
57                             if (control is Label)
58                             {
59                                 Label txt7 = (Label)control;
60                                 txt7.Text = value;
61                             }
62                             if (control is HtmlTextArea)
63                             {
64                                 HtmlTextArea area = (HtmlTextArea)control;
65                                 area.Value = value;
66                             }
67                         }
68                     }
69                 }
70             }
71         }
cyq.dataV4.5.5批量设置值更新

 忽然发现前边已经对SetTo做了判断了,没必要这里也来一次判断。重新修改为如下代码:

cyq.dataV4.5.5批量设置值更新
 1 /// <summary>
 2         /// 批量设置值
 3         /// </summary>
 4         public void SetToAll(object page, bool isControlEnabled)
 5         {
 6             List<string> PrefixList;
 7             if (autoPrefixList == null)
 8             {
 9                 PrefixList = new List<string> { "txt", "ddl", "chb" };
10             }
11             else
12             {
13                 PrefixList = autoPrefixList;
14             }
15             MDataColumn mdc = _Row.Columns;
16             for (int i = 0; i < mdc.Count; i++)
17             {
18                 string key = mdc[i].ColumnName; //获取到列名
19                 string value = _Row[key].Value.ToString(); //对应值
20                 if (page is Control)
21                 {
22                     foreach (string autoPrefix in PrefixList)
23                     {
24                         Control control = ((Control)page).FindControl(autoPrefix + key);
25                         if (control != null)
26                         {
27                             SetTo(control, value, isControlEnabled);
28                         }
29                     }
30                 }
31             }
32         }
cyq.dataV4.5.5批量设置值更新

 Maction.cs中增加操作函数

cyq.dataV4.5.5批量设置值更新
 1 /// <summary>
 2         /// 批量设置值
 3         /// </summary>
 4         public void SetToAll(object page)
 5         {
 6             _UI.SetToAll(page, true);
 7         }
 8         public void SetToAll(object page, bool isControlEnabled)
 9         {
10             _UI.SetToAll(page, isControlEnabled);
11         }
cyq.dataV4.5.5批量设置值更新

 索性把win的绑定也弄了一下,也不清楚对不对,反正就这样先放着,

cyq.dataV4.5.5批量设置值更新
 1 public void SetToAll(object page, bool isControlEnabled)
 2         {
 3             List<string> PrefixList;
 4             if (autoPrefixList == null)
 5             {
 6                 PrefixList = new List<string> { "txt", "ddl", "chb" };
 7             }
 8             else
 9             {
10                 PrefixList = autoPrefixList;
11             }
12             MDataColumn mdc = _Row.Columns;
13             for (int i = 0; i < mdc.Count; i++)
14             {
15                 string key = mdc[i].ColumnName; //获取到列名
16                 string value = _Row[key].Value.ToString(); //对应值
17                 if (page is Control)
18                 {
19                     foreach (string autoPrefix in PrefixList)
20                     {
21                         Control control = ((Control)page).FindControl(autoPrefix + key);
22                         if (control != null)
23                         {
24                             SetTo(control, value, isControlEnabled);
25                         }
26                     }
27                 }
28                 else
29                 {
30                     foreach (string autoPrefix in PrefixList)
31                     {
32                         Win.Control control = ((Win.Control)page).Controls.Find(autoPrefix + key,true)[0];
33                         if (control != null)
34                         {
35                             SetTo(control, value, isControlEnabled);
36                         }
37                     }
38                 }
39             }
40         }
cyq.dataV4.5.5批量设置值更新

cyq.dataV4.5.5批量设置值更新

上一篇:Linux命令


下一篇:Flex之理解Flash中的事件机制