XlCalculateForm.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraTreeList.Data;
  3. using ExtensionsDev;
  4. using Newtonsoft.Json;
  5. using PosResAnalysis;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Data.Entity;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Net.Http;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Controls;
  19. using System.Windows.Documents;
  20. using System.Windows.Forms;
  21. using XdCxRhDw.Dto;
  22. using XdCxRhDW.Core;
  23. using XdCxRhDW.Core.Api;
  24. using XdCxRhDW.Repostory;
  25. using XdCxRhDW.Repostory.EFContext;
  26. using XdCxRhDW.Repostory.Model;
  27. namespace XdCxRhDW.App.CorTools
  28. {
  29. public partial class XlCalculateForm : DevExpress.XtraEditors.XtraForm
  30. {
  31. List<string> resXl = new List<string>();
  32. List<SatEphDto> listEph = new List<SatEphDto>();
  33. public XlCalculateForm()
  34. {
  35. InitializeComponent();
  36. }
  37. private async void XlCalculateForm_Load(object sender, EventArgs e)
  38. {
  39. gridControl.Init<SatEphDto>().UseSort().UseFilter().UseMultiSelect().UseRowNumber();
  40. gridControl.DataSource = listEph;
  41. txtTle.UseDoubleClickToSelectAll();
  42. txtTle.UseDefault().SetData(await XlCache.GetAllAsync(), nameof(XlInfo.TwoLine));
  43. }
  44. private async void btnCalculate_Click(object sender, EventArgs e)
  45. {
  46. if (string.IsNullOrWhiteSpace(txtStartTime.Text))
  47. {
  48. DxHelper.MsgBoxHelper.ShowError("请填写开始时间");
  49. return;
  50. }
  51. if (!string.IsNullOrEmpty(txtEndTime.Text) && string.IsNullOrEmpty(txtSpanSeconds.Text))
  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 (!double.TryParse(txtTimeout.Text, out double timeout))
  72. {
  73. DxHelper.MsgBoxHelper.ShowError("超时时间非数字");
  74. return;
  75. }
  76. if (timeout <= 0) timeout = 30;
  77. listEph.Clear();
  78. var settings = new SysSetings();
  79. using (RHDWContext db = new RHDWContext())
  80. {
  81. settings = await db.SysSetings.FirstOrDefaultAsync();
  82. }
  83. using (var client = new HttpClient())
  84. {
  85. try
  86. {
  87. if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text))
  88. {
  89. string url = string.Format("http://{0}:{1}/Api/Xl/CalcMult", IpHelper.GetLocalIp(), settings.HttpPort);
  90. var XlCalcMultDto = new XlCalcMultDto()
  91. {
  92. tleStr = txtTle.Text,
  93. start = startTime,
  94. end = endTime,
  95. spanSeconds = (int)txtSpanSeconds.EditValue,
  96. TimeoutSeconds = (int)timeout
  97. };
  98. var ephRes = await HttpHelper.PostRequestAsync<List<SatEphDto>>(url, XlCalcMultDto, (int)timeout);
  99. if (ephRes.code == 200)
  100. {
  101. listEph.AddRange(ephRes.data);
  102. gridView.RefreshData();
  103. }
  104. }
  105. else
  106. {
  107. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  108. var XlCalcDto = new XlCalcDto()
  109. {
  110. tleStr = txtTle.Text,
  111. dt = Convert.ToDateTime(txtStartTime.EditValue),
  112. TimeoutSeconds = (int)timeout
  113. };
  114. var ephRes = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto, (int)timeout);
  115. if (ephRes.code == 200)
  116. {
  117. listEph.Add(ephRes.data);
  118. gridView.RefreshData();
  119. }
  120. }
  121. }
  122. catch (TaskCanceledException)
  123. {
  124. Serilog.Log.Warning("星历推算Http接口调用超时");
  125. DxHelper.MsgBoxHelper.ShowInfo("星历推算Http接口调用超时");
  126. }
  127. catch (Exception ex)
  128. {
  129. Serilog.Log.Error(ex, "星历推算异常");
  130. DxHelper.MsgBoxHelper.ShowError("星历推算异常");
  131. }
  132. }
  133. Console.ReadLine();
  134. }
  135. }
  136. }