PosTimeEditor.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using DevExpress.XtraEditors;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Documents;
  13. using System.Windows.Forms;
  14. using XdCxRhDW.Entity;
  15. using XdCxRhDW.Repostory;
  16. namespace XdCxRhDW.App.EditForms
  17. {
  18. public partial class PosTimeEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. static Dictionary<int, (DateTime, DateTime)> cache = new Dictionary<int, (DateTime, DateTime)>();
  21. public DateTime start;
  22. public DateTime end;
  23. TaskInfo tsk;
  24. public PosTimeEditor()
  25. {
  26. InitializeComponent();
  27. this.layoutControl1.UseDefault();
  28. this.txtStartTime.UseDefault().UseDoubleClickToSelectAll();
  29. this.txtEndTime.UseDefault().UseDoubleClickToSelectAll();
  30. this.StartPosition = FormStartPosition.CenterParent;
  31. }
  32. public PosTimeEditor(TaskInfo tsk)
  33. : this()
  34. {
  35. this.tsk = tsk;
  36. }
  37. private void SatEditor_Load(object sender, EventArgs e)
  38. {
  39. if (cache.ContainsKey(tsk.ID))
  40. {
  41. txtStartTime.DateTime = cache[tsk.ID].Item1;
  42. txtEndTime.DateTime = cache[tsk.ID].Item2;
  43. }
  44. else
  45. {
  46. txtStartTime.DateTime = DateTime.Now;
  47. txtEndTime.DateTime = DateTime.Today.AddDays(7);
  48. }
  49. }
  50. private void btnCancel_Click(object sender, EventArgs e)
  51. {
  52. this.DialogResult = DialogResult.Cancel;
  53. }
  54. private void btnOk_Click(object sender, EventArgs e)
  55. {
  56. if (this.txtStartTime.DateTime == DateTime.MinValue)
  57. {
  58. DxHelper.MsgBoxHelper.ShowWarning("开始时间不能为空!");
  59. return;
  60. }
  61. if (this.txtEndTime.DateTime == DateTime.MinValue)
  62. {
  63. DxHelper.MsgBoxHelper.ShowWarning("结束时间不能为空!");
  64. return;
  65. }
  66. start = DateTime.Parse(txtStartTime.DateTime.ToString("yyyy-MM-dd HH:mm:ss"));//通过转换移除掉毫秒部分
  67. end = DateTime.Parse(txtEndTime.DateTime.ToString("yyyy-MM-dd HH:mm:ss"));//通过转换移除掉毫秒部分
  68. if (start > end)
  69. {
  70. dxErrorProvider1.SetError(txtEndTime, "结束时间不能小于开始时间");
  71. return;
  72. }
  73. if (cache.Count >= 50)
  74. cache.Remove(cache.First().Key);
  75. if (cache.ContainsKey(tsk.ID))
  76. cache[tsk.ID] = (start, end);
  77. else
  78. cache.Add(tsk.ID, (start, end));
  79. this.DialogResult = DialogResult.OK;
  80. }
  81. }
  82. }