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); } //else if (LCItem.Control is LC_DropChkList) //{ // LC_DropChkList Item = LCItem.Control as LC_DropChkList; // Item.SetValue(OItem as List); //} 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 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; } } } }