FixedStationEditor.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using DevExpress.XtraEditors;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Documents;
  12. using System.Windows.Forms;
  13. using DW5S.Entity;
  14. using DW5S.Repostory;
  15. using Serilog;
  16. using DW5S.Service;
  17. namespace DW5S.App.EditForms
  18. {
  19. public partial class FixedStationEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. public FixedStation info;
  22. private List<FixedStation> infos;
  23. public FixedStationEditor()
  24. {
  25. InitializeComponent();
  26. this.layoutControl1.UseDefault();
  27. this.Text = "固定站添加";
  28. info = new FixedStation();
  29. this.StartPosition = FormStartPosition.CenterParent;
  30. }
  31. public FixedStationEditor(FixedStation info)
  32. : this()
  33. {
  34. this.Text = "固定站编辑";
  35. this.info = info;
  36. }
  37. private async void SatEditor_Load(object sender, EventArgs e)
  38. {
  39. infos = new List<FixedStation>();
  40. var unitOfWork = IocContainer.UnitOfWork;
  41. var repsFixed = unitOfWork.Of<FixedStation>();
  42. var res = await repsFixed.GetAllAsync();
  43. infos.AddRange(res);
  44. var repsSig = unitOfWork.Of<SigInfo>();
  45. var sigs = await repsSig.GetAllAsync();
  46. this.txtFreqUp.UseDefault().SetData(sigs, nameof(SigInfo.FreqUpDis)).UseDoubleClickToSelectAll();
  47. if (this.Text == "固定站编辑" && info != null)
  48. {
  49. this.txtName.Text = info.StationName;
  50. this.txtLon.Text = info.Lon.ToString();
  51. this.txtLat.Text = info.Lat.ToString();
  52. this.txtValue.Text = info.Value.ToString();
  53. this.txtFreqUp.EditValue = sigs.FirstOrDefault(p => p.FreqUp == info.FreqUpHz);
  54. this.txtEnable.Checked = info.Enable;
  55. }
  56. }
  57. private void btnCancel_Click(object sender, EventArgs e)
  58. {
  59. this.DialogResult = DialogResult.Cancel;
  60. }
  61. private void btnOk_Click(object sender, EventArgs e)
  62. {
  63. try
  64. {
  65. var name = txtName.Text.Trim();
  66. if (infos.Any(i => i.Id != info.Id && i.StationName == name))
  67. {
  68. DxHelper.MsgBoxHelper.ShowError($"已经存在名称为[{name}]的固定站!");
  69. return;
  70. }
  71. var freqUpHz = (txtFreqUp.EditValue as SigInfo).FreqUp;
  72. if (infos.Any(i => i.Id != info.Id && i.FreqUpHz == freqUpHz))
  73. {
  74. DxHelper.MsgBoxHelper.ShowError($"已经存在上行频点为[{freqUpHz / 1e6:f3}MHz]的固定站!");
  75. return;
  76. }
  77. if (!double.TryParse(txtLon.Text.Trim(), out double lon))
  78. {
  79. DxHelper.MsgBoxHelper.ShowError($"经度不是有效的数字");
  80. return;
  81. }
  82. if (!double.TryParse(txtLat.Text.Trim(), out double lat))
  83. {
  84. DxHelper.MsgBoxHelper.ShowError($"纬度不是有效的数字");
  85. return;
  86. }
  87. if (!double.TryParse(txtValue.Text.Trim(), out double value))
  88. {
  89. DxHelper.MsgBoxHelper.ShowError($"判定规则不是有效的数字");
  90. return;
  91. }
  92. if (value < 0)
  93. {
  94. DxHelper.MsgBoxHelper.ShowError($"判定规则必须大于0秒");
  95. return;
  96. }
  97. info.StationName = name;
  98. info.Lon = lon;
  99. info.Lat = lat;
  100. info.FreqUpHz = freqUpHz;
  101. info.Value = value;
  102. info.Enable = txtEnable.Checked;
  103. this.DialogResult = DialogResult.OK;
  104. }
  105. catch (Exception ex)
  106. {
  107. string msg = "编辑固定站信息出错";
  108. IocContainer.Logger.Error(ex, msg);
  109. DxHelper.MsgBoxHelper.ShowError(msg);
  110. }
  111. }
  112. }
  113. }