using DevExpress.Xpo.DB.Exceptions; using DevExpress.Xpo; using DevExpress.XtraEditors; using Ips.Library.DxpLib; 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.Forms; namespace Ips.Sps.Tsks { public partial class StartTskForm : DevExpress.XtraEditors.XtraForm { public StartTskForm() { InitializeComponent(); StartTimeDateEdit.UseTimeEdit(); EndTimeDateEdit.UseTimeEdit(); } public StartTskForm(int? id) : this() { this.Id = id; } public int? Id { get; private set; } protected UnitOfWork UnitOfWork { get; private set; } public Tsk EditModel { get => (Tsk)bsTsk.DataSource; } private void StartTskForm_Load(object sender, EventArgs e) { UnitOfWork = new UnitOfWork(); if (Id.HasValue) bsTsk.DataSource = UnitOfWork.GetObjectByKey(Id.Value); else bsTsk.DataSource = new Tsk(UnitOfWork); } private void btnOk_Click(object sender, EventArgs e) { if (StartTimeDateEdit.EditValue == null || StartTimeDateEdit.DateTime == DateTime.MinValue) { MsgHelper.ShowError("请输入开始时间!"); return; } if (EndTimeDateEdit.EditValue == null || EndTimeDateEdit.DateTime == DateTime.MinValue) { MsgHelper.ShowError("请输入结束时间!"); return; } if (StartTimeDateEdit.DateTime > EndTimeDateEdit.DateTime) { MsgHelper.ShowError("开始时间必须小于结束时间!"); return; } try { UnitOfWork.CommitChanges(); this.DialogResult = DialogResult.OK; Close(); } catch (LockingException) { MsgHelper.ShowError("对象已被修改,请关闭后重新打开进行编辑!"); } } private void btnCancel_Click(object sender, EventArgs e) { Close(); } } }