SigEditor.cs 7.0 KB

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