XlCalculateForm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.EFContext;
  25. using XdCxRhDW.Repostory.Model;
  26. namespace XdCxRhDW.App.CorTools
  27. {
  28. public partial class XlCalculateForm : DevExpress.XtraEditors.XtraForm
  29. {
  30. List<string> resXl = new List<string>();
  31. List<SatEphDto> listEph = new List<SatEphDto>();
  32. public XlCalculateForm()
  33. {
  34. InitializeComponent();
  35. }
  36. private async void XlCalculateForm_Load(object sender, EventArgs e)
  37. {
  38. gridControl.Init<SatEphDto>().UseSort().UseFilter().UseMultiSelect().UseRowNumber();
  39. gridControl.DataSource = listEph;
  40. txtTle.UseDoubleClickToSelectAll();
  41. var listXl =await XlCache.GetAllAsync();
  42. txtTle.UseDefault().SetStringData(listXl.Select(p=>p.TwoLine));
  43. }
  44. private async void btnCalculate_Click(object sender, EventArgs e)
  45. {
  46. if (!string.IsNullOrEmpty(txtEndTime.Text) && string.IsNullOrEmpty(txtSpanSeconds.Text))
  47. {
  48. DxHelper.MsgBoxHelper.ShowInfo("请填写推算间隔");
  49. return;
  50. }
  51. var startTime = Convert.ToDateTime(txtStartTime.EditValue);
  52. var endTime = Convert.ToDateTime(txtEndTime.EditValue);
  53. if (!string.IsNullOrEmpty(txtStartTime.Text) && !string.IsNullOrEmpty(txtEndTime.Text))
  54. {
  55. if (endTime < startTime)
  56. {
  57. DxHelper.MsgBoxHelper.ShowInfo("结束时间不能大于开始时间");
  58. return;
  59. }
  60. if ((endTime - startTime).TotalHours > 24)
  61. {
  62. DxHelper.MsgBoxHelper.ShowInfo("开始时间和结束时间不能相差超过24小时");
  63. return;
  64. }
  65. }
  66. listEph.Clear();
  67. var settings = new SysSetings();
  68. using (RHDWContext db = new RHDWContext())
  69. {
  70. settings = await db.SysSetings.FirstOrDefaultAsync();
  71. }
  72. using (var client = new HttpClient())
  73. {
  74. try
  75. {
  76. if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text))
  77. {
  78. string url = string.Format("http://{0}:{1}/Api/Xl/CalcMult", IpHelper.GetLocalIp(), settings.HttpPort);
  79. var XlCalcMultDto = new XlCalcMultDto() { tleStr = txtTle.Text, start = startTime, end = endTime, spanSeconds = (int)txtSpanSeconds.EditValue };
  80. var ephRes = await HttpHelper.PostRequestAsync<List<SatEphDto>>(url, XlCalcMultDto);
  81. if (ephRes.code == 200)
  82. {
  83. listEph.AddRange(ephRes.data);
  84. gridView.RefreshData();
  85. }
  86. }
  87. else
  88. {
  89. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  90. var XlCalcDto = new XlCalcDto() { tleStr = txtTle.Text, dt = Convert.ToDateTime(txtStartTime.EditValue) };
  91. var ephRes = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto);
  92. if (ephRes.code == 200)
  93. {
  94. listEph.Add(ephRes.data);
  95. gridView.RefreshData();
  96. }
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. Serilog.Log.Error(ex, "请求星历推算Api出错");
  102. DxHelper.MsgBoxHelper.ShowError("星历推算错误");
  103. }
  104. }
  105. Console.ReadLine();
  106. }
  107. }
  108. }