FixedStationEditor.cs 4.3 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.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Documents;
  14. using System.Windows.Forms;
  15. using XdCxRhDW.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.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. List<SigInfo> sigs;
  41. using (RHDWContext db = new RHDWContext())
  42. {
  43. var res = await db.FixedStation.ToListAsync();
  44. infos.AddRange(res);
  45. sigs = await db.SigInfos.ToListAsync();
  46. if (sigs == null)
  47. sigs = new List<SigInfo>();
  48. this.txtFreqUp.UseDefault().SetData(sigs, nameof(SigInfo.FreqUpDis)).UseDoubleClickToSelectAll();
  49. }
  50. if (this.Text == "固定站编辑" && info != null)
  51. {
  52. this.txtName.Text = info.StationName;
  53. this.txtLon.Text = info.Lon.ToString();
  54. this.txtLat.Text = info.Lat.ToString();
  55. this.txtValue.Text = info.Value.ToString();
  56. this.txtFreqUp.EditValue = sigs.FirstOrDefault(p => p.FreqUp == info.FreqUpHz);
  57. this.txtEnable.Checked = info.Enable;
  58. }
  59. }
  60. private void btnCancel_Click(object sender, EventArgs e)
  61. {
  62. this.DialogResult = DialogResult.Cancel;
  63. }
  64. private void btnOk_Click(object sender, EventArgs e)
  65. {
  66. try
  67. {
  68. var name = txtName.Text.Trim();
  69. if (infos.Any(i => i.ID != info.ID && i.StationName == name))
  70. {
  71. DxHelper.MsgBoxHelper.ShowError($"已经存在名称为[{name}]的固定站!");
  72. return;
  73. }
  74. var freqUpHz = (txtFreqUp.EditValue as SigInfo).FreqUp;
  75. if (infos.Any(i => i.ID != info.ID && i.FreqUpHz == freqUpHz))
  76. {
  77. DxHelper.MsgBoxHelper.ShowError($"已经存在上行频点为[{freqUpHz / 1e6:f3}MHz]的固定站!");
  78. return;
  79. }
  80. if (!double.TryParse(txtLon.Text.Trim(), out double lon))
  81. {
  82. DxHelper.MsgBoxHelper.ShowError($"经度不是有效的数字");
  83. return;
  84. }
  85. if (!double.TryParse(txtLat.Text.Trim(), out double lat))
  86. {
  87. DxHelper.MsgBoxHelper.ShowError($"纬度不是有效的数字");
  88. return;
  89. }
  90. if (!double.TryParse(txtValue.Text.Trim(), out double value))
  91. {
  92. DxHelper.MsgBoxHelper.ShowError($"判定规则不是有效的数字");
  93. return;
  94. }
  95. if (value < 0)
  96. {
  97. DxHelper.MsgBoxHelper.ShowError($"判定规则必须大于0秒");
  98. return;
  99. }
  100. info.StationName = name;
  101. info.Lon = lon;
  102. info.Lat = lat;
  103. info.FreqUpHz = freqUpHz;
  104. info.Value = value;
  105. info.Enable = txtEnable.Checked;
  106. this.DialogResult = DialogResult.OK;
  107. }
  108. catch (Exception ex)
  109. {
  110. XdCxRhDW.Framework.LogHelper.Error("编辑固定站信息出错", ex);
  111. DxHelper.MsgBoxHelper.ShowError("编辑固定站信息出错");
  112. }
  113. }
  114. }
  115. }