LCItemUtil.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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_ComboBoxEx(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  131. {
  132. ComboBoxEx ControlItem = new ComboBoxEx();
  133. ControlItem.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  134. ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  135. ControlItem.FormattingEnabled = true;
  136. ControlItem.ItemHeight = 15;
  137. ControlItem.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  138. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  139. if (DataChangeMethods != null)
  140. {
  141. ControlItem.SelectedValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  142. }
  143. return LCItem;
  144. }
  145. public static LayoutControlItem Add_SpacerItem(string LCName, int WidthItem, int HeightItem)
  146. {
  147. LayoutControlItem LCItem = new LayoutControlItem();
  148. LCItem.Padding = new System.Windows.Forms.Padding(3);
  149. LCItem.Name = LCName;
  150. LCItem.Text = "";
  151. LCItem.WidthType = eLayoutSizeType.Percent;
  152. LCItem.Width = WidthItem;
  153. LCItem.HeightType = eLayoutSizeType.Absolute;
  154. LCItem.Height = HeightItem;
  155. return LCItem;
  156. }
  157. public static LayoutControlItem Add_TwoDateTime(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods)
  158. {
  159. LC_TwoDateTime ControlItem = new LC_TwoDateTime();
  160. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  161. return LCItem;
  162. }
  163. public static LayoutControlItem Add_DateTimeInput(string LCName, string LblText, string CustomFormat, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  164. {
  165. DevComponents.Editors.DateTimeAdv.DateTimeInput ControlItem = new DevComponents.Editors.DateTimeAdv.DateTimeInput();
  166. ControlItem.BackgroundStyle.Class = "DateTimeInputBackground";
  167. ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  168. ControlItem.ButtonClear.Tooltip = "";
  169. ControlItem.ButtonCustom.Tooltip = "";
  170. ControlItem.ButtonCustom2.Tooltip = "";
  171. ControlItem.ButtonDropDown.Shortcut = DevComponents.DotNetBar.eShortcut.AltDown;
  172. ControlItem.ButtonDropDown.Tooltip = "";
  173. ControlItem.ButtonDropDown.Visible = true;
  174. ControlItem.ButtonFreeText.Tooltip = "";
  175. ControlItem.CustomFormat = CustomFormat;
  176. if (string.IsNullOrEmpty(CustomFormat))
  177. {
  178. ControlItem.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  179. }
  180. ControlItem.Format = DevComponents.Editors.eDateTimePickerFormat.Custom;
  181. ControlItem.IsPopupCalendarOpen = false;
  182. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  183. if (DataChangeMethods != null)
  184. {
  185. ControlItem.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
  186. }
  187. return LCItem;
  188. }
  189. public static LayoutControlItem Add_DropChkList(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
  190. {
  191. LC_DropChkList ControlItem = new LC_DropChkList();
  192. LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
  193. if (DataChangeMethods != null)
  194. {
  195. ControlItem.DataChangeEvent += new LC_DropChkList.DataChangeHandler(delegate() { DataChangeMethods(LCItem.Name); });
  196. }
  197. return LCItem;
  198. }
  199. #endregion
  200. public static void SetValue_LCItem(LayoutControlItem LCItem, object OItem)
  201. {
  202. try
  203. {
  204. if (LCItem.Control == null)
  205. {
  206. return;
  207. }
  208. if (LCItem.Control is ComboBoxEx)
  209. {
  210. ComboBoxEx Item = LCItem.Control as ComboBoxEx;
  211. Item.SelectedValue = OItem == null ? -1 : OItem;
  212. }
  213. else if (LCItem.Control is TextBoxX)
  214. {
  215. LCItem.Control.Text = OItem == null ? "" : OItem.ToString();
  216. }
  217. else if (LCItem.Control is LC_TwoDateTime)
  218. {
  219. LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
  220. Item.SetValue(OItem as List<DateTime>);
  221. }
  222. //else if (LCItem.Control is LC_DropChkList)
  223. //{
  224. // LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  225. // Item.SetValue(OItem as List<string>);
  226. //}
  227. else if (LCItem.Control is LC_DropChkList)
  228. {
  229. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  230. string s = OItem.ToString();
  231. Item.SetValue(s.Split(',').ToList());
  232. }
  233. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  234. {
  235. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  236. Item.Value = (OItem is int) ? int.Parse(OItem.ToString()) : 0;
  237. }
  238. else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
  239. {
  240. DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
  241. if (OItem == null || !(OItem is bool))
  242. {
  243. if (Item.ThreeState)
  244. {
  245. Item.CheckState = System.Windows.Forms.CheckState.Indeterminate;
  246. }
  247. else
  248. {
  249. Item.Checked = false;
  250. }
  251. }
  252. else
  253. {
  254. Item.Checked = (bool)OItem;
  255. }
  256. }
  257. else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
  258. {
  259. DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
  260. if (OItem == null || !(OItem is DateTime))
  261. {
  262. Item.Value = DateTime.MinValue;
  263. }
  264. else
  265. {
  266. Item.Value = (DateTime)OItem;
  267. }
  268. }
  269. }
  270. catch
  271. {
  272. }
  273. }
  274. public static object GetValue_LCItem(LayoutControlItem LCItem)
  275. {
  276. try
  277. {
  278. if (LCItem.Control == null)
  279. {
  280. return null;
  281. }
  282. if (LCItem.Control is ComboBoxEx)
  283. {
  284. ComboBoxEx Item = LCItem.Control as ComboBoxEx;
  285. return Item.SelectedValue;
  286. }
  287. else if (LCItem.Control is TextBoxX)
  288. {
  289. return LCItem.Control.Text;
  290. }
  291. else if (LCItem.Control is LC_TwoDateTime)
  292. {
  293. LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
  294. return Item.GetValue();
  295. }
  296. else if (LCItem.Control is LC_DropChkList)
  297. {
  298. LC_DropChkList Item = LCItem.Control as LC_DropChkList;
  299. return Item.GetValue();
  300. }
  301. else if (LCItem.Control is DevComponents.Editors.IntegerInput)
  302. {
  303. DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
  304. return Item.Value;
  305. }
  306. else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
  307. {
  308. DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
  309. if (Item.CheckState == System.Windows.Forms.CheckState.Indeterminate)
  310. {
  311. return null;
  312. }
  313. else
  314. {
  315. return Item.Checked;
  316. }
  317. }
  318. else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
  319. {
  320. DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
  321. if (Item.Value == DateTime.MinValue)
  322. {
  323. return null;
  324. }
  325. return Item.Value;
  326. }
  327. }
  328. catch
  329. {
  330. }
  331. return null;
  332. }
  333. public static void ClearValue_LCItem(List<LayoutControlItem> LCItemList)
  334. {
  335. if (LCItemList == null || LCItemList.Count <= 0)
  336. {
  337. return;
  338. }
  339. foreach (LayoutControlItem LCItem in LCItemList)
  340. {
  341. ClearValue_LCItem(LCItem);
  342. }
  343. }
  344. public static void ClearValue_LCItem(LayoutControlItem LCItem)
  345. {
  346. SetValue_LCItem(LCItem, null);
  347. }
  348. public static void Refresh_LCItem(LayoutControlItem LCItem, DataTable dt, string KeyField, string DisplayField)
  349. {
  350. if (LCItem.Control == null)
  351. {
  352. return;
  353. }
  354. if (LCItem.Control is ComboBoxEx)
  355. {
  356. ComboBoxEx citem = LCItem.Control as ComboBoxEx;
  357. string s = citem.SelectedValue == null ? "" : citem.SelectedValue.ToString();
  358. citem.ValueMember = KeyField;
  359. citem.DisplayMember = DisplayField;
  360. citem.DataSource = dt;
  361. citem.SelectedValue = s;
  362. }
  363. else if (LCItem.Control is LC_DropChkList)
  364. {
  365. LC_DropChkList citem = LCItem.Control as LC_DropChkList;
  366. citem.RefreshData(dt, KeyField, DisplayField);
  367. }
  368. }
  369. public static void SetReadOnly_LCItem(LayoutControlItem LCItem, bool IsReadOnly)
  370. {
  371. if (LCItem.Control == null)
  372. {
  373. return;
  374. }
  375. if (LCItem.Control is TextBoxX)
  376. {
  377. TextBoxX Item = LCItem.Control as TextBoxX;
  378. Item.ReadOnly = IsReadOnly;
  379. }
  380. else
  381. {
  382. LCItem.Control.Enabled = IsReadOnly;
  383. }
  384. }
  385. }
  386. }