using DevExpress.XtraEditors; using XdCxRhDW.App.EFContext; using XdCxRhDW.App.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors.Controls; namespace XdCxRhDW.App.UserControl { public partial class CtrlTx : DevExpress.XtraEditors.XtraUserControl { List list = new List(); public CtrlTx() { InitializeComponent(); } private async void CtrlTx_Load(object sender, EventArgs e) { try { using (RHDWContext db = new RHDWContext()) { var sats = await db.SatInfos.ToListAsync(); foreach (var item in sats) { this.txtMainSat.Properties.Items.Add(new ImageComboBoxItem(item.Sat, item)); this.txtAdjaSat.Properties.Items.Add(new ImageComboBoxItem(item.Sat, item)); } list = await db.TxInfos.ToListAsync(); var mainTx = list.Find(p => p.TxType == EnumTxType.MainSat); var adjaTx = list.Find(p => p.TxType == EnumTxType.AdjaSat); 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 (mainTx != null) { this.txtMainTxName.Text = mainTx.Name; this.txtMainTxLon.Text = mainTx.Lon.ToString(); this.txtMainTxLat.Text = mainTx.Lat.ToString(); this.txtMainSat.EditValue = mainTx.SatInfo; } if (adjaTx != null) { this.txtAdjaTxName.Text = adjaTx.Name; this.txtAdjaTxLon.Text = adjaTx.Lon.ToString(); this.txtAdjaTxLat.Text = adjaTx.Lat.ToString(); this.txtAdjaSat.EditValue = adjaTx.SatInfo; } 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.txtRefLon.Text = refLoc.Lon.ToString(); this.txtRefLat.Text = refLoc.Lat.ToString(); } } } catch (Exception ex) { Serilog.Log.Error(ex,"加载天线信息异常"); DxHelper.MsgBoxHelper.ShowError("加载天线信息异常"); } } private async void btnSave_Click(object sender, EventArgs e) { try { TxInfo txMain = list.Find(p => p.TxType == EnumTxType.MainSat); TxInfo txAdja = list.Find(p => p.TxType == EnumTxType.AdjaSat); 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 (txMain == null) txMain = new TxInfo(); if (txAdja == null) txAdja = new TxInfo(); if (txCdb == null) txCdb = new TxInfo(); if (txCx == null) txCx = new TxInfo(); if (txRef == null) txRef = new TxInfo(); List tmp = new List(); txMain.Name = txtMainTxName.Text; txMain.TxType = EnumTxType.MainSat; if (!double.TryParse(txtMainTxLon.Text.Trim(), out double lon)) throw new Exception("主星天线经度格式错误!"); if (!double.TryParse(txtMainTxLat.Text.Trim(), out double lat)) throw new Exception("主星天线纬度格式错误!"); txMain.Lon = lon; txMain.Lat = lat; txMain.SatInfoID = (txtMainSat.EditValue as SatInfo)?.ID; tmp.Add(txMain); txAdja.Name = txtAdjaTxName.Text; txAdja.TxType = EnumTxType.AdjaSat; if (!double.TryParse(txtAdjaTxLon.Text.Trim(), out double adjaLon)) throw new Exception("邻星天线经度格式错误!"); if (!double.TryParse(txtAdjaTxLat.Text.Trim(), out double adjaLat)) throw new Exception("邻星天线纬度格式错误!"); txAdja.Lon = adjaLon; txAdja.Lat = adjaLat; txAdja.SatInfoID = (txtAdjaSat.EditValue as SatInfo)?.ID; tmp.Add(txAdja); 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; txCdb.SatInfoID = null; 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; txCx.SatInfoID = null; tmp.Add(txCx); 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; txRef.SatInfoID = null; tmp.Add(txRef); using (RHDWContext db = new RHDWContext()) { foreach (var item in tmp) { var find = await db.TxInfos.Where(p => p.ID == item.ID).FirstOrDefaultAsync(); if (find != null) { find.Name = item.Name; find.Lon = item.Lon; find.Lat = item.Lat; find.SatInfoID = item.SatInfoID; } else { db.TxInfos.Add(item); } await db.SaveChangesAsync(); } } DxHelper.MsgBoxHelper.ShowInfo("保存成功!"); } catch (Exception ex) { Serilog.Log.Error(ex, "保存天线信息异常"); DxHelper.MsgBoxHelper.ShowError($"保存天线信息异常.{ex.Message}"); } } } }