SetValue.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web.UI;
  6. namespace Ant.Frame
  7. {
  8. public enum ControlType { Ext, Net }
  9. public static class SetValue
  10. {
  11. #region 不知道控件的级次进行赋值
  12. /// <summary>
  13. /// 不知道控件的级次进行赋值
  14. /// </summary>
  15. /// <param name="page"></param>
  16. /// <param name="enty"></param>
  17. /// <param name="lbl"></param>
  18. /// <returns></returns>
  19. public static void SetControlValue(Control page, object enty)
  20. {
  21. List<Control> conlist = new List<Control>(); List<object> obj = new List<object>();
  22. if (!object.Equals(enty, null))
  23. obj.Add(enty);
  24. foreach (Control ctrol in page.Controls)
  25. {
  26. conlist.Add(ctrol);
  27. }
  28. GetCollection(conlist, obj, "");
  29. }
  30. /// <summary>
  31. /// 不知道控件的级次进行赋值
  32. /// </summary>
  33. /// <param name="page">控件集合</param>
  34. /// <param name="enty">单个实体</param>
  35. /// <param name="lbl"></param>
  36. /// <returns></returns>
  37. public static void SetControlValue(Control page, object enty, string lbl)
  38. {
  39. List<Control> conlist = new List<Control>(); List<object> obj = new List<object>();
  40. if (!object.Equals(enty, null))
  41. obj.Add(enty);
  42. foreach (Control ctrol in page.Controls)
  43. {
  44. conlist.Add(ctrol);
  45. }
  46. GetCollection(conlist, obj, lbl);
  47. }
  48. /// <summary>
  49. /// 给多个实体的控件赋值
  50. /// </summary>
  51. /// <param name="page">控件集合</param>
  52. /// <param name="enty">实体集合</param>
  53. /// <param name="lbl"></param>
  54. public static void SetControlValue(Control page, List<object> enty, string lbl)
  55. {
  56. List<Control> conlist = new List<Control>();
  57. foreach (Control ctrol in page.Controls)
  58. {
  59. conlist.Add(ctrol);
  60. }
  61. GetCollection(conlist, enty, lbl);
  62. }
  63. /// <summary>
  64. ///不知道控件的级次进行赋值
  65. /// </summary>
  66. /// <param name="pages"></param>
  67. /// <param name="enty"></param>
  68. public static void SetControlValue(List<Control> pages, List<object> enty)
  69. {
  70. GetCollection(pages, enty, "");
  71. }
  72. private static void GetCollection(List<Control> page, List<object> enty, string lbl)
  73. {
  74. int level = 0;
  75. level = ControlCollection(page, level, enty, lbl);
  76. }
  77. private static int ControlCollection(List<Control> oldMenus, int level, List<object> entity, string lbl)
  78. {
  79. foreach (Control con in oldMenus)
  80. {
  81. SelectControl setcon = new SelectControl(ControlType.Ext, con);
  82. setcon.SetResult(entity, lbl);
  83. int controlnum = con.Controls.Count;
  84. if (controlnum == 0)
  85. level++;
  86. else
  87. {
  88. List<Control> conlist = new List<Control>();
  89. foreach (Control ctrol in con.Controls)
  90. {
  91. conlist.Add(ctrol);
  92. }
  93. level += ControlCollection(conlist, level, entity, lbl);
  94. }
  95. }
  96. return level;
  97. }
  98. #endregion
  99. #region 知道控件的级次,对控件下面的所有控件进行赋值
  100. /// <summary>
  101. /// 知道控件的级次,对控件下面的所有控件进行赋值
  102. /// </summary>
  103. /// <param name="page"></param>
  104. /// <param name="enty"></param>
  105. public static void SetValueControl(Control page, List<object> enty)
  106. {
  107. int level = 0;
  108. List<Control> conlist = new List<Control>();
  109. foreach (Control ctrol in page.Controls)
  110. {
  111. conlist.Add(ctrol);
  112. }
  113. ControlSet(conlist, level, enty, "");
  114. }
  115. /// <summary>
  116. /// 知道控件的级次,对控件下面的所有控件进行赋值
  117. /// </summary>
  118. /// <param name="pages">控件集合</param>
  119. /// <param name="enty">实体集合</param>
  120. public static void SetValueControl(List<Control> pages, List<object> enty, string lbl)
  121. {
  122. try
  123. {
  124. int level = 0;
  125. level = ControlSet(pages, level, enty, lbl);
  126. }
  127. catch (Exception ex) { }
  128. }
  129. /// <summary>
  130. /// 知道控件的级次,对控件下面的所有控件进行赋值
  131. /// </summary>
  132. /// <param name="oldMenus">控件集合</param>
  133. /// <param name="level">循环次数</param>
  134. /// <param name="entity">实体集合</param>
  135. /// <param name="lbl">标签</param>
  136. /// <returns></returns>
  137. private static int ControlSet(List<Control> oldMenus, int level, List<object> entity, string lbl)
  138. {
  139. foreach (Control menu in oldMenus)
  140. {
  141. foreach (Control cc in menu.Controls)
  142. {
  143. SelectControl con = new SelectControl(ControlType.Ext, cc);
  144. con.SetResult(entity, lbl);
  145. }
  146. }
  147. return level;
  148. }
  149. #endregion
  150. }
  151. }