using DevExpress.Mvvm.ModuleInjection.Native; using DevExpress.XtraEditors; using DevExpress.XtraEditors.DXErrorProvider; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Data.Entity.Migrations; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using XdDw.App.Api; using XdDw.App.EFContext; using XzXdDw.App.Model; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; namespace XdDw.App.EditForms { public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraForm { public XDPosRes info; public List listTx; private CgRes cgRes; private double[] PosRes; private Action callBack; public X2D1PosParamEditor(XDPosRes info, CgRes cgRes, List listTx, Action callBack) { InitializeComponent(); this.Text = "两星一地定位"; this.info = info; if (cgRes == null) { cgRes = new CgRes(); } this.cgRes = cgRes; this.listTx = listTx; this.callBack = callBack; this.StartPosition = FormStartPosition.CenterParent; txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged; txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged; txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged; } private void TxtRefLocation_EditValueChanged(object sender, EventArgs e) { txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"); } private void TxtcdbStation_EditValueChanged(object sender, EventArgs e) { txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"); } private void TxtsatStation_EditValueChanged(object sender, EventArgs e) { txtsatStation.CheckLonLat(dxErrorProvider, "接收站"); } private async void X2D1PosParamEditor_Load(object sender, EventArgs e) { List list = new List(); using (RHDWContext db = new RHDWContext()) { var res = await db.XlInfos.OrderBy(p => p.SatName).ToListAsync(); if (res != null) list.AddRange(res.Select(p => p.Sat)); } var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat); var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb); var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref); this.txtsatStation.Text = $"{satTx.Lon},{satTx.Lat}"; this.txtcdbStation.Text = $"{cdbTx.Lon},{cdbTx.Lat}"; this.txtRefLocation.Text = $"{refTx.Lon},{refTx.Lat}"; this.txtDtoSx.Text = $"{cgRes.DtoSx}"; this.txtDtoCdb.Text = $"{cgRes.DtoCdb}"; this.txtYbMain.Text = $"{cgRes.YbMain}"; this.txtYbAdja.Text = $"{cgRes.YbAdja}"; this.sigTime.EditValue = cgRes.SigTime; this.txtMainX.Text = $"{cgRes.MainX}"; this.txtMainY.Text = $"{cgRes.MainY}"; this.txtMainZ.Text = $"{cgRes.MainZ}"; this.txtAdjaX.Text = $"{cgRes.AdjaX}"; this.txtAdjaY.Text = $"{cgRes.AdjaY}"; this.txtAdjaZ.Text = $"{cgRes.AdjaZ}"; } private void btnUpdate_Click(object sender, EventArgs e) { try { if (!CheckParam()) { return; } if (this.listBox.Items.Count == 0) { XtraMessageBox.Show($"两星一地未定位不能更新到数据库中"); return; } cgRes.DtoSx = Convert.ToDouble(this.txtDtoSx.Text); cgRes.DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); cgRes.YbMain = Convert.ToDouble(this.txtYbMain.Text); cgRes.YbAdja = Convert.ToDouble(this.txtYbAdja.Text); cgRes.SigTime = this.sigTime.DateTime; cgRes.MainX = Convert.ToDouble(this.txtMainX.Text); cgRes.MainY = Convert.ToDouble(this.txtMainY.Text); cgRes.MainZ = Convert.ToDouble(this.txtMainZ.Text); cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text); cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text); cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text); string posstr = this.listBox.Items[0].ToString(); var allstrs = posstr.Split(new string[] { ":", "定位经度", "定位纬度", "镜像经度", "镜像纬度" }, StringSplitOptions.RemoveEmptyEntries); if (allstrs.Length == 4) { using (RHDWContext db = new RHDWContext()) { info.PosLon = Convert.ToDouble(PosRes[0]); info.PosLat = Convert.ToDouble(PosRes[1]); info.MirrLon = Convert.ToDouble(PosRes[3]); info.MirrLat = Convert.ToDouble(PosRes[4]); db.CgRes.AddOrUpdate(cgRes);//参估结果入库 db.XDPosRes.AddOrUpdate(info);//定位结果入库 db.SaveChangesAsync(); } callBack?.Invoke(); XtraMessageBox.Show($"两星一地更新数据成功"); } } catch (Exception ex) { XtraMessageBox.Show($"两星一地更新定位数据失败,失败信息:{ex.Message}"); } } public bool CheckParam() { if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } return true; } private void btnOk_Click(object sender, EventArgs e) { listBox.Items.Clear(); if (!CheckParam()) { return; } try { TxInfo satTx = new TxInfo(); satTx.Lon = Convert.ToDouble(txtsatStation.Text.Replace(",", ",").Split(',')[0].Trim()); satTx.Lat = Convert.ToDouble(txtsatStation.Text.Replace(",", ",").Split(',')[1].Trim()); TxInfo cdbTx = new TxInfo(); cdbTx.Lon = Convert.ToDouble(txtcdbStation.Text.Replace(",", ",").Split(',')[0].Trim()); cdbTx.Lat = Convert.ToDouble(txtcdbStation.Text.Replace(",", ",").Split(',')[1].Trim()); TxInfo refTx = new TxInfo(); refTx.Lon = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[0].Trim()); refTx.Lat = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[1].Trim()); CgRes cgRes = new CgRes(); cgRes.DtoSx = Convert.ToDouble(this.txtDtoSx.Text); cgRes.DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); cgRes.YbMain = Convert.ToDouble(this.txtYbMain.Text); cgRes.YbAdja = Convert.ToDouble(this.txtYbAdja.Text); cgRes.SigTime = this.sigTime.DateTime; cgRes.MainX = Convert.ToDouble(this.txtMainX.Text); cgRes.MainY = Convert.ToDouble(this.txtMainY.Text); cgRes.MainZ = Convert.ToDouble(this.txtMainZ.Text); cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text); cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text); cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text); PosRes = PosApi.X2D1_POS(cgRes, satTx, cdbTx, refTx); listBox.Items.Add($"定位经度:{PosRes[0]:f4} 定位纬度:{PosRes[1]:f4} 镜像经度:{PosRes[3]:f4} 镜像纬度:{PosRes[4]:f4}"); } catch (Exception ex) { XtraMessageBox.Show($"两星一地定位失败,失败信息:{ex.Message}"); } } } }