XlCalculateForm.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.Data.Entity;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using XdCxRhDW.Dto;
  17. using XdCxRhDW.App.Model;
  18. using XdCxRhDW.Entity;
  19. using XdCxRhDW.Repostory;
  20. namespace XdCxRhDW.App.CorTools
  21. {
  22. public partial class XlCalculateForm : DevExpress.XtraEditors.XtraForm
  23. {
  24. List<ModelSatEphRes> listEph = new List<ModelSatEphRes>();
  25. public XlCalculateForm()
  26. {
  27. InitializeComponent();
  28. }
  29. private async void XlCalculateForm_Load(object sender, EventArgs e)
  30. {
  31. gridControl.UseDefault(listEph).UseMultiSelect().UseRowNumber();
  32. txtStartTime.UseDefault();
  33. txtEndTime.UseDefault();
  34. txtTle.UseDoubleClickToSelectAll();
  35. txtTle.UseDefault().SetData(await XlRepository.GetAllAsync(), nameof(XlInfo.TwoLine));
  36. }
  37. private async void btnCalculate_Click(object sender, EventArgs e)
  38. {
  39. if (string.IsNullOrWhiteSpace(txtStartTime.Text))
  40. {
  41. DxHelper.MsgBoxHelper.ShowError("请填写开始时间");
  42. return;
  43. }
  44. int timeout, spanSeconds = 1;
  45. if (txtEndTime.DateTime != txtStartTime.DateTime)
  46. {
  47. if (!string.IsNullOrEmpty(txtEndTime.Text) && !int.TryParse(txtSpanSeconds.Text, out spanSeconds))
  48. {
  49. DxHelper.MsgBoxHelper.ShowError("推算间隔非数字");
  50. return;
  51. }
  52. }
  53. if (!int.TryParse(txtTimeout.Text, out timeout))
  54. {
  55. DxHelper.MsgBoxHelper.ShowError("超时时间非数字");
  56. return;
  57. }
  58. var startTime = Convert.ToDateTime(txtStartTime.EditValue);
  59. var endTime = Convert.ToDateTime(txtEndTime.EditValue);
  60. if (!string.IsNullOrEmpty(txtStartTime.Text) && !string.IsNullOrEmpty(txtEndTime.Text))
  61. {
  62. if (endTime < startTime)
  63. {
  64. DxHelper.MsgBoxHelper.ShowError("开始时间不能大于结束时间");
  65. return;
  66. }
  67. if ((endTime - startTime).TotalHours > 24)
  68. {
  69. DxHelper.MsgBoxHelper.ShowError("开始时间和结束时间不能相差超过24小时");
  70. return;
  71. }
  72. }
  73. if (timeout <= 0) timeout = 30;
  74. listEph.Clear();
  75. try
  76. {
  77. if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text))
  78. {
  79. var XlCalcMultDto = new XlCalcMultDto()
  80. {
  81. tleStr = txtTle.Text,
  82. startTime = startTime,
  83. endTime = endTime,
  84. spanSeconds = spanSeconds,
  85. TimeoutSeconds = timeout
  86. };
  87. var ephRes = await HttpHelper.PostRequestAsync<List<ModelSatEphRes>>(SysConfig.GetUrl("Xl/CalcMult"), XlCalcMultDto, timeout);
  88. if (ephRes.code == 200)
  89. {
  90. listEph.AddRange(ephRes.data);
  91. gridView.RefreshData();
  92. }
  93. else
  94. {
  95. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  96. }
  97. }
  98. else
  99. {
  100. var XlCalcDto = new XlCalcDto()
  101. {
  102. tleStr = txtTle.Text,
  103. SigTime = txtStartTime.DateTime,
  104. TimeoutSeconds = timeout
  105. };
  106. var ephRes = await HttpHelper.PostRequestAsync<ModelSatEphRes>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto, timeout);
  107. if (ephRes.code == 200)
  108. {
  109. listEph.Add(ephRes.data);
  110. gridView.RefreshData();
  111. }
  112. else
  113. {
  114. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  115. }
  116. }
  117. }
  118. catch (TaskCanceledException)
  119. {
  120. Serilog.Log.Warning("星历推算Http接口调用超时");
  121. DxHelper.MsgBoxHelper.ShowInfo("星历推算Http接口调用超时");
  122. }
  123. catch (Exception ex)
  124. {
  125. Serilog.Log.Error(ex, "星历推算异常");
  126. DxHelper.MsgBoxHelper.ShowError("星历推算异常");
  127. }
  128. Console.ReadLine();
  129. }
  130. }
  131. }