using DevExpress.Utils.About; using DevExpress.XtraEditors; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Runtime.Remoting.Metadata.W3cXsd2001; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class SigEditor : DevExpress.XtraEditors.XtraForm { public SigInfo info; private List infos; public SigEditor() { InitializeComponent(); this.layoutControl1.UseDefault(); txtFreqUp.UseDoubleClickToSelectAll(); txtFreqDown.UseDoubleClickToSelectAll(); txtSnr.UseDoubleClickToSelectAll(); this.Text = "添加信号"; info = new SigInfo(); this.StartPosition = FormStartPosition.CenterParent; } public SigEditor(SigInfo info) : this() { this.Text = "编辑信号"; this.info = info; } private async void SatEditor_Load(object sender, EventArgs e) { txtSigType.AddEnum(); if (this.Text == "编辑信号" && info != null) { this.txtFreqUp.EditValue = info.FreqUp / 1e6; this.txtFreqDown.EditValue = info.FreqDown / 1e6; this.txtSnr.EditValue = info.Snr; this.txtBandHz.EditValue = info.Band; var arr = Enum.GetValues(typeof(EnumSigCheckType)); foreach (EnumSigCheckType item in arr) { if (info.SigType.HasFlag(item)) txtSigType.Items[item].CheckState = CheckState.Checked; } } infos = new List(); using (RHDWContext db = new RHDWContext()) { var res = await db.SigInfos.ToListAsync(); infos.AddRange(res); } } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void btnOk_Click(object sender, EventArgs e) { try { dxErrorProvider.ClearErrors(); if (!decimal.TryParse(txtFreqUp.Text, out decimal freqUp)) { dxErrorProvider.SetError(txtFreqUp, "上行频点格式错误"); return; } if (!decimal.TryParse(txtFreqDown.Text, out decimal freqDown)) { dxErrorProvider.SetError(txtFreqDown, "下行频点格式错误"); return; } if (!txtSigType.Items.Any(p => p.CheckState == CheckState.Checked)) { DxHelper.MsgBoxHelper.ShowError("请选择信号类型"); return; } if (!double.TryParse(txtBandHz.Text, out double bandHz)) { dxErrorProvider.SetError(txtBandHz, "带宽格式错误"); return; } if (!double.TryParse(txtSnr.Text, out double snr)) { dxErrorProvider.SetError(txtSnr, "门限格式错误"); return; } long frequp = (long)(freqUp * 1000000); if (infos.Any(i => i.ID != info.ID && i.FreqUp == frequp)) { DxHelper.MsgBoxHelper.ShowError($"上行频点[{freqUp}]已经存在!"); return; } info.FreqUp = frequp; info.FreqDown = (long)(freqDown * 1000000); info.Snr = Convert.ToDouble(txtSnr.EditValue); info.Band = bandHz; var res = txtSigType.Items.Where(p => p.CheckState == CheckState.Checked).Select(t => (EnumSigCheckType)t.Value).ToList(); EnumSigCheckType sigType = res.First(); for (int i = 1; i < res.Count; i++) { sigType |= res[i]; } info.SigType = sigType; this.DialogResult = DialogResult.OK; } catch (Exception ex) { XdCxRhDW.Framework.LogHelper.Error("编辑信号信息出错", ex); DxHelper.MsgBoxHelper.ShowError("编辑信号信息出错"); } } private void txtSigType_SelectedIndexChanged(object sender, EventArgs e) { var idx = txtSigType.SelectedIndex; txtSigType.Items[idx].InvertCheckState(); } private void txtSigType_ItemCheck_1(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) { if (e.State == CheckState.Checked) { if (e.Index < 3) { txtSigType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Unchecked; } else { txtSigType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked; txtSigType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked; txtSigType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked; } } } } }