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 XzXdDw.App.Api; using XzXdDw.App.EFContext; using XzXdDw.App.Model; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; namespace XzXdDw.App.EditForms { public partial class X2PosParamEditor : DevExpress.XtraEditors.XtraForm { public XZPosRes info; private CgRes cgRes; private Action callBack; public X2PosParamEditor(XZPosRes info, CgRes cgRes, TxInfo refTx,double fu1,double fu2, Action callBack) { InitializeComponent(); this.Text = "两星定位"; this.info = info; if (cgRes == null) { cgRes = new CgRes(); } this.cgRes = cgRes; this.callBack = callBack; this.txtRefLocation.Text = $"{refTx.Lon},{refTx.Lat}"; this.txtTargetDto.Text = $"{cgRes.DtoSx}"; this.txtTargetDfo.Text = $"{cgRes.DfoSx}"; this.txtRefDTo.Text = $"{cgRes.DtoCdb}"; this.txtRefDfo.Text = $"{cgRes.DfoCdb}"; this.sigTime.EditValue = cgRes.SigTime; this.txtTargetUpFreq.Text = $"{fu1*1e-6}"; this.txtRefUpFreq.Text = $"{fu2 * 1e-6}"; this.txtMainX.Text = $"{cgRes.MainX}"; this.txtMainY.Text = $"{cgRes.MainY}"; this.txtMainZ.Text = $"{cgRes.MainZ}"; this.txtMainVX.Text = $"{cgRes.MainVX}"; this.txtMainVY.Text = $"{cgRes.MainVY}"; this.txtMainVZ.Text = $"{cgRes.MainVZ}"; this.txtAdjaX.Text = $"{cgRes.AdjaX}"; this.txtAdjaY.Text = $"{cgRes.AdjaY}"; this.txtAdjaZ.Text = $"{cgRes.AdjaZ}"; this.txtAdjaVX.Text = $"{cgRes.AdjaVX}"; this.txtAdjaVY.Text = $"{cgRes.AdjaVY}"; this.txtAdjaVZ.Text = $"{cgRes.AdjaVZ}"; this.StartPosition = FormStartPosition.CenterParent; txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged; } private void TxtRefLocation_EditValueChanged(object sender, EventArgs e) { txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"); } 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.txtTargetDto.Text); cgRes.DfoSx = Convert.ToDouble(this.txtTargetDfo.Text); cgRes.DtoCdb = Convert.ToDouble(this.txtRefDTo.Text); cgRes.DfoCdb = Convert.ToDouble(this.txtRefDfo.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.MainVX = Convert.ToDouble(this.txtMainVX.Text); cgRes.MainVY = Convert.ToDouble(this.txtMainVY.Text); cgRes.MainVZ = Convert.ToDouble(this.txtMainVZ.Text); cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text); cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text); cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text); cgRes.AdjaVX = Convert.ToDouble(this.txtAdjaVX.Text); cgRes.AdjaVY = Convert.ToDouble(this.txtAdjaVY.Text); cgRes.AdjaVZ = Convert.ToDouble(this.txtAdjaVZ.Text); string posstr = this.listBox.Items[0].ToString(); var allstrs = posstr.Split(new string[] { ":", "PosLon", "PosLat", "MirrLon", "MirrLat" }, StringSplitOptions.RemoveEmptyEntries); if (allstrs.Length == 5) { using (RHDWContext db = new RHDWContext()) { info.PosLon = Convert.ToDouble(allstrs[1]); info.PosLat = Convert.ToDouble(allstrs[2]); info.MirrLon = Convert.ToDouble(allstrs[3]); info.MirrLat = Convert.ToDouble(allstrs[4]); db.CgRes.AddOrUpdate(cgRes);//参估结果入库 db.XZPosRes.AddOrUpdate(info);//定位结果入库 db.SaveChangesAsync(); } callBack?.Invoke(); XtraMessageBox.Show($"两星更新数据成功"); } } catch (Exception ex) { XtraMessageBox.Show($"两星更新定位数据失败,失败信息:{ex.Message}"); } } public bool CheckParam() { if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } return true; } private void btnOk_Click(object sender, EventArgs e) { listBox.Items.Clear(); if (!CheckParam()) { return; } try { TxInfo refTx = new TxInfo(); refTx.Lon = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[0].Trim()); refTx.Lat = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[1].Trim()); double fu1= Convert.ToDouble(this.txtTargetUpFreq.Text) * 1e6; double fu2 = Convert.ToDouble(this.txtRefUpFreq.Text) * 1e6; CgRes cgRes = new CgRes(); cgRes.DtoSx = Convert.ToDouble(this.txtTargetDto.Text); cgRes.DfoSx = Convert.ToDouble(this.txtTargetDfo.Text); cgRes.DtoCdb = Convert.ToDouble(this.txtRefDTo.Text); cgRes.DfoCdb = Convert.ToDouble(this.txtRefDfo.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.MainVX = Convert.ToDouble(this.txtMainVX.Text); cgRes.MainVY = Convert.ToDouble(this.txtMainVY.Text); cgRes.MainVZ = Convert.ToDouble(this.txtMainVZ.Text); cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text); cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text); cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text); cgRes.AdjaVX = Convert.ToDouble(this.txtAdjaVX.Text); cgRes.AdjaVY = Convert.ToDouble(this.txtAdjaVY.Text); cgRes.AdjaVZ = Convert.ToDouble(this.txtAdjaVZ.Text); var res = PosApi.X2_POS(cgRes,refTx,fu1,fu2); listBox.Items.Add($" 定位结果 PosLon:{res[0]} PosLat:{res[1]} MirrLon:{res[3]} MirrLat:{res[4]}"); } catch (Exception ex) { XtraMessageBox.Show($"两星定位失败,失败信息:{ex.Message}"); } } } }