LCItemUtil.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using DevComponents.DotNetBar;
  6. using DevComponents.DotNetBar.Layout;
  7. using DevComponents.DotNetBar.Controls;
  8. using System.Windows.Forms;
  9. using System.Data;
  10. namespace WCS_Client.UC
  11. {
  12. public class LCItemUtil
  13. {
  14. #region Add_LCItem
  15. public const int LCItem_Height = 27;
  16. public delegate void SubmitHandler(string LCName);
  17. public delegate void DataChangeHandler(string LCName);
  18. private static LayoutControlItem Add_Common(string LCName, System.Windows.Forms.Control LControl, string LblText, int WidthItem, eLayoutSizeType WidthTypeItem, int HeightItem, SubmitHandler SubmitMethods)
  19. {
  20. if (string.IsNullOrEmpty(LCName))
  21. {
  22. throw new Exception("UC_LayoutControlItem名称为空!!!");
  23. }
  24. LayoutControlItem LCItem = new LayoutControlItem();
  25. LCItem.Padding = new System.Windows.Forms.Padding(3);
  26. LCItem.Name = LCName;
  27. LCItem.Text = LblText;
  28. LCItem.WidthType = WidthTypeItem;
  29. LCItem.Width = WidthItem;
  30. LCItem.HeightType = eLayoutSizeType.Absolute;
  31. LCItem.Height = HeightItem;
  32. LCItem.Control = LControl;
  33. LControl.Name = "LC_" + LCName;
  34. LControl.Padding = new System.Windows.Forms.Padding(0);
  35. LControl.Margin = new System.Windows.Forms.Padding(0);
  36. if (SubmitMethods != null)
  37. {
  38. LControl.KeyDown += new System.Windows.Forms.KeyEventHandler(delegate(object sender, System.Windows.Forms.KeyEventArgs e)
  39. {
  40. if (e.KeyCode == System.Windows.Forms.Keys.Enter)
  41. {
  42. SubmitMethods(LCItem.Name);
  43. }
  44. });
  45. }
  46. return LCItem;
  47. }
  48. public static LayoutControlItem Add_TextboxX(string LCName, string LblText, bool IsPassWord, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  49. {
  50. TextBoxX ControlItem = new TextBoxX();
  51. if (IsPassWord)
  52. {
  53. ControlItem.PasswordChar = '*';
  54. }
  55. ControlItem.Border.Class = "TextBoxBorder";
  56. ControlItem.Border.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  57. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  58. if (DataChangeMethods != null)
  59. {
  60. ControlItem.TextChanged += new EventHandler(delegate(object sender, EventArgs e)
  61. {
  62. DataChangeMethods(LCItem.Name);
  63. });
  64. }
  65. return LCItem;
  66. }
  67. public static LayoutControlItem Add_TextboxX(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  68. {
  69. return Add_TextboxX(LCName, LblText, false, WidthItem, SubmitMethods, DataChangeMethods);
  70. }
  71. public static LayoutControlItem Add_CheckBoxX(string LCName, string ControlText, bool ThreeState, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  72. {
  73. CheckBoxX ControlItem = new CheckBoxX();
  74. ControlItem.Text = ControlText;
  75. ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  76. ControlItem.TextColor = System.Drawing.Color.Black;
  77. ControlItem.BackColor = System.Drawing.Color.Transparent;
  78. ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  79. ControlItem.ThreeState = ThreeState;
  80. if (ThreeState)
  81. {
  82. ControlItem.CheckState = System.Windows.Forms.CheckState.Indeterminate;
  83. }
  84. else
  85. {
  86. ControlItem.Checked = false;
  87. }
  88. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  89. if (DataChangeMethods != null)
  90. {
  91. ControlItem.CheckedChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  92. }
  93. return LCItem;
  94. }
  95. public static LayoutControlItem Add_IntegerInput(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  96. {
  97. DevComponents.Editors.IntegerInput ControlItem = new DevComponents.Editors.IntegerInput();
  98. ControlItem.BackgroundStyle.Class = "DateTimeInputBackground";
  99. ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  100. ControlItem.ButtonCalculator.DisplayPosition = 0;
  101. ControlItem.ButtonCalculator.Tooltip = "";
  102. ControlItem.ButtonCalculator.Visible = true;
  103. ControlItem.ButtonClear.Tooltip = "";
  104. ControlItem.ButtonCustom.Visible = false;
  105. ControlItem.ButtonCustom.Tooltip = "";
  106. ControlItem.ShowUpDown = true;
  107. ControlItem.MinValue = 0;
  108. ControlItem.Value = 0;
  109. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  110. if (DataChangeMethods != null)
  111. {
  112. ControlItem.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  113. }
  114. return LCItem;
  115. }
  116. public static LayoutControlItem Add_ButtonX(string LCName, string BtnText, int WidthItem, int HeightItem, SubmitHandler SubmitMethods)
  117. {
  118. ButtonX ControlItem = new ButtonX();
  119. ControlItem.Text = BtnText;
  120. ControlItem.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
  121. ControlItem.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
  122. ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  123. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Absolute, HeightItem, SubmitMethods);
  124. if (SubmitMethods != null)
  125. {
  126. ControlItem.Click += new EventHandler(delegate(object sender, EventArgs e) { SubmitMethods(LCItem.Name); });
  127. }
  128. return LCItem;
  129. }
  130. public static LayoutControlItem Add_Button(string LCName, string BtnText, int WidthItem, int HeightItem,eButtonColor color, SubmitHandler SubmitMethods)
  131. {
  132. ButtonX ControlItem = new ButtonX();
  133. ControlItem.Text = BtnText;
  134. ControlItem.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
  135. ControlItem.ColorTable = color;
  136. ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  137. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Absolute, HeightItem, SubmitMethods);
  138. if (SubmitMethods != null)
  139. {
  140. ControlItem.Click += new EventHandler(delegate (object sender, EventArgs e) { SubmitMethods(LCItem.Name); });
  141. }
  142. return LCItem;
  143. }
  144. public static LayoutControlItem Add_ComboBoxEx(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  145. {
  146. ComboBoxEx ControlItem = new ComboBoxEx();
  147. ControlItem.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  148. ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  149. ControlItem.FormattingEnabled = true;
  150. ControlItem.ItemHeight = 15;
  151. ControlItem.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  152. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  153. if (DataChangeMethods != null)
  154. {
  155. ControlItem.SelectedValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  156. }
  157. return LCItem;
  158. }
  159. public static LayoutControlItem Add_SpacerItem(string LCName, int WidthItem, int HeightItem)
  160. {
  161. LayoutControlItem LCItem = new LayoutControlItem();
  162. LCItem.Padding = new System.Windows.Forms.Padding(3);
  163. LCItem.Name = LCName;
  164. LCItem.Text = "";
  165. LCItem.WidthType = eLayoutSizeType.Percent;
  166. LCItem.Width = WidthItem;
  167. LCItem.HeightType = eLayoutSizeType.Absolute;
  168. LCItem.Height = HeightItem;
  169. return LCItem;
  170. }
  171. public static LayoutControlItem Add_TwoDateTime(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods)
  172. {
  173. LC_TwoDateTime ControlItem = new LC_TwoDateTime();
  174. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  175. return LCItem;
  176. }
  177. public static LayoutControlItem Add_DateTimeInput(string LCName, string LblText, string CustomFormat, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  178. {
  179. DevComponents.Editors.DateTimeAdv.DateTimeInput ControlItem = new DevComponents.Editors.DateTimeAdv.DateTimeInput();
  180. ControlItem.BackgroundStyle.Class = "DateTimeInputBackground";
  181. ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  182. ControlItem.ButtonClear.Tooltip = "";
  183. ControlItem.ButtonCustom.Tooltip = "";
  184. ControlItem.ButtonCustom2.Tooltip = "";
  185. ControlItem.ButtonDropDown.Shortcut = DevComponents.DotNetBar.eShortcut.AltDown;
  186. ControlItem.ButtonDropDown.Tooltip = "";
  187. ControlItem.ButtonDropDown.Visible = true;
  188. ControlItem.ButtonFreeText.Tooltip = "";
  189. ControlItem.CustomFormat = CustomFormat;
  190. if (string.IsNullOrEmpty(CustomFormat))
  191. {
  192. ControlItem.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  193. }
  194. ControlItem.Format = DevComponents.Editors.eDateTimePickerFormat.Custom;
  195. ControlItem.IsPopupCalendarOpen = false;
  196. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  197. if (DataChangeMethods != null)
  198. {
  199. ControlItem.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  200. }
  201. return LCItem;
  202. }
  203. public static LayoutControlItem Add_DropChkList(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  204. {
  205. LC_DropChkList ControlItem = new LC_DropChkList();
  206. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  207. if (DataChangeMethods != null)
  208. {
  209. ControlItem.DataChangeEvent += new LC_DropChkList.DataChangeHandler(delegate() { DataChangeMethods(LCItem.Name); });
  210. }
  211. return LCItem;
  212. }
  213. #endregion
  214. public static void SetValue_LCItem(LayoutControlItem LCItem, object OItem)
  215. {
  216. try
  217. {
  218. if (LCItem.Control == null)
  219. {
  220. return;
  221. }
  222. if (LCItem.Control is ComboBoxEx)
  223. {
  224. ComboBoxEx Item = LCItem.Control as ComboBoxEx;
  225. Item.SelectedValue = OItem == null ? -1 : OItem;
  226. }
  227. else if (LCItem.Control is TextBoxX)
  228. {
  229. LCItem.Control.Text = OItem == null ? "" : OItem.ToString();
  230. }
  231. else if (LCItem.Control is LC_TwoDateTime)
  232. {
  233. LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
  234. Item.SetValue(OItem as List<DateTime>);
  235. }
  236. //else if (LCItem.Control is LC_DropChkList)
  237. //{
  238. // LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  239. // Item.SetValue(OItem as List<string>);
  240. //}
  241. else if (LCItem.Control is LC_DropChkList)
  242. {
  243. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  244. string s = OItem.ToString();
  245. Item.SetValue(s.Split(',').ToList());
  246. }
  247. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  248. {
  249. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  250. Item.Value = (OItem is int) ? int.Parse(OItem.ToString()) : 0;
  251. }
  252. else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
  253. {
  254. DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
  255. if (OItem == null || !(OItem is bool))
  256. {
  257. if (Item.ThreeState)
  258. {
  259. Item.CheckState = System.Windows.Forms.CheckState.Indeterminate;
  260. }
  261. else
  262. {
  263. Item.Checked = false;
  264. }
  265. }
  266. else
  267. {
  268. Item.Checked = (bool)OItem;
  269. }
  270. }
  271. else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
  272. {
  273. DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
  274. if (OItem == null || !(OItem is DateTime))
  275. {
  276. Item.Value = DateTime.MinValue;
  277. }
  278. else
  279. {
  280. Item.Value = (DateTime)OItem;
  281. }
  282. }
  283. }
  284. catch
  285. {
  286. }
  287. }
  288. public static object GetValue_LCItem(LayoutControlItem LCItem)
  289. {
  290. try
  291. {
  292. if (LCItem == null)
  293. return null;
  294. if (LCItem.Control == null)
  295. {
  296. return null;
  297. }
  298. if (LCItem.Control is ComboBoxEx)
  299. {
  300. ComboBoxEx Item = LCItem.Control as ComboBoxEx;
  301. return Item.SelectedValue;
  302. }
  303. else if (LCItem.Control is TextBoxX)
  304. {
  305. return LCItem.Control.Text;
  306. }
  307. else if (LCItem.Control is LC_TwoDateTime)
  308. {
  309. LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
  310. return Item.GetValue();
  311. }
  312. else if (LCItem.Control is LC_DropChkList)
  313. {
  314. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  315. return Item.GetValue();
  316. }
  317. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  318. {
  319. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  320. return Item.Value;
  321. }
  322. else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
  323. {
  324. DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
  325. if (Item.CheckState == System.Windows.Forms.CheckState.Indeterminate)
  326. {
  327. return null;
  328. }
  329. else
  330. {
  331. return Item.Checked;
  332. }
  333. }
  334. else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
  335. {
  336. DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
  337. if (Item.Value == DateTime.MinValue)
  338. {
  339. return null;
  340. }
  341. return Item.Value;
  342. }
  343. }
  344. catch
  345. {
  346. }
  347. return null;
  348. }
  349. public static void ClearValue_LCItem(List<LayoutControlItem> LCItemList)
  350. {
  351. if (LCItemList == null || LCItemList.Count <= 0)
  352. {
  353. return;
  354. }
  355. foreach (LayoutControlItem LCItem in LCItemList)
  356. {
  357. ClearValue_LCItem(LCItem);
  358. }
  359. }
  360. public static void ClearValue_LCItem(LayoutControlItem LCItem)
  361. {
  362. SetValue_LCItem(LCItem, null);
  363. }
  364. public static void Refresh_LCItem(LayoutControlItem LCItem, DataTable dt, string KeyField, string DisplayField)
  365. {
  366. if (LCItem.Control == null)
  367. {
  368. return;
  369. }
  370. if (LCItem.Control is ComboBoxEx)
  371. {
  372. ComboBoxEx citem = LCItem.Control as ComboBoxEx;
  373. string s = citem.SelectedValue == null ? "" : citem.SelectedValue.ToString();
  374. citem.ValueMember = KeyField;
  375. citem.DisplayMember = DisplayField;
  376. citem.DataSource = dt;
  377. citem.SelectedValue = s;
  378. }
  379. else if (LCItem.Control is LC_DropChkList)
  380. {
  381. LC_DropChkList citem = LCItem.Control as LC_DropChkList;
  382. citem.RefreshData(dt, KeyField, DisplayField);
  383. }
  384. }
  385. public static void SetReadOnly_LCItem(LayoutControlItem LCItem, bool IsReadOnly)
  386. {
  387. if (LCItem.Control == null)
  388. {
  389. return;
  390. }
  391. if (LCItem.Control is TextBoxX)
  392. {
  393. TextBoxX Item = LCItem.Control as TextBoxX;
  394. Item.ReadOnly = IsReadOnly;
  395. }
  396. else
  397. {
  398. LCItem.Control.Enabled = IsReadOnly;
  399. }
  400. }
  401. }
  402. }