CdbEditor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using DevExpress.Utils.About;
  2. using DW5S.Entity;
  3. using DW5S.Repostory;
  4. using DW5S.Service;
  5. using ExtensionsDev;
  6. using Serilog;
  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. namespace DW5S.App.EditForms
  17. {
  18. public partial class CdbEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public CdbTxViewModel info;
  21. private List<CdbTxViewModel> infos;
  22. public CdbEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加超短波";
  27. info = new CdbTxViewModel();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public CdbEditor(CdbTxViewModel info)
  31. : this()
  32. {
  33. this.Text = "编辑超短波";
  34. this.info = info;
  35. }
  36. private async void CdbEditor_Load(object sender, EventArgs e)
  37. {
  38. if (this.Text == "编辑超短波" && info != null)
  39. {
  40. this.txtCdbTxName.Text = info.Name;
  41. this.txtLon.Text = info.Lon.ToString();
  42. this.txtLat.Text = info.Lat.ToString();
  43. this.txtRemark.EditValue = info.Remark;
  44. this.checkEdit.EditValue = info.Enable;
  45. }
  46. infos = new List<CdbTxViewModel>();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsCdb = unitOfWork.Of<TxInfo>();
  49. var res = await repsCdb.FindAsync(f => f.TxType == EnumTxType.Cdb);
  50. infos.AddRange(res.To<List<CdbTxViewModel>>());
  51. }
  52. private void btnOk_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. if (infos.Any(i => i.Id != info.Id && i.Name == txtCdbTxName.Text))
  57. {
  58. DxHelper.MsgBoxHelper.ShowError($"超短波[{txtCdbTxName.Text}]已经存在!");
  59. return;
  60. }
  61. info.Name= txtCdbTxName.Text;
  62. info.Lon=Convert.ToDouble(txtLon.Text);
  63. info.Lat = Convert.ToDouble(txtLat.Text);
  64. info.Remark = txtRemark.Text;
  65. info.Enable = (bool)checkEdit.EditValue;
  66. this.DialogResult = DialogResult.OK;
  67. }
  68. catch (Exception ex)
  69. {
  70. string msg = "编辑超短波信息出错";
  71. IocContainer.Logger.Error(ex, msg);
  72. DxHelper.MsgBoxHelper.ShowError(msg);
  73. }
  74. }
  75. private void btnCancle_Click(object sender, EventArgs e)
  76. {
  77. this.DialogResult = DialogResult.Cancel;
  78. }
  79. }
  80. }