XlCalculateForm.cs 5.3 KB

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