using DevExpress.XtraEditors; using DevExpress.XtraTreeList.Data; using ExtensionsDev; using PosResAnalysis; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using XdCxRhDw.Dto; using XdCxRhDW.App.Model; using XdCxRhDW.Dto; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.CorTools { public partial class XlCalculateForm : DevExpress.XtraEditors.XtraForm { List resXl = new List(); List listEph = new List(); public XlCalculateForm() { InitializeComponent(); } private async void XlCalculateForm_Load(object sender, EventArgs e) { gridControl.Init().UseSort().UseFilter().UseMultiSelect().UseRowNumber().DataSource = listEph; txtTle.UseDoubleClickToSelectAll(); txtTle.UseDefault().SetData(await XlRepository.GetAllAsync(), nameof(XlInfo.TwoLine)); } private async void btnCalculate_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtStartTime.Text)) { DxHelper.MsgBoxHelper.ShowError("请填写开始时间"); return; } if (!string.IsNullOrEmpty(txtEndTime.Text) && string.IsNullOrEmpty(txtSpanSeconds.Text)) { DxHelper.MsgBoxHelper.ShowError("请填写推算间隔"); return; } var startTime = Convert.ToDateTime(txtStartTime.EditValue); var endTime = Convert.ToDateTime(txtEndTime.EditValue); if (!string.IsNullOrEmpty(txtStartTime.Text) && !string.IsNullOrEmpty(txtEndTime.Text)) { if (endTime < startTime) { DxHelper.MsgBoxHelper.ShowError("开始时间不能大于结束时间"); return; } if ((endTime - startTime).TotalHours > 24) { DxHelper.MsgBoxHelper.ShowError("开始时间和结束时间不能相差超过24小时"); return; } } if (!double.TryParse(txtTimeout.Text, out double timeout)) { DxHelper.MsgBoxHelper.ShowError("超时时间非数字"); return; } if (timeout <= 0) timeout = 30; listEph.Clear(); var settings = new SysSetings(); using (RHDWContext db = new RHDWContext()) { settings = await db.SysSetings.FirstOrDefaultAsync(); } try { if (!string.IsNullOrEmpty(txtEndTime.Text) && !string.IsNullOrEmpty(txtSpanSeconds.Text)) { string url = string.Format("http://{0}:{1}/Api/Xl/CalcMult", IpHelper.GetLocalIp(), settings.HttpPort); var XlCalcMultDto = new XlCalcMultDto() { tleStr = txtTle.Text, start = startTime, end = endTime, spanSeconds = (int)txtSpanSeconds.EditValue, TimeoutSeconds = (int)timeout }; var ephRes = await HttpHelper.PostRequestAsync>(url, XlCalcMultDto, (int)timeout); if (ephRes.code == 200) { listEph.AddRange(ephRes.data); gridView.RefreshData(); } } else { string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort); var XlCalcDto = new XlCalcDto() { tleStr = txtTle.Text, dt = Convert.ToDateTime(txtStartTime.EditValue), TimeoutSeconds = (int)timeout }; var ephRes = await HttpHelper.PostRequestAsync(url, XlCalcDto, (int)timeout); if (ephRes.code == 200) { listEph.Add(ephRes.data); gridView.RefreshData(); } } } catch (TaskCanceledException) { Serilog.Log.Warning("星历推算Http接口调用超时"); DxHelper.MsgBoxHelper.ShowInfo("星历推算Http接口调用超时"); } catch (Exception ex) { Serilog.Log.Error(ex, "星历推算异常"); DxHelper.MsgBoxHelper.ShowError("星历推算异常"); } Console.ReadLine(); } } }