XlCalculateForm.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraTreeList.Data;
  3. using ExtensionsDev;
  4. using PosResAnalysis;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using DW5S.DTO;
  16. using DW5S.Entity;
  17. using DW5S.Repostory;
  18. using Serilog;
  19. using DW5S.Service;
  20. using DW5S.ViewModel;
  21. namespace DW5S.App.CorTools
  22. {
  23. public partial class XlCalculateForm : DevExpress.XtraEditors.XtraForm
  24. {
  25. List<SatEphResViewModel> listEph = new List<SatEphResViewModel>();
  26. //选择卫星执行星历推算
  27. public XlCalculateForm()
  28. {
  29. InitializeComponent();
  30. this.itemTle.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  31. var unitOfWork = IocContainer.UnitOfWork;
  32. var list1 = unitOfWork.Of<SatInfo>().GetAllAsync(p => p.SatCode).Result;
  33. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  34. var list2 = repsXl.GetAllSat().Result.ToList();//所有卫星
  35. list2.RemoveAll(p => list1.Select(t => t.SatCode).Contains(p.SatCode));
  36. list2.InsertRange(0, list1);
  37. this.txtSat.UseDefault().SetData(list2, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  38. }
  39. //选择TLE执行星历推算
  40. public XlCalculateForm(string tle)
  41. : this()
  42. {
  43. this.Text = "星历推算";
  44. this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  45. this.IconOptions.ShowIcon = false;
  46. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  47. this.txtTle.Text = tle;
  48. this.itemTle.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  49. this.itemSat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  50. }
  51. private void XlCalculateForm_Load(object sender, EventArgs e)
  52. {
  53. gridControl.UseDefault(listEph).UseMultiSelect().UseRowNumber();
  54. txtStartTime.UseDefault().UseDoubleClickToSelectAll();
  55. txtEndTime.UseDefault().UseDoubleClickToSelectAll();
  56. layoutControl1.BestFit();
  57. }
  58. private async void btnCalculate_Click(object sender, EventArgs e)
  59. {
  60. if (itemSat.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
  61. {
  62. if (txtSat.EditValue == null)
  63. {
  64. DxHelper.MsgBoxHelper.ShowError("请选择卫星");
  65. return;
  66. }
  67. }
  68. else
  69. {
  70. if (string.IsNullOrWhiteSpace(txtTle.Text))
  71. {
  72. DxHelper.MsgBoxHelper.ShowError("请选择双行根数");
  73. return;
  74. }
  75. }
  76. if (string.IsNullOrWhiteSpace(txtStartTime.Text))
  77. {
  78. DxHelper.MsgBoxHelper.ShowError("请填写开始时间");
  79. return;
  80. }
  81. int spanSeconds = 1;
  82. if (txtEndTime.DateTime != txtStartTime.DateTime)
  83. {
  84. if (!string.IsNullOrEmpty(txtEndTime.Text) && !int.TryParse(txtSpanSeconds.Text, out spanSeconds))
  85. {
  86. DxHelper.MsgBoxHelper.ShowError("推算间隔非数字");
  87. return;
  88. }
  89. }
  90. var startTime = Convert.ToDateTime(txtStartTime.EditValue);
  91. var endTime = Convert.ToDateTime(txtEndTime.EditValue);
  92. if (!string.IsNullOrEmpty(txtStartTime.Text) && !string.IsNullOrEmpty(txtEndTime.Text))
  93. {
  94. if (endTime < startTime)
  95. {
  96. DxHelper.MsgBoxHelper.ShowError("开始时间不能大于结束时间");
  97. return;
  98. }
  99. if ((endTime - startTime).TotalHours > 24)
  100. {
  101. DxHelper.MsgBoxHelper.ShowError("开始时间和结束时间不能相差超过24小时");
  102. return;
  103. }
  104. }
  105. listEph.Clear();
  106. try
  107. {
  108. var unitOfWork = IocContainer.UnitOfWork;
  109. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  110. if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text))
  111. {
  112. var XlCalcMultDto = new XlCalcMultDto()
  113. {
  114. startTime = startTime,
  115. endTime = endTime,
  116. spanSeconds = spanSeconds,
  117. };
  118. if (itemTle.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
  119. {
  120. XlCalcMultDto.tleStr = txtTle.Text.Trim();
  121. }
  122. else
  123. {
  124. var sat = txtSat.EditValue as SatInfo;
  125. var xlInfo = await repsXl.GetLatestAsync(sat.SatCode, startTime);
  126. XlCalcMultDto.tleStr = xlInfo.TwoLine;
  127. }
  128. var ephRes = await HttpHelper.PostRequestAsync<List<SatEphResViewModel>>(SysConfig.GetUrl("Xl/CalcMult"), XlCalcMultDto);
  129. if (ephRes.code == 200)
  130. {
  131. listEph.AddRange(ephRes.data);
  132. gridView.RefreshData();
  133. }
  134. else
  135. {
  136. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  137. }
  138. }
  139. else
  140. {
  141. var XlCalcDto = new XlCalcDto()
  142. {
  143. SigTime = txtStartTime.DateTime,
  144. };
  145. if (itemTle.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
  146. {
  147. XlCalcDto.tleStr = txtTle.Text;
  148. }
  149. else
  150. {
  151. var sat = txtSat.EditValue as SatInfo;
  152. var xlInfo = await repsXl.GetLatestAsync(sat.SatCode, XlCalcDto.SigTime);
  153. XlCalcDto.tleStr = xlInfo.TwoLine;
  154. }
  155. var ephRes = await HttpHelper.PostRequestAsync<SatEphResViewModel>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  156. if (ephRes.code == 200)
  157. {
  158. listEph.Add(ephRes.data);
  159. gridView.RefreshData();
  160. }
  161. else
  162. {
  163. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  164. }
  165. }
  166. }
  167. catch (TaskCanceledException)
  168. {
  169. string msg = "星历推算Http接口调用超时";
  170. IocContainer.Logger.Warning(msg);
  171. DxHelper.MsgBoxHelper.ShowWarning("星历推算Http接口调用超时");
  172. }
  173. catch (Exception ex)
  174. {
  175. string msg = "星历推算异常";
  176. IocContainer.Logger.Error(ex,msg);
  177. DxHelper.MsgBoxHelper.ShowError("星历推算异常");
  178. }
  179. }
  180. }
  181. }