| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 | 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.Ants{    public partial class AntEditForm : DevExpress.XtraEditors.XtraForm    {        public AntEditForm()        {            InitializeComponent();        }        public AntEditForm(int? id) : this()        {            this.Id = id;        }        public int? Id { get; private set; }        protected UnitOfWork UnitOfWork { get; private set; }        public Ant EditModel { get => (Ant)bsAnt.DataSource; }        private void AntEditForm_Load(object sender, EventArgs e)        {            UnitOfWork = new UnitOfWork();            if (Id.HasValue)                bsAnt.DataSource = UnitOfWork.GetObjectByKey<Ant>(Id.Value);            else                bsAnt.DataSource = new Ant(UnitOfWork);        }        private void btnSave_Click(object sender, EventArgs e)        {            try            {                UnitOfWork.CommitChanges();                Id = ((Ant)(bsAnt.DataSource)).Oid;                this.DialogResult = DialogResult.OK;                Close();            }            catch (LockingException)            {                MsgHelper.ShowError("对象已被修改,请关闭后重新打开进行编辑!");            }        }        private void btnCancel_Click(object sender, EventArgs e)        {            Close();        }    }}
 |