WorkDataUtil.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using DevComponents.DotNetBar.Layout;
  7. using DevComponents.DotNetBar.Controls;
  8. namespace WCS_Client.UC
  9. {
  10. public class WorkDataUtil
  11. {
  12. public static DataSet GetWorkParameter(List<LayoutControlItem> LCItemList)
  13. {
  14. try
  15. {
  16. List<WorkDataInfo> WorkDataList = new List<WorkDataInfo>();
  17. foreach (LayoutControlItem LCItem in LCItemList)
  18. {
  19. if (LCItem == null || LCItem.Control == null || LCItem.Tag == null)
  20. {
  21. continue;
  22. }
  23. List<WorkDataInfo> Tmplist = GetLCItemValue(LCItem);
  24. if (Tmplist != null)
  25. {
  26. WorkDataList.AddRange(Tmplist);
  27. }
  28. }
  29. List<string> WorkNameList = new List<string>();
  30. foreach (WorkDataInfo witem in WorkDataList)
  31. {
  32. if (!WorkNameList.Contains(witem.WorkName))
  33. {
  34. WorkNameList.Add(witem.WorkName);
  35. }
  36. }
  37. DataSet ds = new DataSet();
  38. foreach (string wname in WorkNameList)
  39. {
  40. DataTable dt = new DataTable(wname);
  41. List<WorkDataInfo> wdlist = WorkDataList.FindAll(a => a.WorkName == wname);
  42. foreach (WorkDataInfo w in wdlist)
  43. {
  44. dt.Columns.Add(w.ParameterName, typeof(string));
  45. }
  46. DataRow dr = dt.NewRow();
  47. foreach (WorkDataInfo w in wdlist)
  48. {
  49. dr[w.ParameterName] = w.ParameterData;
  50. }
  51. dt.Rows.Add(dr);
  52. ds.Tables.Add(dt);
  53. }
  54. return ds;
  55. }
  56. catch
  57. {
  58. }
  59. return null;
  60. }
  61. public static List<WorkDataInfo> GetLCItemValue(LayoutControlItem LCItem)
  62. {
  63. try
  64. {
  65. if (LCItem == null || LCItem.Control == null || LCItem.Tag == null)
  66. {
  67. throw new Exception();
  68. }
  69. List<WorkDataInfo> WorkDataList = new List<WorkDataInfo>();
  70. if (LCItem.Tag is WorkDataInfo)
  71. {
  72. WorkDataList.Add(LCItem.Tag as WorkDataInfo);
  73. }
  74. else if (LCItem.Tag is List<WorkDataInfo>)
  75. {
  76. WorkDataList.AddRange(LCItem.Tag as List<WorkDataInfo>);
  77. }
  78. else
  79. {
  80. throw new Exception();
  81. }
  82. string s = "";
  83. if (LCItem.Control is ComboBoxEx)
  84. {
  85. ComboBoxEx Citem = LCItem.Control as ComboBoxEx;
  86. s = Citem.SelectedValue == null ? "" : Citem.SelectedValue.ToString();
  87. }
  88. else if (LCItem.Control is TextBoxX)
  89. {
  90. s = LCItem.Control.Text;
  91. }
  92. else if (LCItem.Control is LC_DropChkList)
  93. {
  94. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  95. s = ListToString(Item.GetValue());
  96. }
  97. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  98. {
  99. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  100. s = Item.Value.ToString();
  101. }
  102. else if (LCItem.Control is CheckBoxX)
  103. {
  104. CheckBoxX Item = LCItem.Control as CheckBoxX;
  105. if (Item.Checked)
  106. {
  107. s = "1";
  108. }
  109. else
  110. {
  111. s = "0";
  112. }
  113. }
  114. else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
  115. {
  116. DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
  117. s = Item.Value.ToString();
  118. }
  119. else
  120. {
  121. throw new Exception();
  122. }
  123. foreach (WorkDataInfo witem in WorkDataList)
  124. {
  125. witem.ParameterData = s;
  126. }
  127. return WorkDataList;
  128. }
  129. catch
  130. {
  131. }
  132. return null;
  133. }
  134. public static String ListToString(List<string> list)
  135. {
  136. string s = "";
  137. if (list != null)
  138. {
  139. int Count = list.Count;
  140. for (int i = 0; i < Count; i++)
  141. {
  142. if (i == 0)
  143. {
  144. s = list[i];
  145. continue;
  146. }
  147. s = s + "," + list[i];
  148. }
  149. }
  150. return s;
  151. }
  152. }
  153. public class WorkDataInfo
  154. {
  155. string _WorkName = "";
  156. /// <summary>
  157. /// 方法名
  158. /// </summary>
  159. public string WorkName
  160. {
  161. get
  162. {
  163. return _WorkName;
  164. }
  165. set
  166. {
  167. _WorkName = value;
  168. }
  169. }
  170. string _ParameterName = "";
  171. /// <summary>
  172. /// 参数名
  173. /// </summary>
  174. public string ParameterName
  175. {
  176. get
  177. {
  178. return _ParameterName;
  179. }
  180. set
  181. {
  182. _ParameterName = value;
  183. }
  184. }
  185. string _ParameterData = "";
  186. /// <summary>
  187. /// 参数数量
  188. /// </summary>
  189. public string ParameterData
  190. {
  191. get
  192. {
  193. return _ParameterData;
  194. }
  195. set
  196. {
  197. _ParameterData = value;
  198. }
  199. }
  200. }
  201. }