FixedStationEditor.cs 4.4 KB

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