123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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<TxInfo> list = new List<TxInfo>();
- 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<TxInfo> tmp = new List<TxInfo>();
- 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}");
- }
- }
- }
- }
|