CdbEditor.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 CdbTxInfo info;
  21. private List<CdbTxInfo> infos;
  22. public CdbEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加超短波";
  27. info = new CdbTxInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public CdbEditor(CdbTxInfo 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.txtAlt.Text = info.Alt.ToString();
  44. this.txtRemark.EditValue = info.Remark;
  45. }
  46. infos = new List<CdbTxInfo>();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsCdb = unitOfWork.Of<CdbTxInfo>();
  49. var res = await repsCdb.GetAllAsync(p => p.Name);
  50. infos.AddRange(res);
  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. //if (!string.IsNullOrWhiteSpace(txtAlt.Text))
  65. info.Alt = Convert.ToDouble(txtAlt.Text);
  66. info.Remark = txtRemark.Text;
  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. }