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