XlCalculateForm.cs 5.2 KB

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