AntEditForm.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using DevExpress.Xpo.DB.Exceptions;
  2. using DevExpress.Xpo;
  3. using DevExpress.XtraEditors;
  4. using Ips.Library.DxpLib;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace Ips.Sps.Ants
  15. {
  16. public partial class AntEditForm : DevExpress.XtraEditors.XtraForm
  17. {
  18. public AntEditForm()
  19. {
  20. InitializeComponent();
  21. }
  22. public AntEditForm(int? id) : this()
  23. {
  24. this.Id = id;
  25. }
  26. public int? Id { get; private set; }
  27. protected UnitOfWork UnitOfWork { get; private set; }
  28. public Ant EditModel { get => (Ant)bsAnt.DataSource; }
  29. private void AntEditForm_Load(object sender, EventArgs e)
  30. {
  31. UnitOfWork = new UnitOfWork();
  32. if (Id.HasValue)
  33. bsAnt.DataSource = UnitOfWork.GetObjectByKey<Ant>(Id.Value);
  34. else
  35. bsAnt.DataSource = new Ant(UnitOfWork);
  36. }
  37. private void btnSave_Click(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. UnitOfWork.CommitChanges();
  42. Id = ((Ant)(bsAnt.DataSource)).Oid;
  43. this.DialogResult = DialogResult.OK;
  44. Close();
  45. }
  46. catch (LockingException)
  47. {
  48. MsgHelper.ShowError("对象已被修改,请关闭后重新打开进行编辑!");
  49. }
  50. }
  51. private void btnCancel_Click(object sender, EventArgs e)
  52. {
  53. Close();
  54. }
  55. }
  56. }