SigEditor.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using DevExpress.Utils.About;
  2. using DevExpress.XtraEditors;
  3. using ExtensionsDev;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Documents;
  13. using System.Windows.Forms;
  14. using DW5S.Entity;
  15. using DW5S.Repostory;
  16. using Microsoft.Extensions.Logging;
  17. namespace DW5S.App.EditForms
  18. {
  19. public partial class SigEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. [Autowired]
  22. private readonly ILogger logger;
  23. [Autowired]
  24. private readonly UnitOfWork unitOfWork;
  25. public SigInfo info;
  26. private List<SigInfo> infos;
  27. public SigEditor()
  28. {
  29. InitializeComponent();
  30. this.layoutControl1.UseDefault();
  31. txtFreqUp.UseDoubleClickToSelectAll();
  32. txtFreqDown.UseDoubleClickToSelectAll();
  33. txtSnr.UseDoubleClickToSelectAll();
  34. this.Text = "添加信号";
  35. info = new SigInfo();
  36. this.StartPosition = FormStartPosition.CenterParent;
  37. }
  38. public SigEditor(SigInfo info)
  39. : this()
  40. {
  41. this.Text = "编辑信号";
  42. this.info = info;
  43. }
  44. private async void SatEditor_Load(object sender, EventArgs e)
  45. {
  46. txtSigType.AddEnum<EnumSigCheckType>();
  47. if (this.Text == "编辑信号" && info != null)
  48. {
  49. this.txtFreqUp.EditValue = info.FreqUp / 1e6;
  50. this.txtFreqDown.EditValue = info.FreqDown / 1e6;
  51. this.txtSnr.EditValue = info.Snr;
  52. this.txtBandHz.EditValue = info.Band;
  53. var arr = Enum.GetValues(typeof(EnumSigCheckType));
  54. foreach (EnumSigCheckType item in arr)
  55. {
  56. if (info.SigType.HasFlag(item))
  57. txtSigType.Items[item].CheckState = CheckState.Checked;
  58. }
  59. }
  60. infos = new List<SigInfo>();
  61. var repsSig = unitOfWork.Of<SigInfo>();
  62. var res = await repsSig.GetAllAsync();
  63. infos.AddRange(res);
  64. }
  65. private void btnCancel_Click(object sender, EventArgs e)
  66. {
  67. this.DialogResult = DialogResult.Cancel;
  68. }
  69. private void btnOk_Click(object sender, EventArgs e)
  70. {
  71. try
  72. {
  73. dxErrorProvider.ClearErrors();
  74. if (!decimal.TryParse(txtFreqUp.Text, out decimal freqUp))
  75. {
  76. dxErrorProvider.SetError(txtFreqUp, "上行频点格式错误");
  77. return;
  78. }
  79. if (!decimal.TryParse(txtFreqDown.Text, out decimal freqDown))
  80. {
  81. dxErrorProvider.SetError(txtFreqDown, "下行频点格式错误");
  82. return;
  83. }
  84. if (!txtSigType.Items.Any(p => p.CheckState == CheckState.Checked))
  85. {
  86. DxHelper.MsgBoxHelper.ShowError("请选择信号类型");
  87. return;
  88. }
  89. if (!double.TryParse(txtBandHz.Text, out double bandHz))
  90. {
  91. dxErrorProvider.SetError(txtBandHz, "带宽格式错误");
  92. return;
  93. }
  94. if (!double.TryParse(txtSnr.Text, out double snr))
  95. {
  96. dxErrorProvider.SetError(txtSnr, "门限格式错误");
  97. return;
  98. }
  99. long frequp = (long)(freqUp * 1000000);
  100. if (infos.Any(i => i.Id != info.Id && i.FreqUp == frequp))
  101. {
  102. DxHelper.MsgBoxHelper.ShowError($"上行频点[{freqUp}]已经存在!");
  103. return;
  104. }
  105. info.FreqUp = frequp;
  106. info.FreqDown = (long)(freqDown * 1000000);
  107. info.Snr = Convert.ToDouble(txtSnr.EditValue);
  108. info.Band = bandHz;
  109. var res = txtSigType.Items.Where(p => p.CheckState == CheckState.Checked).Select(t => (EnumSigCheckType)t.Value).ToList();
  110. EnumSigCheckType sigType = res.First();
  111. for (int i = 1; i < res.Count; i++)
  112. {
  113. sigType |= res[i];
  114. }
  115. info.SigType = sigType;
  116. this.DialogResult = DialogResult.OK;
  117. }
  118. catch (Exception ex)
  119. {
  120. string msg = "编辑信号信息出错";
  121. logger.LogError(ex, msg);
  122. DxHelper.MsgBoxHelper.ShowError(msg);
  123. }
  124. }
  125. private void txtSigType_SelectedIndexChanged(object sender, EventArgs e)
  126. {
  127. var idx = txtSigType.SelectedIndex;
  128. txtSigType.Items[idx].InvertCheckState();
  129. }
  130. private void txtSigType_ItemCheck_1(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
  131. {
  132. if (e.State == CheckState.Checked)
  133. {
  134. if (e.Index < 3)
  135. {
  136. txtSigType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Unchecked;
  137. }
  138. else
  139. {
  140. txtSigType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked;
  141. txtSigType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked;
  142. txtSigType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked;
  143. }
  144. }
  145. }
  146. }
  147. }