EphCalcForm.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using DevExpress.Xpo;
  2. using DevExpress.XtraEditors;
  3. using Ips.Library.Basic;
  4. using Ips.Library.DxpLib;
  5. using Ips.Library.Entity;
  6. using Ips.Sps.Sats;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Ips.Sps.Ephs
  17. {
  18. public partial class EphCalcForm : DevExpress.XtraEditors.XtraForm
  19. {
  20. public EphCalcForm()
  21. {
  22. InitializeComponent();
  23. txtTime.UseTimeEdit();
  24. txtEphType.Properties.Items.AddEnum<EphType>();
  25. _session = new Session();
  26. }
  27. Session _session;
  28. List<Sat> _satList;
  29. BindingList<EphResult> ephList = new BindingList<EphResult>();
  30. private void EphCalcForm_Load(object sender, EventArgs e)
  31. {
  32. _satList = _session.Query<Sat>().Where(m => m.Enable).OrderBy(m => m.Lon).ToList();
  33. colSatNumEdit.DataSource = _satList;
  34. txtSatNum.Properties.Items.AddRange(_satList);
  35. bsEphResultList.DataSource = ephList;
  36. }
  37. private async void btnCalc_Click(object sender, EventArgs e)
  38. {
  39. if (txtTime.DateTime == DateTime.MinValue)
  40. {
  41. MsgHelper.ShowError("请输入时间");
  42. return;
  43. }
  44. int satNum;
  45. var sat = txtSatNum.EditValue as Sat;
  46. if (sat != null)
  47. {
  48. satNum = sat.SatNum;
  49. }
  50. else if (!int.TryParse(txtSatNum.Text.Trim(), out satNum))
  51. {
  52. MsgHelper.ShowError("卫星编号格式不正确!");
  53. return;
  54. }
  55. btnCalc.Enabled = false;
  56. try
  57. {
  58. var time = txtTime.DateTime;
  59. EphResult result = null;
  60. if (txtEphType.EditValue == null)
  61. {
  62. result = await Task.Run(() => EphManager.Default.GetEph(satNum, time));
  63. }
  64. else
  65. {
  66. var ephType = (EphType)txtEphType.EditValue;
  67. if (ephType == EphType.Tle)
  68. {
  69. result = await Task.Run(() => EphManager.Default.GetEphTle(satNum, time));
  70. }
  71. else if (ephType == EphType.High)
  72. {
  73. result = await Task.Run(() => EphManager.Default.GetEphHigh(satNum, time));
  74. }
  75. }
  76. if (result == null)
  77. {
  78. MsgHelper.ShowWarn("计算结果为空!");
  79. }
  80. else
  81. {
  82. ephList.Add(result);
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. MsgHelper.ShowError("计算星历出错,错误消息:" + ex.Message);
  88. }
  89. finally
  90. {
  91. btnCalc.Enabled = true;
  92. }
  93. }
  94. private void btnClear_Click(object sender, EventArgs e)
  95. {
  96. ephList.Clear();
  97. }
  98. private void txtSatNum_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
  99. {
  100. //var sat = e.Value as Sat;
  101. //if (sat != null)
  102. //{
  103. // e.DisplayText = sat.SatNum.ToString();
  104. //}
  105. }
  106. private void gvEphResult_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
  107. {
  108. if (e.Column == colSatNum && e.DisplayText.IsNullOrWhitespace())
  109. {
  110. e.DisplayText = e.Value?.ToString();
  111. }
  112. }
  113. }
  114. }