TaskHistoryTimeEditor.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 TaskHistoryTimeEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. Dictionary<int, (DateTime, DateTime)> cache = new Dictionary<int, (DateTime, DateTime)>();
  21. public DateTime start;
  22. public DateTime end;
  23. TaskInfo tsk;
  24. public TaskHistoryTimeEditor()
  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 TaskHistoryTimeEditor(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. start = txtStartTime.DateTime;
  57. end = txtEndTime.DateTime;
  58. if (cache.Count >= 50)
  59. cache.Remove(cache.First().Key);
  60. cache.Add(tsk.ID, (start, end));
  61. this.DialogResult = DialogResult.OK;
  62. }
  63. }
  64. }