XlCalculateForm.cs 4.4 KB

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