CdbEditor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. }
  45. infos = new List<CdbTxViewModel>();
  46. var unitOfWork = IocContainer.UnitOfWork;
  47. var repsCdb = unitOfWork.Of<TxInfo>();
  48. var res = await repsCdb.FindAsync(f => f.TxType == EnumTxType.Cdb);
  49. infos.AddRange(res.To<List<CdbTxViewModel>>());
  50. }
  51. private void btnOk_Click(object sender, EventArgs e)
  52. {
  53. try
  54. {
  55. if (infos.Any(i => i.Id != info.Id && i.Name == txtCdbTxName.Text))
  56. {
  57. DxHelper.MsgBoxHelper.ShowError($"超短波[{txtCdbTxName.Text}]已经存在!");
  58. return;
  59. }
  60. info.Name= txtCdbTxName.Text;
  61. info.Lon=Convert.ToDouble(txtLon.Text);
  62. info.Lat = Convert.ToDouble(txtLat.Text);
  63. info.Remark = txtRemark.Text;
  64. this.DialogResult = DialogResult.OK;
  65. }
  66. catch (Exception ex)
  67. {
  68. string msg = "编辑超短波信息出错";
  69. IocContainer.Logger.Error(ex, msg);
  70. DxHelper.MsgBoxHelper.ShowError(msg);
  71. }
  72. }
  73. private void btnCancle_Click(object sender, EventArgs e)
  74. {
  75. this.DialogResult = DialogResult.Cancel;
  76. }
  77. }
  78. }