PosEditForm.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.TskResults.Poses
  15. {
  16. public partial class PosEditForm : DevExpress.XtraEditors.XtraForm
  17. {
  18. public PosEditForm()
  19. {
  20. InitializeComponent();
  21. }
  22. public PosEditForm(long? id) : this()
  23. {
  24. this.Id = id;
  25. }
  26. public long? Id { get; private set; }
  27. protected UnitOfWork UnitOfWork { get; private set; }
  28. public Pos EditModel { get => (Pos)bsPos.DataSource; }
  29. private void PosEditForm_Load(object sender, EventArgs e)
  30. {
  31. UnitOfWork = new UnitOfWork();
  32. if (Id.HasValue)
  33. bsPos.DataSource = UnitOfWork.GetObjectByKey<Pos>(Id.Value);
  34. else
  35. bsPos.DataSource = new Pos(UnitOfWork);
  36. }
  37. private void btnSave_Click(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. UnitOfWork.CommitChanges();
  42. var pos = (Pos)(bsPos.DataSource);
  43. Id = pos.Id;
  44. this.DialogResult = DialogResult.OK;
  45. Close();
  46. }
  47. catch (LockingException)
  48. {
  49. MsgHelper.ShowError("对象已被修改,请关闭后重新打开进行编辑!");
  50. }
  51. }
  52. private void btnCancel_Click(object sender, EventArgs e)
  53. {
  54. Close();
  55. }
  56. }
  57. }