X1D1PosParamEditor.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.Entity;
  15. using XdCxRhDW.Repostory;
  16. namespace XdCxRhDW.App.EditForms
  17. {
  18. public partial class X1D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. private MapControl mapControl1;
  21. private PosRes info;
  22. private CgRes cg;
  23. private List<SatInfo> listSat;
  24. public X1D1PosParamEditor(PosRes info, MapControl mapControl)
  25. {
  26. InitializeComponent();
  27. this.info = info;
  28. this.listSat = new List<SatInfo>();
  29. this.mapControl1 = mapControl;
  30. this.labelControl1.Text = $"";
  31. //this.StartPosition = FormStartPosition.CenterParent;
  32. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  33. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  34. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  35. txtCxLocation.EditValueChanged += TxtCxLocation_EditValueChanged;
  36. }
  37. private void TxtCxLocation_EditValueChanged(object sender, EventArgs e)
  38. {
  39. txtCxLocation.CheckLonLat(dxErrorProvider, "测向站");
  40. }
  41. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  42. {
  43. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  44. }
  45. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  46. {
  47. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  48. }
  49. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  50. {
  51. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  52. }
  53. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  54. {
  55. StationRes station;
  56. CxRes cx;
  57. using (RHDWContext db = new RHDWContext())
  58. {
  59. listSat = await db.SatInfos.ToListAsync();
  60. }
  61. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  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. if (cg != null)
  68. {
  69. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  70. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  71. this.sigTime.EditValue = info.SigTime;
  72. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  73. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  74. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  75. }
  76. if (cx != null)
  77. {
  78. this.txtcxFx.Text = $"{cx.Fx:f3}";
  79. }
  80. if (station != null)
  81. {
  82. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  83. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  84. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  85. this.txtCxLocation.Text = $"{station.CxLon:f3},{station.CxLat:f3}";
  86. }
  87. }
  88. public bool CheckParam()
  89. {
  90. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  91. {
  92. return false;
  93. }
  94. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  95. {
  96. return false;
  97. }
  98. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  99. {
  100. return false;
  101. }
  102. return true;
  103. }
  104. private void btnOk_Click(object sender, EventArgs e)
  105. {
  106. if (!CheckParam()) { return; }
  107. try
  108. {
  109. var MsAnt = txtsatStation.GetLonLat();
  110. var CDBAnt = txtcdbStation.GetLonLat();
  111. var RefGeod = txtRefLocation.GetLonLat();
  112. var CXStation = txtCxLocation.GetLonLat();
  113. var sigTime = this.sigTime.DateTime;
  114. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  115. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  116. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  117. var MainX = Convert.ToDouble(this.txtMainX.Text);
  118. var MainY = Convert.ToDouble(this.txtMainY.Text);
  119. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  120. var StationRes = new StationRes()
  121. {
  122. SatTxLon = MsAnt[0],
  123. SatTxLat = MsAnt[1],
  124. CdbTxLon = CDBAnt[0],
  125. CdbTxLat = CDBAnt[1],
  126. CxLon = CXStation[0],
  127. CxLat = CXStation[1],
  128. RefLon = RefGeod[0],
  129. RefLat = RefGeod[1],
  130. };
  131. var cgRes = new CgRes()
  132. {
  133. SigTime = sigTime,
  134. DtoCdb = DtoCdb,
  135. YbMainDto = YbMainDto,
  136. MainX = MainX,
  137. MainY = MainY,
  138. MainZ = MainZ,
  139. };
  140. var cxRes = new CxRes()
  141. {
  142. SigTime = sigTime,
  143. Fx = Fx,
  144. };
  145. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  146. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  147. }
  148. catch (Exception ex)
  149. {
  150. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  151. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  152. }
  153. }
  154. private async void btnCalcXl_Click(object sender, EventArgs e)
  155. {
  156. try
  157. {
  158. var sigTime = this.sigTime.DateTime;
  159. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  160. if (xlInfo == null)
  161. {
  162. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  163. return;
  164. }
  165. var p = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  166. this.txtMainX.Text = $"{p.X:f3}";
  167. this.txtMainY.Text = $"{p.Y:f3}";
  168. this.txtMainZ.Text = $"{p.Z:f3}";
  169. }
  170. catch (Exception ex)
  171. {
  172. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  173. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  174. }
  175. }
  176. }
  177. }