SigEditor.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. var arr = Enum.GetValues(typeof(EnumSigCheckType));
  50. foreach (EnumSigCheckType item in arr)
  51. {
  52. if (info.SigType.HasFlag(item))
  53. txtSigType.Items[item].CheckState = CheckState.Checked;
  54. }
  55. }
  56. infos = new List<SigInfo>();
  57. using (RHDWContext db = new RHDWContext())
  58. {
  59. var res = await db.SigInfos.ToListAsync();
  60. infos.AddRange(res);
  61. }
  62. }
  63. private void btnCancel_Click(object sender, EventArgs e)
  64. {
  65. this.DialogResult = DialogResult.Cancel;
  66. }
  67. private void btnOk_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. dxErrorProvider.ClearErrors();
  72. if (!decimal.TryParse(txtFreqUp.Text, out decimal freqUp))
  73. {
  74. dxErrorProvider.SetError(txtFreqUp, "上行频点格式错误");
  75. return;
  76. }
  77. if (!decimal.TryParse(txtFreqDown.Text, out decimal freqDown))
  78. {
  79. dxErrorProvider.SetError(txtFreqDown, "下行频点格式错误");
  80. return;
  81. }
  82. if (!txtSigType.Items.Any(p => p.CheckState == CheckState.Checked))
  83. {
  84. DxHelper.MsgBoxHelper.ShowError("请选择信号类型");
  85. return;
  86. }
  87. if (!double.TryParse(txtSnr.Text, out double snr))
  88. {
  89. dxErrorProvider.SetError(txtSnr, "门限格式错误");
  90. return;
  91. }
  92. long frequp = (long)(freqUp * 1000000);
  93. if (infos.Any(i => i.ID != info.ID && i.FreqUp == frequp))
  94. {
  95. DxHelper.MsgBoxHelper.ShowError($"上行频点[{freqUp}]已经存在!");
  96. return;
  97. }
  98. info.FreqUp = frequp;
  99. info.FreqDown = (long)(freqDown * 1000000);
  100. info.Snr = Convert.ToDouble(txtSnr.EditValue);
  101. var res = txtSigType.Items.Where(p => p.CheckState == CheckState.Checked).Select(t => (EnumSigCheckType)t.Value).ToList();
  102. EnumSigCheckType sigType = res.First();
  103. for (int i = 1; i < res.Count; i++)
  104. {
  105. sigType |= res[i];
  106. }
  107. info.SigType = sigType;
  108. this.DialogResult = DialogResult.OK;
  109. }
  110. catch (Exception ex)
  111. {
  112. Serilog.Log.Error(ex, "编辑信号信息出错");
  113. DxHelper.MsgBoxHelper.ShowError("编辑信号信息出错");
  114. }
  115. }
  116. private void txtSigType_SelectedIndexChanged(object sender, EventArgs e)
  117. {
  118. var idx = txtSigType.SelectedIndex;
  119. txtSigType.Items[idx].InvertCheckState();
  120. }
  121. private void txtSigType_ItemCheck_1(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
  122. {
  123. if (e.State == CheckState.Checked)
  124. {
  125. if (e.Index < 3)
  126. {
  127. txtSigType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Unchecked;
  128. }
  129. else
  130. {
  131. txtSigType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked;
  132. txtSigType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked;
  133. txtSigType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked;
  134. }
  135. }
  136. }
  137. }
  138. }