using DevExpress.Mvvm.ModuleInjection.Native; using DevExpress.XtraEditors; using DevExpress.XtraEditors.DXErrorProvider; using DevExpress.XtraLayout; using DevExpress.XtraMap; using DevExpress.XtraTreeList.Data; using DxHelper; using ExtensionsDev; using System; using System.CodeDom; 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 XdCxRhDW.Api; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class X2DTOParamEditor : DevExpress.XtraEditors.XtraUserControl { private MapControl mapControl1; private PosRes info; private CgRes cg; private List listSat; public X2DTOParamEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.layoutControl1.UseDefault(); sigTime.UseDefault(); this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数"; this.info = info; this.listSat = new List(); this.mapControl1 = mapControl; //this.StartPosition = FormStartPosition.CenterParent; txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged; txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged; } private void TxtRefLocation_EditValueChanged(object sender, EventArgs e) { txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"); } private void TxtsatStation_EditValueChanged(object sender, EventArgs e) { txtsatStation.CheckLonLat(dxErrorProvider, "接收站"); } private async void X2DTOParamEditor_Load(object sender, EventArgs e) { StationRes station = null; using (RHDWContext db = new RHDWContext()) { listSat = await db.SatInfos.ToListAsync(); } using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime)) { cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync(); station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync(); } if (cg != null) { this.txtDtoSx.Text = $"{cg.Dto1.Value:f4}"; this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}"; this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f4}"; this.sigTime.EditValue = info.SigTime; ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black); ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black); } if (station != null) { this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}"; this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}"; } } public bool CheckParam() { if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } return true; } private void btnOk_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } try { var MsAnt = txtsatStation.GetLonLat(); var RefGeod = txtRefLocation.GetLonLat(); var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var YbMainDto = Convert.ToDouble(this.txtYbMain.Text); var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text); double[] msEph = ucEphXYZMain.EphXYZ(); double[] Ns1Eph = ucEphXYZAdaj.EphXYZ(); DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption(); twoStartOption.MsEph = msEph; twoStartOption.NsEph = Ns1Eph; twoStartOption.MsAnt = MsAnt; twoStartOption.NsAnt = MsAnt; twoStartOption.RefGeod = RefGeod; twoStartOption.TargetDto = DtoSx; twoStartOption.RefDto = YbMainDto - YbAdja1Dto; twoStartOption.PosLon = info.PosLon; twoStartOption.PosLat = info.PosLat; var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString(); var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat; if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString(); var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption); mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine); } catch (Exception ex) { Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}"); DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败"); } } private async void btnEphCalc_Click(object sender, EventArgs e) { if (this.sigTime.DateTime == DateTime.MinValue) { DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!"); return; } var sigTime = this.sigTime.DateTime; try { var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime); if (mainxlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历"); return; } var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc()); ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red); var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime); if (adjaxlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历"); return; } var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc()); ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red); } catch (Exception ex) { Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}"); DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}"); } } } }