12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.DXErrorProvider;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using DW5S.Entity;
- using DW5S.Repostory;
- namespace DW5S.App.EditForms
- {
- public partial class TaskHistoryTimeEditor : DevExpress.XtraEditors.XtraForm
- {
- static Dictionary<int, (DateTime, DateTime)> cache = new Dictionary<int, (DateTime, DateTime)>();
- public DateTime start;
- public DateTime end;
- TaskInfo tsk;
- public TaskHistoryTimeEditor()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.txtStartTime.UseDefault().UseDoubleClickToSelectAll();
- this.txtEndTime.UseDefault().UseDoubleClickToSelectAll();
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public TaskHistoryTimeEditor(TaskInfo tsk)
- : this()
- {
- this.tsk = tsk;
- }
- private void SatEditor_Load(object sender, EventArgs e)
- {
- if (cache.ContainsKey(tsk.ID))
- {
- txtStartTime.DateTime = cache[tsk.ID].Item1;
- txtEndTime.DateTime = cache[tsk.ID].Item2;
- }
- else
- {
- txtStartTime.DateTime = DateTime.Now;
- txtEndTime.DateTime = DateTime.Today.AddDays(7);
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- dxErrorProvider1.ClearErrors();
- start = DateTime.Parse(txtStartTime.DateTime.ToString("yyyy-MM-dd HH:mm:ss"));//通过转换移除掉毫秒部分
- end = DateTime.Parse(txtEndTime.DateTime.ToString("yyyy-MM-dd HH:mm:ss"));//通过转换移除掉毫秒部分
- if (start > end)
- {
- dxErrorProvider1.SetError(txtEndTime, "结束时间不能小于开始时间");
- return;
- }
- if (cache.Count >= 50)
- cache.Remove(cache.First().Key);
- if (cache.ContainsKey(tsk.ID))
- cache[tsk.ID] = (start, end);
- else
- cache.Add(tsk.ID, (start, end));
- this.DialogResult = DialogResult.OK;
- }
- }
- }
|