using DevExpress.Utils.About; using DW5S.Entity; using DW5S.Repostory; using DW5S.Service; using DW5S.ViewModel; using ExtensionsDev; using Serilog; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using XdCxRhDW5S.ViewModel; namespace DW5S.App.EditForms { public partial class AdChannelEditor : DevExpress.XtraEditors.XtraForm { public AdChannelViewModel info; private List infos; public AdChannelEditor() { InitializeComponent(); this.layoutControl1.UseDefault(); this.Text = "添加采集通道"; info = new AdChannelViewModel(); infos = new List(); this.StartPosition = FormStartPosition.CenterParent; } public AdChannelEditor(AdChannelViewModel info, List infos) : this() { this.Text = "编辑采集通道"; this.info = info; this.infos = infos; } private async void CxEditor_Load(object sender, EventArgs e) { var unitOfWork = IocContainer.UnitOfWork; var sats = await unitOfWork.Of().GetAllAsync(); var satList = sats.To>(); //启用的天线才可以选择 var txs = await unitOfWork.Of().GetAllAsync(m => m.Enable); var txList = txs.To>(); this.txtSat.UseDefault().SetData(satList, displayField: nameof(SatViewModel.Sat)).UseDoubleClickToSelectAll(); this.txtAnt.UseDefault().SetData(txList, displayField: nameof(RecTxViewModel.Name)).UseDoubleClickToSelectAll(); if (this.Text == "编辑采集通道" && info != null) { var sat = satList.FirstOrDefault(s => s.Id == info.SatInfoID); var ant = txList.FirstOrDefault(a => a.Id == info.TxInfoID); this.txtChannel.EditValue = info.ChNum; this.txtCenterFreq.EditValue = info.CenterFreq; this.txtSat.EditValue = sat; this.txtAnt.EditValue = ant; this.checkEdit.EditValue = info.Enable; } } private void btnOk_Click(object sender, EventArgs e) { try { if (!int.TryParse(txtChannel.Text, out int chNum)) { DxHelper.MsgBoxHelper.ShowError($"通道号非有效整形数字"); return; } if (infos.Any(i => i.Id != info.Id && i.ChNum == chNum)) { DxHelper.MsgBoxHelper.ShowError($"通道号[{txtChannel.Text}]已经存在!"); return; } if (!double.TryParse(txtCenterFreq.Text, out double centerFreq)) { DxHelper.MsgBoxHelper.ShowError($"中心频点非有效数字"); return; } if (txtSat.EditValue == null) { DxHelper.MsgBoxHelper.ShowError($"卫星不能为空"); return; } if (txtAnt.EditValue == null) { DxHelper.MsgBoxHelper.ShowError($"天线不能为空"); return; } info.ChNum = chNum; info.CenterFreq = centerFreq; info.SatInfoID = ((SatViewModel)txtSat.EditValue).Id; info.TxInfoID = ((RecTxViewModel)txtAnt.EditValue).Id; info.Enable = (bool)checkEdit.EditValue; this.DialogResult = DialogResult.OK; } catch (Exception ex) { string msg = "编辑采集通道信息出错"; IocContainer.Logger.Error(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } private void btnCancle_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } } }