EmtEditForm.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using DevExpress.LookAndFeel;
  2. using DevExpress.Xpo.DB.Exceptions;
  3. using DevExpress.Xpo;
  4. using DevExpress.XtraEditors;
  5. using Ips.Library.Basic;
  6. using Ips.Library.DxpLib;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using DevExpress.XtraLayout.Utils;
  17. using Ips.Library.Entity;
  18. namespace Ips.Sps.Emts
  19. {
  20. public partial class EmtEditForm : DevExpress.XtraEditors.XtraForm
  21. {
  22. public EmtEditForm()
  23. {
  24. InitializeComponent();
  25. EmtTypeImageComboBoxEdit.Properties.Items.AddEnum<EmtType>();
  26. }
  27. public EmtEditForm(int? id) : this()
  28. {
  29. this.Id = id;
  30. }
  31. public int? Id { get; private set; }
  32. protected UnitOfWork UnitOfWork { get; private set; }
  33. public Emt EditModel { get => (Emt)bsEmt.DataSource; }
  34. private void EmtEditForm_Load(object sender, EventArgs e)
  35. {
  36. UnitOfWork = new UnitOfWork();
  37. if (Id.HasValue)
  38. bsEmt.DataSource = UnitOfWork.GetObjectByKey<Emt>(Id.Value);
  39. else
  40. bsEmt.DataSource = new Emt(UnitOfWork);
  41. }
  42. private void btnSave_Click(object sender, EventArgs e)
  43. {
  44. try
  45. {
  46. UnitOfWork.CommitChanges();
  47. Id = ((Emt)(bsEmt.DataSource)).Oid;
  48. this.DialogResult = DialogResult.OK;
  49. Close();
  50. }
  51. catch (LockingException)
  52. {
  53. MsgHelper.ShowError("对象已被修改,请关闭后重新打开进行编辑!");
  54. }
  55. }
  56. private void btnCancel_Click(object sender, EventArgs e)
  57. {
  58. Close();
  59. }
  60. private void SampleFileButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  61. {
  62. string sampleFile = ToolDialog.OpenFile("", "选择信号样本");
  63. if (sampleFile.IsNullOrWhitespace()) return;
  64. gvEmtSampleList.SetFocusedRowCellValue(colSampleFile, sampleFile);
  65. }
  66. private void lcgSamples_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
  67. {
  68. string caption = e.Button.Properties.Caption;
  69. switch (caption)
  70. {
  71. case "添加":
  72. gvEmtSampleList.AddNewRow();
  73. break;
  74. case "删除":
  75. gvEmtSampleList.DeleteSelectedRows();
  76. break;
  77. }
  78. }
  79. private void HasSampleCheckEdit_CheckedChanged(object sender, EventArgs e)
  80. {
  81. lcgSamples.Visibility = HasSampleCheckEdit.Checked ? LayoutVisibility.Always : LayoutVisibility.Never;
  82. }
  83. private void EmtTypeImageComboBoxEdit_SelectedIndexChanged(object sender, EventArgs e)
  84. {
  85. var emtType = (EmtType)EmtTypeImageComboBoxEdit.EditValue;
  86. ItemForLon.Visibility = ItemForLat.Visibility = emtType == EmtType.FixSation ? LayoutVisibility.Always : LayoutVisibility.Never;
  87. }
  88. }
  89. }