LC_TwoDateTime.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using DevComponents.DotNetBar.Controls;
  7. namespace WCS_Client.UC
  8. {
  9. public class LC_TwoDateTime : TextBoxDropDown
  10. {
  11. public LC_TwoDateTime()
  12. {
  13. this.BackgroundStyle.Class = "TextBoxBorder";
  14. this.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
  15. this.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  16. this.BackColor = System.Drawing.SystemColors.Control;
  17. this.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0);
  18. this.ReadOnly = true;
  19. this.ButtonCustom.Visible = true;
  20. this.ButtonCustom.Shortcut = DevComponents.DotNetBar.eShortcut.Ins;
  21. this.ButtonCustomClick += new EventHandler(Item_ButtonCustomClick);
  22. this.ButtonCustom2.Visible = false;
  23. this.ButtonDropDown.Visible = false;
  24. this.ButtonClear.Visible = true;
  25. this.ButtonClear.Shortcut = DevComponents.DotNetBar.eShortcut.Del;
  26. this.ButtonClearClick += new System.ComponentModel.CancelEventHandler(Item_ButtonClearClick);
  27. }
  28. DateTime _StartDateTime = DateTime.MinValue;
  29. DateTime _EndDateTime = DateTime.MinValue;
  30. private void Item_ButtonCustomClick(object sender, EventArgs e)
  31. {
  32. Frm_TowDateTime frm = new Frm_TowDateTime(_StartDateTime, _EndDateTime);
  33. frm.SubmitEvent += new Frm_TowDateTime.SubmitHandler(frm_SubmitEvent);
  34. frm.ShowDialog();
  35. frm = null;
  36. }
  37. public List<DateTime> GetValue()
  38. {
  39. if (!IsValueNull())
  40. {
  41. return new List<DateTime>() { _StartDateTime, _EndDateTime };
  42. }
  43. return null;
  44. }
  45. public void SetValue(List<DateTime> LCValue)
  46. {
  47. if (LCValue == null || LCValue.Count != 2)
  48. {
  49. frm_SubmitEvent(DateTime.MinValue, DateTime.MinValue);
  50. }
  51. else
  52. {
  53. frm_SubmitEvent(LCValue[0], LCValue[1]);
  54. }
  55. }
  56. /// <summary>
  57. /// 控件数据改变
  58. /// </summary>
  59. private void frm_SubmitEvent(DateTime SDataTime, DateTime EDateTime)
  60. {
  61. if (SDataTime == DateTime.MinValue || EDateTime == DateTime.MinValue || SDataTime > EDateTime)
  62. {
  63. _StartDateTime = DateTime.MinValue;
  64. _EndDateTime = DateTime.MinValue;
  65. this.Text = "";
  66. }
  67. else
  68. {
  69. _StartDateTime = SDataTime;
  70. _EndDateTime = EDateTime;
  71. this.Text = string.Format("[{0}] 至 [{1}]", _StartDateTime.ToString("yyyy-MM-dd HH:mm:ss"), _EndDateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  72. }
  73. }
  74. /// <summary>
  75. /// 是否控件输入值是否为空
  76. /// </summary>
  77. /// <returns>true,空值;false,已经输入值</returns>
  78. public bool IsValueNull()
  79. {
  80. return (_StartDateTime == DateTime.MinValue || _EndDateTime == DateTime.MinValue || _StartDateTime > _EndDateTime);
  81. }
  82. private void Item_ButtonClearClick(object sender, System.ComponentModel.CancelEventArgs e)
  83. {
  84. this.Text = "";
  85. _StartDateTime = DateTime.MinValue;
  86. _EndDateTime = DateTime.MinValue;
  87. }
  88. public void ClearValue()
  89. {
  90. Item_ButtonClearClick(null, null);
  91. }
  92. }
  93. }