XlCalculateForm.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. string url = string.Format("http://{0}:{1}/Api/Xl/CalcMult", IpHelper.GetLocalIp(), SysConfig.Config.HttpPort);
  80. var XlCalcMultDto = new XlCalcMultDto()
  81. {
  82. tleStr = txtTle.Text,
  83. startTime = startTime,
  84. endTime = endTime,
  85. spanSeconds = spanSeconds,
  86. TimeoutSeconds = timeout
  87. };
  88. var ephRes = await HttpHelper.PostRequestAsync<List<ModelSatEphRes>>(url, XlCalcMultDto, timeout);
  89. if (ephRes.code == 200)
  90. {
  91. listEph.AddRange(ephRes.data);
  92. gridView.RefreshData();
  93. }
  94. else
  95. {
  96. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  97. }
  98. }
  99. else
  100. {
  101. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), SysConfig.Config.HttpPort);
  102. var XlCalcDto = new XlCalcDto()
  103. {
  104. tleStr = txtTle.Text,
  105. SigTime = txtStartTime.DateTime,
  106. TimeoutSeconds = timeout
  107. };
  108. var ephRes = await HttpHelper.PostRequestAsync<ModelSatEphRes>(url, XlCalcDto, timeout);
  109. if (ephRes.code == 200)
  110. {
  111. listEph.Add(ephRes.data);
  112. gridView.RefreshData();
  113. }
  114. else
  115. {
  116. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  117. }
  118. }
  119. }
  120. catch (TaskCanceledException)
  121. {
  122. Serilog.Log.Warning("星历推算Http接口调用超时");
  123. DxHelper.MsgBoxHelper.ShowInfo("星历推算Http接口调用超时");
  124. }
  125. catch (Exception ex)
  126. {
  127. Serilog.Log.Error(ex, "星历推算异常");
  128. DxHelper.MsgBoxHelper.ShowError("星历推算异常");
  129. }
  130. Console.ReadLine();
  131. }
  132. }
  133. }