CdbEditor.cs 2.8 KB

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