XlCalculateForm.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. txtTle.UseDoubleClickToSelectAll();
  33. txtTle.UseDefault().SetData(await XlRepository.GetAllAsync(), nameof(XlInfo.TwoLine));
  34. }
  35. private async void btnCalculate_Click(object sender, EventArgs e)
  36. {
  37. if (string.IsNullOrWhiteSpace(txtStartTime.Text))
  38. {
  39. DxHelper.MsgBoxHelper.ShowError("请填写开始时间");
  40. return;
  41. }
  42. int timeout, spanSeconds = 1;
  43. if (txtEndTime.DateTime != txtStartTime.DateTime)
  44. {
  45. if (!string.IsNullOrEmpty(txtEndTime.Text) && !int.TryParse(txtSpanSeconds.Text, out spanSeconds))
  46. {
  47. DxHelper.MsgBoxHelper.ShowError("推算间隔非数字");
  48. return;
  49. }
  50. }
  51. if (!int.TryParse(txtTimeout.Text, out timeout))
  52. {
  53. DxHelper.MsgBoxHelper.ShowError("超时时间非数字");
  54. return;
  55. }
  56. var startTime = Convert.ToDateTime(txtStartTime.EditValue);
  57. var endTime = Convert.ToDateTime(txtEndTime.EditValue);
  58. if (!string.IsNullOrEmpty(txtStartTime.Text) && !string.IsNullOrEmpty(txtEndTime.Text))
  59. {
  60. if (endTime < startTime)
  61. {
  62. DxHelper.MsgBoxHelper.ShowError("开始时间不能大于结束时间");
  63. return;
  64. }
  65. if ((endTime - startTime).TotalHours > 24)
  66. {
  67. DxHelper.MsgBoxHelper.ShowError("开始时间和结束时间不能相差超过24小时");
  68. return;
  69. }
  70. }
  71. if (timeout <= 0) timeout = 30;
  72. listEph.Clear();
  73. var settings = new SysSetings();
  74. using (RHDWContext db = new RHDWContext())
  75. {
  76. settings = await db.SysSetings.FirstOrDefaultAsync();
  77. }
  78. try
  79. {
  80. if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text))
  81. {
  82. string url = string.Format("http://{0}:{1}/Api/Xl/CalcMult", IpHelper.GetLocalIp(), settings.HttpPort);
  83. var XlCalcMultDto = new XlCalcMultDto()
  84. {
  85. tleStr = txtTle.Text,
  86. start = startTime,
  87. end = endTime,
  88. spanSeconds = spanSeconds,
  89. TimeoutSeconds = timeout
  90. };
  91. var ephRes = await HttpHelper.PostRequestAsync<List<ModelSatEphRes>>(url, XlCalcMultDto, timeout);
  92. if (ephRes.code == 200)
  93. {
  94. listEph.AddRange(ephRes.data);
  95. gridView.RefreshData();
  96. }
  97. else
  98. {
  99. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  100. }
  101. }
  102. else
  103. {
  104. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  105. var XlCalcDto = new XlCalcDto()
  106. {
  107. tleStr = txtTle.Text,
  108. dt = txtStartTime.DateTime,
  109. TimeoutSeconds = timeout
  110. };
  111. var ephRes = await HttpHelper.PostRequestAsync<ModelSatEphRes>(url, XlCalcDto, timeout);
  112. if (ephRes.code == 200)
  113. {
  114. listEph.Add(ephRes.data);
  115. gridView.RefreshData();
  116. }
  117. else
  118. {
  119. DxHelper.MsgBoxHelper.ShowError(ephRes.msg);
  120. }
  121. }
  122. }
  123. catch (TaskCanceledException)
  124. {
  125. Serilog.Log.Warning("星历推算Http接口调用超时");
  126. DxHelper.MsgBoxHelper.ShowInfo("星历推算Http接口调用超时");
  127. }
  128. catch (Exception ex)
  129. {
  130. Serilog.Log.Error(ex, "星历推算异常");
  131. DxHelper.MsgBoxHelper.ShowError("星历推算异常");
  132. }
  133. Console.ReadLine();
  134. }
  135. }
  136. }