123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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<AdChannelViewModel> infos;
- public AdChannelEditor()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.Text = "添加采集通道";
- info = new AdChannelViewModel();
- infos = new List<AdChannelViewModel>();
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public AdChannelEditor(AdChannelViewModel info, List<AdChannelViewModel> 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<SatInfo>().GetAllAsync();
- var satList = sats.To<List<SatViewModel>>();
- //启用的天线才可以选择
- var txs = await unitOfWork.Of<TxInfo>().GetAllAsync(m => m.Enable);
- var txList = txs.To<List<RecTxViewModel>>();
- 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;
- }
- }
- }
|