XlCalculateForm.cs 4.5 KB

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