using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar.Controls; namespace WCS_Client.UC { public class LC_TwoDateTime : TextBoxDropDown { public LC_TwoDateTime() { this.BackgroundStyle.Class = "TextBoxBorder"; this.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; this.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.BackColor = System.Drawing.SystemColors.Control; this.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); this.ReadOnly = true; this.ButtonCustom.Visible = true; this.ButtonCustom.Shortcut = DevComponents.DotNetBar.eShortcut.Ins; this.ButtonCustomClick += new EventHandler(Item_ButtonCustomClick); this.ButtonCustom2.Visible = false; this.ButtonDropDown.Visible = false; this.ButtonClear.Visible = true; this.ButtonClear.Shortcut = DevComponents.DotNetBar.eShortcut.Del; this.ButtonClearClick += new System.ComponentModel.CancelEventHandler(Item_ButtonClearClick); } DateTime _StartDateTime = DateTime.MinValue; DateTime _EndDateTime = DateTime.MinValue; private void Item_ButtonCustomClick(object sender, EventArgs e) { Frm_TowDateTime frm = new Frm_TowDateTime(_StartDateTime, _EndDateTime); frm.SubmitEvent += new Frm_TowDateTime.SubmitHandler(frm_SubmitEvent); frm.ShowDialog(); frm = null; } public List GetValue() { if (!IsValueNull()) { return new List() { _StartDateTime, _EndDateTime }; } return null; } public void SetValue(List LCValue) { if (LCValue == null || LCValue.Count != 2) { frm_SubmitEvent(DateTime.MinValue, DateTime.MinValue); } else { frm_SubmitEvent(LCValue[0], LCValue[1]); } } /// /// 控件数据改变 /// private void frm_SubmitEvent(DateTime SDataTime, DateTime EDateTime) { if (SDataTime == DateTime.MinValue || EDateTime == DateTime.MinValue || SDataTime > EDateTime) { _StartDateTime = DateTime.MinValue; _EndDateTime = DateTime.MinValue; this.Text = ""; } else { _StartDateTime = SDataTime; _EndDateTime = EDateTime; this.Text = string.Format("[{0}] 至 [{1}]", _StartDateTime.ToString("yyyy-MM-dd HH:mm:ss"), _EndDateTime.ToString("yyyy-MM-dd HH:mm:ss")); } } /// /// 是否控件输入值是否为空 /// /// true,空值;false,已经输入值 public bool IsValueNull() { return (_StartDateTime == DateTime.MinValue || _EndDateTime == DateTime.MinValue || _StartDateTime > _EndDateTime); } private void Item_ButtonClearClick(object sender, System.ComponentModel.CancelEventArgs e) { this.Text = ""; _StartDateTime = DateTime.MinValue; _EndDateTime = DateTime.MinValue; } public void ClearValue() { Item_ButtonClearClick(null, null); } } }