X1D1PosParamEditor.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.Entity;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using XdCxRhDW.Api;
  14. using XdCxRhDW.App.App.Properties;
  15. using XdCxRhDW.Dto;
  16. using XdCxRhDW.Entity;
  17. using XdCxRhDW.Repostory;
  18. namespace XdCxRhDW.App.EditForms
  19. {
  20. public partial class X1D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private PosRes info;
  23. private CgRes cg;
  24. private SysSetings settings = new SysSetings();
  25. public X1D1PosParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.info = info;
  29. this.labelControl1.Text = $"";
  30. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  31. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  32. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  33. txtCxLocation.EditValueChanged += TxtCxLocation_EditValueChanged;
  34. }
  35. private void TxtCxLocation_EditValueChanged(object sender, EventArgs e)
  36. {
  37. txtCxLocation.CheckLonLat(dxErrorProvider, "测向站");
  38. }
  39. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  40. {
  41. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  42. }
  43. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  44. {
  45. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  46. }
  47. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  50. }
  51. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  52. {
  53. StationRes station=null;
  54. using (RHDWContext db = new RHDWContext())
  55. {
  56. settings = await db.SysSetings.FirstOrDefaultAsync();
  57. }
  58. CxRes cx=null;
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. if (db.DatabaseExist)
  62. {
  63. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  64. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  65. cx = await db.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  66. }
  67. }
  68. if (cg != null)
  69. {
  70. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  71. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  72. this.sigTime.EditValue = info.SigTime;
  73. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  74. }
  75. if (cx != null)
  76. {
  77. this.txtcxFx.Text = $"{cx.Fx:f3}";
  78. }
  79. if (station != null)
  80. {
  81. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  82. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  83. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  84. this.txtCxLocation.Text = $"{station.CxLon:f3},{station.CxLat:f3}";
  85. }
  86. }
  87. public bool CheckParam()
  88. {
  89. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  90. {
  91. return false;
  92. }
  93. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  94. {
  95. return false;
  96. }
  97. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  98. {
  99. return false;
  100. }
  101. return true;
  102. }
  103. private void btnOk_Click(object sender, EventArgs e)
  104. {
  105. if (!CheckParam()) { return; }
  106. try
  107. {
  108. var MsAnt = txtsatStation.GetLonLat();
  109. var CDBAnt = txtcdbStation.GetLonLat();
  110. var RefGeod = txtRefLocation.GetLonLat();
  111. var CXStation = txtCxLocation.GetLonLat();
  112. var sigTime = this.sigTime.DateTime;
  113. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  114. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  115. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  116. double[] msEph = ucEphXYZMain.EphXYZ();
  117. var StationRes = new StationRes()
  118. {
  119. SatTxLon = MsAnt[0],
  120. SatTxLat = MsAnt[1],
  121. CdbTxLon = CDBAnt[0],
  122. CdbTxLat = CDBAnt[1],
  123. CxLon = CXStation[0],
  124. CxLat = CXStation[1],
  125. RefLon = RefGeod[0],
  126. RefLat = RefGeod[1],
  127. };
  128. var cgRes = new CgRes()
  129. {
  130. SigTime = sigTime,
  131. DtoCdb = DtoCdb,
  132. YbMainDto = YbMainDto,
  133. MainX = msEph[0],
  134. MainY = msEph[1],
  135. MainZ = msEph[2],
  136. };
  137. var cxRes = new CxRes()
  138. {
  139. SigTime = sigTime,
  140. Fx = Fx,
  141. };
  142. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  143. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  144. }
  145. catch (Exception ex)
  146. {
  147. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  148. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  149. }
  150. }
  151. private async void btnCalcXl_Click(object sender, EventArgs e)
  152. {
  153. if (this.sigTime.DateTime == DateTime.MinValue)
  154. {
  155. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  156. return;
  157. }
  158. try
  159. {
  160. var sigTime = this.sigTime.DateTime;
  161. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  162. if (xlInfo == null)
  163. {
  164. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  165. return;
  166. }
  167. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = sigTime };
  168. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  169. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  170. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  171. }
  172. catch (Exception ex)
  173. {
  174. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  175. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  176. }
  177. }
  178. }
  179. }