123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DevComponents.DotNetBar;
- using DevComponents.DotNetBar.Layout;
- using DevComponents.DotNetBar.Controls;
- using System.Windows.Forms;
- using System.Data;
- namespace WCS_Client.UC
- {
- public class LCItemUtil
- {
- #region Add_LCItem
- public const int LCItem_Height = 27;
- public delegate void SubmitHandler(string LCName);
- public delegate void DataChangeHandler(string LCName);
- private static LayoutControlItem Add_Common(string LCName, System.Windows.Forms.Control LControl, string LblText, int WidthItem, eLayoutSizeType WidthTypeItem, int HeightItem, SubmitHandler SubmitMethods)
- {
- if (string.IsNullOrEmpty(LCName))
- {
- throw new Exception("UC_LayoutControlItem名称为空!!!");
- }
- LayoutControlItem LCItem = new LayoutControlItem();
- LCItem.Padding = new System.Windows.Forms.Padding(3);
- LCItem.Name = LCName;
- LCItem.Text = LblText;
- LCItem.WidthType = WidthTypeItem;
- LCItem.Width = WidthItem;
- LCItem.HeightType = eLayoutSizeType.Absolute;
- LCItem.Height = HeightItem;
- LCItem.Control = LControl;
- LControl.Name = "LC_" + LCName;
- LControl.Padding = new System.Windows.Forms.Padding(0);
- LControl.Margin = new System.Windows.Forms.Padding(0);
- if (SubmitMethods != null)
- {
- LControl.KeyDown += new System.Windows.Forms.KeyEventHandler(delegate(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- if (e.KeyCode == System.Windows.Forms.Keys.Enter)
- {
- SubmitMethods(LCItem.Name);
- }
- });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_TextboxX(string LCName, string LblText, bool IsPassWord, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- TextBoxX ControlItem = new TextBoxX();
- if (IsPassWord)
- {
- ControlItem.PasswordChar = '*';
- }
- ControlItem.Border.Class = "TextBoxBorder";
- ControlItem.Border.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.TextChanged += new EventHandler(delegate(object sender, EventArgs e)
- {
- DataChangeMethods(LCItem.Name);
- });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_TextboxX(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- return Add_TextboxX(LCName, LblText, false, WidthItem, SubmitMethods, DataChangeMethods);
- }
- public static LayoutControlItem Add_CheckBoxX(string LCName, string ControlText, bool ThreeState, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- CheckBoxX ControlItem = new CheckBoxX();
- ControlItem.Text = ControlText;
- ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- ControlItem.TextColor = System.Drawing.Color.Black;
- ControlItem.BackColor = System.Drawing.Color.Transparent;
- ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
- ControlItem.ThreeState = ThreeState;
- if (ThreeState)
- {
- ControlItem.CheckState = System.Windows.Forms.CheckState.Indeterminate;
- }
- else
- {
- ControlItem.Checked = false;
- }
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.CheckedChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_IntegerInput(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- DevComponents.Editors.IntegerInput ControlItem = new DevComponents.Editors.IntegerInput();
- ControlItem.BackgroundStyle.Class = "DateTimeInputBackground";
- ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- ControlItem.ButtonCalculator.DisplayPosition = 0;
- ControlItem.ButtonCalculator.Tooltip = "";
- ControlItem.ButtonCalculator.Visible = true;
- ControlItem.ButtonClear.Tooltip = "";
- ControlItem.ButtonCustom.Visible = false;
- ControlItem.ButtonCustom.Tooltip = "";
- ControlItem.ShowUpDown = true;
- ControlItem.MinValue = 0;
- ControlItem.Value = 0;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_ButtonX(string LCName, string BtnText, int WidthItem, int HeightItem, SubmitHandler SubmitMethods)
- {
- ButtonX ControlItem = new ButtonX();
- ControlItem.Text = BtnText;
- ControlItem.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
- ControlItem.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
- ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Absolute, HeightItem, SubmitMethods);
- if (SubmitMethods != null)
- {
- ControlItem.Click += new EventHandler(delegate(object sender, EventArgs e) { SubmitMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_Button(string LCName, string BtnText, int WidthItem, int HeightItem, eButtonColor color, SubmitHandler SubmitMethods)
- {
- ButtonX ControlItem = new ButtonX();
- ControlItem.Text = BtnText;
- ControlItem.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
- ControlItem.ColorTable = color;
- ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, "", WidthItem, eLayoutSizeType.Absolute, HeightItem, SubmitMethods);
- if (SubmitMethods != null)
- {
- ControlItem.Click += new EventHandler(delegate (object sender, EventArgs e) { SubmitMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_ComboBoxEx(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- ComboBoxEx ControlItem = new ComboBoxEx();
- ControlItem.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
- ControlItem.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
- ControlItem.FormattingEnabled = true;
- ControlItem.ItemHeight = 15;
- ControlItem.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.SelectedValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_SpacerItem(string LCName, int WidthItem, int HeightItem)
- {
- LayoutControlItem LCItem = new LayoutControlItem();
- LCItem.Padding = new System.Windows.Forms.Padding(3);
- LCItem.Name = LCName;
- LCItem.Text = "";
- LCItem.WidthType = eLayoutSizeType.Percent;
- LCItem.Width = WidthItem;
- LCItem.HeightType = eLayoutSizeType.Absolute;
- LCItem.Height = HeightItem;
- return LCItem;
- }
- public static LayoutControlItem Add_TwoDateTime(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods)
- {
- LC_TwoDateTime ControlItem = new LC_TwoDateTime();
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- return LCItem;
- }
- public static LayoutControlItem Add_DateTimeInput(string LCName, string LblText, string CustomFormat, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- DevComponents.Editors.DateTimeAdv.DateTimeInput ControlItem = new DevComponents.Editors.DateTimeAdv.DateTimeInput();
- ControlItem.BackgroundStyle.Class = "DateTimeInputBackground";
- ControlItem.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
- ControlItem.ButtonClear.Tooltip = "";
- ControlItem.ButtonCustom.Tooltip = "";
- ControlItem.ButtonCustom2.Tooltip = "";
- ControlItem.ButtonDropDown.Shortcut = DevComponents.DotNetBar.eShortcut.AltDown;
- ControlItem.ButtonDropDown.Tooltip = "";
- ControlItem.ButtonDropDown.Visible = true;
- ControlItem.ButtonFreeText.Tooltip = "";
- ControlItem.CustomFormat = CustomFormat;
- if (string.IsNullOrEmpty(CustomFormat))
- {
- ControlItem.CustomFormat = "yyyy-MM-dd HH:mm:ss";
- }
- ControlItem.Format = DevComponents.Editors.eDateTimePickerFormat.Custom;
- ControlItem.IsPopupCalendarOpen = false;
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { DataChangeMethods(LCItem.Name); });
- }
- return LCItem;
- }
- public static LayoutControlItem Add_DropChkList(string LCName, string LblText, int WidthItem, SubmitHandler SubmitMethods, DataChangeHandler DataChangeMethods)
- {
- LC_DropChkList ControlItem = new LC_DropChkList();
- LayoutControlItem LCItem = Add_Common(LCName, ControlItem, LblText, WidthItem, eLayoutSizeType.Percent, LCItem_Height, SubmitMethods);
- if (DataChangeMethods != null)
- {
- ControlItem.DataChangeEvent += new LC_DropChkList.DataChangeHandler(delegate() { DataChangeMethods(LCItem.Name); });
- }
- return LCItem;
- }
- #endregion
- public static void SetValue_LCItem(LayoutControlItem LCItem, object OItem)
- {
- try
- {
- if (LCItem.Control == null)
- {
- return;
- }
- if (LCItem.Control is ComboBoxEx)
- {
- ComboBoxEx Item = LCItem.Control as ComboBoxEx;
- Item.SelectedValue = OItem == null ? -1 : OItem;
- }
- else if (LCItem.Control is TextBoxX)
- {
- LCItem.Control.Text = OItem == null ? "" : OItem.ToString();
- }
- else if (LCItem.Control is LC_TwoDateTime)
- {
- LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
- Item.SetValue(OItem as List<DateTime>);
- }
- //else if (LCItem.Control is LC_DropChkList)
- //{
- // LC_DropChkList Item = LCItem.Control as LC_DropChkList;
- // Item.SetValue(OItem as List<string>);
- //}
- else if (LCItem.Control is LC_DropChkList)
- {
- LC_DropChkList Item = LCItem.Control as LC_DropChkList;
- string s = OItem.ToString();
- Item.SetValue(s.Split(',').ToList());
- }
- else if (LCItem.Control is DevComponents.Editors.IntegerInput)
- {
- DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
- Item.Value = (OItem is int) ? int.Parse(OItem.ToString()) : 0;
- }
- else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
- {
- DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
- if (OItem == null || !(OItem is bool))
- {
- if (Item.ThreeState)
- {
- Item.CheckState = System.Windows.Forms.CheckState.Indeterminate;
- }
- else
- {
- Item.Checked = false;
- }
- }
- else
- {
- Item.Checked = (bool)OItem;
- }
- }
- else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
- {
- DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
- if (OItem == null || !(OItem is DateTime))
- {
- Item.Value = DateTime.MinValue;
- }
- else
- {
- Item.Value = (DateTime)OItem;
- }
- }
- }
- catch
- {
- }
- }
- public static object GetValue_LCItem(LayoutControlItem LCItem)
- {
- try
- {
- if (LCItem.Control == null)
- {
- return null;
- }
- if (LCItem.Control is ComboBoxEx)
- {
- ComboBoxEx Item = LCItem.Control as ComboBoxEx;
- return Item.SelectedValue;
- }
- else if (LCItem.Control is TextBoxX)
- {
- return LCItem.Control.Text;
- }
- else if (LCItem.Control is LC_TwoDateTime)
- {
- LC_TwoDateTime Item = LCItem.Control as LC_TwoDateTime;
- return Item.GetValue();
- }
- else if (LCItem.Control is LC_DropChkList)
- {
- LC_DropChkList Item = LCItem.Control as LC_DropChkList;
- return Item.GetValue();
- }
- else if (LCItem.Control is DevComponents.Editors.IntegerInput)
- {
- DevComponents.Editors.IntegerInput Item = LCItem.Control as DevComponents.Editors.IntegerInput;
- return Item.Value;
- }
- else if (LCItem.Control is DevComponents.DotNetBar.Controls.CheckBoxX)
- {
- DevComponents.DotNetBar.Controls.CheckBoxX Item = LCItem.Control as DevComponents.DotNetBar.Controls.CheckBoxX;
- if (Item.CheckState == System.Windows.Forms.CheckState.Indeterminate)
- {
- return null;
- }
- else
- {
- return Item.Checked;
- }
- }
- else if (LCItem.Control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
- {
- DevComponents.Editors.DateTimeAdv.DateTimeInput Item = LCItem.Control as DevComponents.Editors.DateTimeAdv.DateTimeInput;
- if (Item.Value == DateTime.MinValue)
- {
- return null;
- }
- return Item.Value;
- }
- }
- catch
- {
- }
- return null;
- }
- public static void ClearValue_LCItem(List<LayoutControlItem> LCItemList)
- {
- if (LCItemList == null || LCItemList.Count <= 0)
- {
- return;
- }
- foreach (LayoutControlItem LCItem in LCItemList)
- {
- ClearValue_LCItem(LCItem);
- }
- }
- public static void ClearValue_LCItem(LayoutControlItem LCItem)
- {
- SetValue_LCItem(LCItem, null);
- }
- public static void Refresh_LCItem(LayoutControlItem LCItem, DataTable dt, string KeyField, string DisplayField)
- {
- if (LCItem.Control == null)
- {
- return;
- }
- if (LCItem.Control is ComboBoxEx)
- {
- ComboBoxEx citem = LCItem.Control as ComboBoxEx;
- string s = citem.SelectedValue == null ? "" : citem.SelectedValue.ToString();
- citem.ValueMember = KeyField;
- citem.DisplayMember = DisplayField;
- citem.DataSource = dt;
- citem.SelectedValue = s;
- }
- else if (LCItem.Control is LC_DropChkList)
- {
- LC_DropChkList citem = LCItem.Control as LC_DropChkList;
- citem.RefreshData(dt, KeyField, DisplayField);
- }
- }
- public static void SetReadOnly_LCItem(LayoutControlItem LCItem, bool IsReadOnly)
- {
- if (LCItem.Control == null)
- {
- return;
- }
- if (LCItem.Control is TextBoxX)
- {
- TextBoxX Item = LCItem.Control as TextBoxX;
- Item.ReadOnly = IsReadOnly;
- }
- else
- {
- LCItem.Control.Enabled = IsReadOnly;
- }
- }
- }
- }
|