SigEditor.cs 7.1 KB

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