PosTimeEditor.cs 2.9 KB

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