XlCalculateForm.cs 4.9 KB

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