FixedStationEditor.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 repsFixed = unitOfWork.Of<FixedStation>();
  41. var res = await repsFixed.GetAllAsync();
  42. infos.AddRange(res);
  43. var repsSig = unitOfWork.Of<SigInfo>();
  44. var sigs = await repsSig.GetAllAsync();
  45. this.txtFreqUp.UseDefault().SetData(sigs, nameof(SigInfo.FreqUpDis)).UseDoubleClickToSelectAll();
  46. if (this.Text == "固定站编辑" && info != null)
  47. {
  48. this.txtName.Text = info.StationName;
  49. this.txtLon.Text = info.Lon.ToString();
  50. this.txtLat.Text = info.Lat.ToString();
  51. this.txtValue.Text = info.Value.ToString();
  52. this.txtFreqUp.EditValue = sigs.FirstOrDefault(p => p.FreqUp == info.FreqUpHz);
  53. this.txtEnable.Checked = info.Enable;
  54. }
  55. }
  56. private void btnCancel_Click(object sender, EventArgs e)
  57. {
  58. this.DialogResult = DialogResult.Cancel;
  59. }
  60. private void btnOk_Click(object sender, EventArgs e)
  61. {
  62. try
  63. {
  64. var name = txtName.Text.Trim();
  65. if (infos.Any(i => i.Id != info.Id && i.StationName == name))
  66. {
  67. DxHelper.MsgBoxHelper.ShowError($"已经存在名称为[{name}]的固定站!");
  68. return;
  69. }
  70. var freqUpHz = (txtFreqUp.EditValue as SigInfo).FreqUp;
  71. if (infos.Any(i => i.Id != info.Id && i.FreqUpHz == freqUpHz))
  72. {
  73. DxHelper.MsgBoxHelper.ShowError($"已经存在上行频点为[{freqUpHz / 1e6:f3}MHz]的固定站!");
  74. return;
  75. }
  76. if (!double.TryParse(txtLon.Text.Trim(), out double lon))
  77. {
  78. DxHelper.MsgBoxHelper.ShowError($"经度不是有效的数字");
  79. return;
  80. }
  81. if (!double.TryParse(txtLat.Text.Trim(), out double lat))
  82. {
  83. DxHelper.MsgBoxHelper.ShowError($"纬度不是有效的数字");
  84. return;
  85. }
  86. if (!double.TryParse(txtValue.Text.Trim(), out double value))
  87. {
  88. DxHelper.MsgBoxHelper.ShowError($"判定规则不是有效的数字");
  89. return;
  90. }
  91. if (value < 0)
  92. {
  93. DxHelper.MsgBoxHelper.ShowError($"判定规则必须大于0秒");
  94. return;
  95. }
  96. info.StationName = name;
  97. info.Lon = lon;
  98. info.Lat = lat;
  99. info.FreqUpHz = freqUpHz;
  100. info.Value = value;
  101. info.Enable = txtEnable.Checked;
  102. this.DialogResult = DialogResult.OK;
  103. }
  104. catch (Exception ex)
  105. {
  106. string msg = "编辑固定站信息出错";
  107. IocContainer.Logger.Error(ex, msg);
  108. DxHelper.MsgBoxHelper.ShowError(msg);
  109. }
  110. }
  111. }
  112. }