using DevExpress.XtraEditors; 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 DevExpress.XtraEditors.Controls; using ExtensionsDev; using DW5S.Entity; using DW5S.Repostory; using Serilog; using DW5S.Service; namespace DW5S.App.UserControl { public partial class CtrlTx : DevExpress.XtraEditors.XtraUserControl { List list = new List(); public CtrlTx() { InitializeComponent(); this.layoutControl1.UseDefault(); this.layoutControl2.UseDefault(); this.layoutControl3.UseDefault(); this.layoutControl4.UseDefault(); } private async void CtrlTx_Load(object sender, EventArgs e) { try { var unitOfWork = IocContainer.UnitOfWork; var repsSys = unitOfWork.Of(); list = (await repsSys.GetAllAsync()).ToList(); var recTx = list.Find(p => p.TxType == EnumTxType.Rec); var cdbTx = list.Find(p => p.TxType == EnumTxType.Cdb); var cxTx = list.Find(p => p.TxType == EnumTxType.Cx); var refLoc = list.Find(p => p.TxType == EnumTxType.Ref); if (recTx != null) { this.txtMainTxName.Text = recTx.Name; this.txtMainTxLon.Text = recTx.Lon.ToString(); this.txtMainTxLat.Text = recTx.Lat.ToString(); } if (cdbTx != null) { this.txtCdbName.Text = cdbTx.Name; this.txtCdbLon.Text = cdbTx.Lon.ToString(); this.txtCdbLat.Text = cdbTx.Lat.ToString(); } if (cxTx != null) { this.txtCxName.Text = cxTx.Name; this.txtCxLon.Text = cxTx.Lon.ToString(); this.txtCxLat.Text = cxTx.Lat.ToString(); } if (refLoc != null) { this.txtRefName.Text = refLoc.Name; this.txtRefLon.Text = refLoc.Lon.ToString(); this.txtRefLat.Text = refLoc.Lat.ToString(); } } catch (Exception ex) { IocContainer.Logger.Error("加载天线信息异常", ex); DxHelper.MsgBoxHelper.ShowError("加载天线信息异常"); } } private async void btnSave_Click(object sender, EventArgs e) { try { TxInfo txRec = list.Find(p => p.TxType == EnumTxType.Rec); TxInfo txCdb = list.Find(p => p.TxType == EnumTxType.Cdb); TxInfo txCx = list.Find(p => p.TxType == EnumTxType.Cx); TxInfo txRef = list.Find(p => p.TxType == EnumTxType.Ref); if (txRec == null) txRec = new TxInfo(); if (txCdb == null) txCdb = new TxInfo(); if (txCx == null) txCx = new TxInfo(); if (txRef == null) txRef = new TxInfo(); List tmp = new List(); txRec.Name = txtMainTxName.Text; txRec.TxType = EnumTxType.Rec; if (!double.TryParse(txtMainTxLon.Text.Trim(), out double lon)) throw new Exception("接收站天线经度格式错误!"); if (!double.TryParse(txtMainTxLat.Text.Trim(), out double lat)) throw new Exception("接收站天线纬度格式错误!"); txRec.Lon = lon; txRec.Lat = lat; tmp.Add(txRec); txCdb.Name = txtCdbName.Text; txCdb.TxType = EnumTxType.Cdb; if (!double.TryParse(txtCdbLon.Text.Trim(), out double cdbLon)) throw new Exception("超短站位置经度格式错误!"); if (!double.TryParse(txtCdbLat.Text.Trim(), out double cdbLat)) throw new Exception("超短站位置纬度格式错误!"); txCdb.Lon = cdbLon; txCdb.Lat = cdbLat; tmp.Add(txCdb); txCx.Name = txtCxName.Text; txCx.TxType = EnumTxType.Cx; if (!double.TryParse(txtCxLon.Text.Trim(), out double cxLon)) throw new Exception("测向站位置经度格式错误!"); if (!double.TryParse(txtCxLat.Text.Trim(), out double cxLat)) throw new Exception("测向站位置纬度格式错误!"); txCx.Lon = cxLon; txCx.Lat = cxLat; tmp.Add(txCx); txRef.Name = txtRefName.Text; txRef.TxType = EnumTxType.Ref; if (!double.TryParse(txtRefLon.Text.Trim(), out double refLon)) throw new Exception("参考站位置经度格式错误!"); if (!double.TryParse(txtRefLat.Text.Trim(), out double refLat)) throw new Exception("参考站位置纬度格式错误!"); txRef.Lon = refLon; txRef.Lat = refLat; tmp.Add(txRef); var unitOfWork = IocContainer.UnitOfWork; var repsSys = unitOfWork.Of(); foreach (var item in tmp) { var find = await repsSys.FirstOrDefaultAsync(p => p.Id == item.Id); if (find != null) { find.Name = item.Name; find.Lon = item.Lon; find.Lat = item.Lat; find.SatInfoID = item.SatInfoID; find.UpdateTime = DateTime.Now; await repsSys.AddOrUpdateAsync(find); } } await unitOfWork.SaveAsync(); DxHelper.MsgBoxHelper.ShowInfo("保存成功!"); } catch (Exception ex) { IocContainer.Logger.Error(ex,"保存天线信息异常"); DxHelper.MsgBoxHelper.ShowError($"保存天线信息异常.{ex.Message}"); } } } }