LCWhereUtil.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using DevComponents.DotNetBar.Layout;
  6. using DevComponents.DotNetBar.Controls;
  7. namespace WCS_Client.UC
  8. {
  9. public class LCWhereUtil
  10. {
  11. public static List<string> GetWhereText(List<LayoutControlItem> LCItemList)
  12. {
  13. try
  14. {
  15. List<LCWhereInfo> QWList = new List<LCWhereInfo>();
  16. foreach (LayoutControlItem Item in LCItemList)
  17. {
  18. if (Item == null || Item.Control == null || Item.Tag == null)
  19. {
  20. continue;
  21. }
  22. if (Item.Tag is LCWhereInfo)
  23. {
  24. LCWhereInfo QWItem = Item.Tag as LCWhereInfo;
  25. if (string.IsNullOrEmpty(QWItem.QWhereText))
  26. {
  27. continue;
  28. }
  29. string s = Get_LCWhere(Item, QWItem.QWhereText);
  30. if (string.IsNullOrEmpty(s))
  31. {
  32. continue;
  33. }
  34. QWList.Add(new LCWhereInfo() { QWhereText = s, ReplaceNo = QWItem.ReplaceNo, GroupNo = QWItem.GroupNo });
  35. }
  36. else if (Item.Tag is List<LCWhereInfo>)
  37. {
  38. List<LCWhereInfo> QWItemList = Item.Tag as List<LCWhereInfo>;
  39. foreach (LCWhereInfo qitem in QWItemList)
  40. {
  41. if (string.IsNullOrEmpty(qitem.QWhereText))
  42. {
  43. continue;
  44. }
  45. string s = Get_LCWhere(Item, qitem.QWhereText);
  46. if (string.IsNullOrEmpty(s))
  47. {
  48. continue;
  49. }
  50. QWList.Add(new LCWhereInfo() { QWhereText = s, ReplaceNo = qitem.ReplaceNo, GroupNo = qitem.GroupNo });
  51. }
  52. }
  53. }
  54. if (QWList.Count > 0)
  55. {
  56. List<LCWhereInfo> QGroupList = new List<LCWhereInfo>();
  57. foreach (LCWhereInfo qitem in QWList)
  58. {
  59. LCWhereInfo Nqitem = QGroupList.Find(a => a.ReplaceNo == qitem.ReplaceNo && a.GroupNo == qitem.GroupNo);
  60. if (Nqitem == null)
  61. {
  62. QGroupList.Add(new LCWhereInfo() { ReplaceNo = qitem.ReplaceNo, QWhereText = qitem.QWhereText, GroupNo = qitem.GroupNo });
  63. continue;
  64. }
  65. if (Nqitem.GroupNo == -1)
  66. {
  67. Nqitem.QWhereText = string.Format("{0} and {1}", Nqitem.QWhereText, qitem.QWhereText);
  68. }
  69. else
  70. {
  71. Nqitem.QWhereText = string.Format("{0} or {1}", Nqitem.QWhereText, qitem.QWhereText);
  72. }
  73. }
  74. List<LCWhereInfo> QReplaceList = new List<LCWhereInfo>();
  75. foreach (LCWhereInfo reitem in QGroupList)
  76. {
  77. LCWhereInfo Nqitem = QReplaceList.Find(a => a.ReplaceNo == reitem.ReplaceNo);
  78. if (Nqitem == null)
  79. {
  80. if (reitem.GroupNo == -1)
  81. {
  82. QReplaceList.Add(new LCWhereInfo() { ReplaceNo = reitem.ReplaceNo, QWhereText = reitem.QWhereText, GroupNo = -1 });
  83. }
  84. else
  85. {
  86. QReplaceList.Add(new LCWhereInfo() { ReplaceNo = reitem.ReplaceNo, QWhereText = string.Format("({0})", reitem.QWhereText), GroupNo = -1 });
  87. }
  88. }
  89. else
  90. {
  91. if (reitem.GroupNo == -1)
  92. {
  93. Nqitem.QWhereText = string.Format("{0} and {1}", Nqitem.QWhereText, reitem.QWhereText);
  94. }
  95. else
  96. {
  97. Nqitem.QWhereText = string.Format("{0} and ({1})", Nqitem.QWhereText, reitem.QWhereText);
  98. }
  99. }
  100. }
  101. return (from n in QReplaceList
  102. orderby n.ReplaceNo
  103. select n.QWhereText).ToList();
  104. }
  105. }
  106. catch
  107. {
  108. }
  109. return null;
  110. }
  111. public static string Get_LCWhere(LayoutControlItem LCItem, string ReplaceString)
  112. {
  113. return Get_LCWhere(LCItem, "", ReplaceString);
  114. }
  115. public static string Get_LCWhere(LayoutControlItem LCItem, string ConnAndOr, string ReplaceString)
  116. {
  117. try
  118. {
  119. if (LCItem == null || LCItem.Control == null || string.IsNullOrEmpty(ReplaceString))
  120. {
  121. throw new Exception();
  122. }
  123. string s = "";
  124. if (LCItem.Control is TextBoxX)
  125. {
  126. if (string.IsNullOrEmpty(LCItem.Control.Text))
  127. {
  128. throw new Exception();
  129. }
  130. s = string.Format(ReplaceString, LCItem.Control.Text);
  131. }
  132. else if (LCItem.Control is ComboBoxEx)
  133. {
  134. ComboBoxEx Citem = LCItem.Control as ComboBoxEx;
  135. if (Citem.SelectedValue == null || string.IsNullOrEmpty(Citem.SelectedValue.ToString()))
  136. {
  137. throw new Exception();
  138. }
  139. s = string.Format(ReplaceString, Citem.SelectedValue.ToString());
  140. }
  141. else if (LCItem.Control is LC_DropChkList)
  142. {
  143. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  144. List<string> DataItemList = Item.GetValue();
  145. if (DataItemList == null || DataItemList.Count == 0)
  146. {
  147. throw new Exception();
  148. }
  149. bool istag = true;
  150. foreach (string str in DataItemList)
  151. {
  152. if (istag)
  153. {
  154. s = string.Format(ReplaceString, str);
  155. istag = false;
  156. continue;
  157. }
  158. s = s + " or " + string.Format(ReplaceString, str);
  159. }
  160. }
  161. else if (LCItem.Control is LC_TwoDateTime)
  162. {
  163. LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
  164. List<DateTime> dtList = Item.GetValue();
  165. if (dtList == null || dtList.Count != 2)
  166. {
  167. throw new Exception();
  168. }
  169. s = string.Format(ReplaceString, dtList[0], dtList[1]);
  170. }
  171. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  172. {
  173. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  174. if (Item.Value <= 0)
  175. {
  176. throw new Exception();
  177. }
  178. s = string.Format(ReplaceString, Item.Value);
  179. }
  180. else if (LCItem.Control is CheckBoxX)
  181. {
  182. CheckBoxX Item = LCItem.Control as CheckBoxX;
  183. if (Item.CheckState == System.Windows.Forms.CheckState.Indeterminate)
  184. {
  185. throw new Exception();
  186. }
  187. s = string.Format(ReplaceString, Item.Checked ? 1 : 0);
  188. }
  189. else
  190. {
  191. throw new Exception();
  192. }
  193. if (!string.IsNullOrEmpty(s))
  194. {
  195. s = string.Format(" {0} ({1})", ConnAndOr, s);
  196. }
  197. return s;
  198. }
  199. catch
  200. {
  201. }
  202. return "";
  203. }
  204. public static string Get_LCWhereOr(LayoutControlItem LCItem, string ReplaceString)
  205. {
  206. return Get_LCWhere(LCItem, "Or", ReplaceString);
  207. }
  208. public static string Get_LCWhereAnd(LayoutControlItem LCItem, string ReplaceString)
  209. {
  210. return Get_LCWhere(LCItem, "And", ReplaceString);
  211. }
  212. }
  213. public class LCWhereInfo
  214. {
  215. string _QWhereText = "";
  216. public string QWhereText
  217. {
  218. get
  219. {
  220. return _QWhereText;
  221. }
  222. set
  223. {
  224. _QWhereText = value;
  225. }
  226. }
  227. int _ReplaceNo = 0;
  228. public int ReplaceNo
  229. {
  230. get
  231. {
  232. return _ReplaceNo;
  233. }
  234. set
  235. {
  236. _ReplaceNo = value;
  237. }
  238. }
  239. int _GroupNo = -1;
  240. public int GroupNo
  241. {
  242. get
  243. {
  244. return _GroupNo;
  245. }
  246. set
  247. {
  248. _GroupNo = value;
  249. }
  250. }
  251. }
  252. }