X2D1PosParamEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using DevExpress.XtraLayout;
  5. using DevExpress.XtraMap;
  6. using DevExpress.XtraTreeList.Data;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Data.Entity.Migrations;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Security.Policy;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using XdCxRhDw.Dto;
  24. using XdCxRhDW.App.App.Properties;
  25. using XdCxRhDW.Core;
  26. using XdCxRhDW.Core.Api;
  27. using XdCxRhDW.Repostory;
  28. using XdCxRhDW.Repostory.EFContext;
  29. using XdCxRhDW.Repostory.Model;
  30. namespace XdCxRhDW.App.EditForms
  31. {
  32. public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  33. {
  34. private List<SatInfo> listSat;
  35. private PosRes info;
  36. private CgRes cg;
  37. private int mainSat;
  38. private int adjaSat;
  39. private SysSetings settings = new SysSetings();
  40. public X2D1PosParamEditor(PosRes info)
  41. {
  42. InitializeComponent();
  43. this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位";
  44. this.info = info;
  45. this.listSat = new List<SatInfo>();
  46. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  47. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  48. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  49. }
  50. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  51. {
  52. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  53. }
  54. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  55. {
  56. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  57. }
  58. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  59. {
  60. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  61. }
  62. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  63. {
  64. StationRes station;
  65. using (RHDWContext db = new RHDWContext())
  66. {
  67. listSat = await db.SatInfos.ToListAsync();
  68. settings = await db.SysSetings.FirstOrDefaultAsync();
  69. }
  70. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  71. {
  72. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  73. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  74. }
  75. if (cg != null)
  76. {
  77. mainSat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value).SatCode;
  78. adjaSat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value).SatCode;
  79. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  80. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  81. if (info.PosResType == EnumPosResType.X2D1)
  82. {
  83. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  84. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  85. }
  86. this.txtSigTime.EditValue = info.SigTime;
  87. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  88. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  89. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  90. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  91. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  92. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  93. }
  94. if (station != null)
  95. {
  96. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  97. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  98. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  99. }
  100. if (info.PosResType == EnumPosResType.X2D1NoRef)
  101. {
  102. txtYbMain.Properties.ReadOnly = true;
  103. txtYbAdja.Properties.ReadOnly = true;
  104. txtRefLocation.Properties.ReadOnly = true;
  105. this.txtRefLocation.Text = $"{0},{0}";
  106. }
  107. }
  108. public bool CheckParam()
  109. {
  110. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  111. {
  112. return false;
  113. }
  114. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  115. {
  116. return false;
  117. }
  118. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  119. {
  120. return false;
  121. }
  122. return true;
  123. }
  124. private async void btnOk_Click(object sender, EventArgs e)
  125. {
  126. if (!CheckParam()) { return; }
  127. lblRes.Text = string.Empty;
  128. try
  129. {
  130. var MsAnt = txtsatStation.GetLonLat();
  131. var CDBAnt = txtcdbStation.GetLonLat();
  132. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  133. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  134. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  135. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  136. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  137. var MainX = Convert.ToDouble(this.txtMainX.Text);
  138. var MainY = Convert.ToDouble(this.txtMainY.Text);
  139. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  140. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  141. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  142. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  143. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  144. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  145. var sigTime = txtSigTime.DateTime;
  146. string url = string.Format("http://{0}:{1}/Api/Pos/", IpHelper.GetLocalIp(), settings.HttpPort);
  147. if (info.PosResType == EnumPosResType.X2D1NoRef)
  148. {
  149. url += "PosX2D1NoParAsync";
  150. X2D1NoParPosDto X2D1PosDto = new X2D1NoParPosDto()
  151. {
  152. SigTime = sigTime,
  153. MainCode = mainSat,
  154. AdjaCode = adjaSat,
  155. SxDto = DtoSx * 1e6,
  156. XdDto = DtoCdb * 1e6,
  157. MainX = MainX,
  158. MainY = MainY,
  159. MainZ = MainZ,
  160. AdjaX = AdjaX,
  161. AdjaY = AdjaY,
  162. AdjaZ = AdjaZ,
  163. SatTxLon = MsAnt[0],
  164. SatTxLat = MsAnt[1],
  165. CdbTxLon = CDBAnt[0],
  166. CdbTxLat = CDBAnt[1],
  167. };
  168. var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  169. if (result.code == 200)
  170. {
  171. lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  172. }
  173. }
  174. else
  175. {
  176. url += "PosX2D1Async";
  177. X2D1PosDto X2D1PosDto = new X2D1PosDto()
  178. {
  179. SigTime = sigTime,
  180. MainCode = mainSat,
  181. AdjaCode = adjaSat,
  182. SxDto = DtoSx * 1e6,
  183. XdDto = DtoCdb * 1e6,
  184. MainYbDto = YbMainDto * 1e6,
  185. AdjaYbDto = YbAdja1Dto * 1e6,
  186. MainX = MainX,
  187. MainY = MainY,
  188. MainZ = MainZ,
  189. AdjaX = AdjaX,
  190. AdjaY = AdjaY,
  191. AdjaZ = AdjaZ,
  192. SatTxLon = MsAnt[0],
  193. SatTxLat = MsAnt[1],
  194. CdbTxLon = CDBAnt[0],
  195. CdbTxLat = CDBAnt[1],
  196. RefLon = RefGeod[0],
  197. RefLat = RefGeod[1],
  198. };
  199. var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  200. if (result.code == 200)
  201. {
  202. lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  203. }
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. Serilog.Log.Error(ex, $"定位{info.PosResType.GetEnumDisplayName()}失败.PosID={info.ID},SigTime={info.SigTime}");
  209. DxHelper.MsgBoxHelper.ShowWarning($"定位{info.PosResType.GetEnumDisplayName()}失败");
  210. }
  211. }
  212. private async void btnMainXl_Click(object sender, EventArgs e)
  213. {
  214. var xlInfo = await XlCache.GetLatestAsync(mainSat, txtSigTime.DateTime);
  215. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  216. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  217. var ephMain = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto);
  218. this.txtMainX.Text = ephMain.data.X.ToString();
  219. this.txtMainY.Text = ephMain.data.Y.ToString();
  220. this.txtMainZ.Text = ephMain.data.Z.ToString();
  221. }
  222. private async void btnAdjaXl_Click(object sender, EventArgs e)
  223. {
  224. var xlInfo = await XlCache.GetLatestAsync(adjaSat, txtSigTime.DateTime);
  225. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  226. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  227. var ephAdja = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto);
  228. this.txtAdjaX.Text = ephAdja.data.X.ToString();
  229. this.txtAdjaY.Text = ephAdja.data.Y.ToString();
  230. this.txtAdjaZ.Text = ephAdja.data.Z.ToString();
  231. }
  232. }
  233. }