SigEditor.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using DevExpress.XtraEditors;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Documents;
  14. using System.Windows.Forms;
  15. using XdCxRhDW.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class SigEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. public SigInfo info;
  22. public SigEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加信号";
  27. info = new SigInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public SigEditor(SigInfo info)
  31. : this()
  32. {
  33. this.Text = "编辑信号";
  34. this.info = info;
  35. }
  36. private void SatEditor_Load(object sender, EventArgs e)
  37. {
  38. txtSigType.AddEnum<EnumSigCheckType>();
  39. if (this.Text == "编辑信号" && info != null)
  40. {
  41. this.txtFreqUp.EditValue = info.FreqUp;
  42. this.txtFreqDown.EditValue = info.FreqDown;
  43. this.txtSnr.EditValue = info.Snr;
  44. //List<EnumSigCheckType> deWay = new List<EnumSigCheckType>();
  45. //if (info.SigType.HasFlag(EnumSigCheckType.DAMA))
  46. //{
  47. // deWay.Add(EnumSigCheckType.DAMA);
  48. //}
  49. //if (info.SigType.HasFlag(EnumSigCheckType.IBS))
  50. //{
  51. // deWay.Add(EnumSigCheckType.IBS);
  52. //}
  53. //if (info.SigType.HasFlag(EnumSigCheckType.Ky5758))
  54. //{
  55. // deWay.Add(EnumSigCheckType.Ky5758);
  56. //}
  57. //this.txtSigType.EditValue = string.Join(",", deWay);
  58. //this.txtSigType.EditValue = info.SigType.ToString();
  59. }
  60. }
  61. private void btnCancel_Click(object sender, EventArgs e)
  62. {
  63. this.DialogResult = DialogResult.Cancel;
  64. }
  65. private void btnOk_Click(object sender, EventArgs e)
  66. {
  67. try
  68. {
  69. dxErrorProvider.ClearErrors();
  70. if (txtFreqUp.EditValue == null)
  71. {
  72. dxErrorProvider.SetError(txtFreqUp, "请输入上行频点");
  73. return;
  74. }
  75. if (txtFreqDown.EditValue == null)
  76. {
  77. dxErrorProvider.SetError(txtFreqDown, "请输入下行频点");
  78. return;
  79. }
  80. if (!txtSigType.Items.Any(p => p.CheckState == CheckState.Checked))
  81. {
  82. dxErrorProvider.SetError(txtSigType, "请选择信号类型");
  83. return;
  84. }
  85. if (txtSnr.EditValue == null)
  86. {
  87. dxErrorProvider.SetError(txtSnr, "请输入门限");
  88. return;
  89. }
  90. info.FreqUp = Convert.ToDouble(txtFreqUp.EditValue);
  91. info.FreqDown = Convert.ToDouble(txtFreqDown.EditValue);
  92. info.Snr = Convert.ToDouble(txtSnr.EditValue);
  93. var res = txtSigType.Items.Where(p => p.CheckState == CheckState.Checked).Select(t => (EnumSigCheckType)t.Value).ToList();
  94. EnumSigCheckType sigType = res.First();
  95. for (int i = 1; i < res.Count; i++)
  96. {
  97. sigType |= res[i];
  98. }
  99. info.SigType = sigType;
  100. this.DialogResult = DialogResult.OK;
  101. }
  102. catch (Exception ex)
  103. {
  104. Serilog.Log.Error(ex, "编辑信号信息出错");
  105. DxHelper.MsgBoxHelper.ShowError("编辑信号信息出错");
  106. }
  107. }
  108. private void txtSigType_SelectedIndexChanged(object sender, EventArgs e)
  109. {
  110. var idx = txtSigType.SelectedIndex;
  111. txtSigType.Items[idx].InvertCheckState();
  112. }
  113. private void txtSigType_ItemCheck_1(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
  114. {
  115. if (e.State == CheckState.Checked)
  116. {
  117. if (e.Index < 3)
  118. {
  119. txtSigType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Unchecked;
  120. }
  121. else
  122. {
  123. txtSigType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked;
  124. txtSigType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked;
  125. txtSigType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked;
  126. }
  127. }
  128. }
  129. }
  130. }