using DW5S.Entity; using DW5S.Repostory; using DW5S.ViewModel; using ExtensionsDev; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; namespace DW5S.App.EditForms { public partial class SigEditor : DevExpress.XtraEditors.XtraForm { public SigViewModel info; private List infos; public SigEditor() { InitializeComponent(); this.layoutControl1.UseDefault(); txtFreqUp.UseDoubleClickToSelectAll(); txtFreqDown.UseDoubleClickToSelectAll(); txtSnr.UseDoubleClickToSelectAll(); this.Text = "添加信号"; info = new SigViewModel(); this.StartPosition = FormStartPosition.CenterParent; } public SigEditor(SigViewModel info) : this() { this.Text = "编辑信号"; this.info = info; } private async void SatEditor_Load(object sender, EventArgs e) { txtSigCheckType.AddEnum(); cbSigType.Properties.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.SigCheckType.HasFlag(item)) txtSigCheckType.Items[item].CheckState = CheckState.Checked; } this.cbSigType.EditValue = info.SigType; } infos = new List(); var unitOfWork = IocContainer.UnitOfWork; var repsSig = unitOfWork.Of(); var res = await repsSig.GetAllAsync(); infos.AddRange(res.To>()); } 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 (!txtSigCheckType.Items.Any(p => p.CheckState == CheckState.Checked)) { DxHelper.MsgBoxHelper.ShowError("请选择信号检测类型"); return; } if (cbSigType.EditValue == null) { dxErrorProvider.SetError(cbSigType, $"请选择信号类型!"); 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 = txtSigCheckType.Items.Where(p => p.CheckState == CheckState.Checked).Select(t => (EnumSigCheckType)t.Value).ToList(); EnumSigCheckType sigCheckType = res.First(); for (int i = 1; i < res.Count; i++) { sigCheckType |= res[i]; } info.SigCheckType = sigCheckType; info.SigType = (EnumSigType)cbSigType.EditValue; info.UpdateTime = DateTime.Now; this.DialogResult = DialogResult.OK; } catch (Exception ex) { IocContainer.Logger.Error(ex,"编辑信号信息出错"); DxHelper.MsgBoxHelper.ShowError("编辑信号信息出错"); } } private void txtSigType_SelectedIndexChanged(object sender, EventArgs e) { var idx = txtSigCheckType.SelectedIndex; txtSigCheckType.Items[idx].InvertCheckState(); } private void txtSigType_ItemCheck_1(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) { if (e.State == CheckState.Checked) { if (cbSigType.EditValue != null) { var sigType = (EnumSigType)cbSigType.EditValue; if (sigType == EnumSigType.Ref) { txtSigCheckType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Checked; return; } } if (e.Index < 3) { txtSigCheckType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Unchecked; } else { txtSigCheckType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked; } } } private void cbSigType_SelectedIndexChanged(object sender, EventArgs e) { var sigType = (EnumSigType)cbSigType.EditValue; if (sigType == EnumSigType.Ref) { txtSigCheckType.Items[EnumSigCheckType.Normal].CheckState = CheckState.Checked; txtSigCheckType.Items[EnumSigCheckType.DAMA].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.IBS].CheckState = CheckState.Unchecked; txtSigCheckType.Items[EnumSigCheckType.Ky5758].CheckState = CheckState.Unchecked; } } } }