X2D1PosParamEditor.cs 9.5 KB

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