SigEditor.cs 5.5 KB

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