MainForm.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using DevExpress.XtraBars;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using DevExpress.XtraBars.Docking2010.Views;
  12. using XdCxRhDW.App.UserControl;
  13. using DevExpress.XtraBars.Ribbon;
  14. using System.Threading;
  15. using XdCxRhDw.CpuCgTools;
  16. using DevExpress.XtraEditors;
  17. using ExtensionsDev;
  18. using DevExpress.XtraBars.Forms;
  19. using XdCxRhDW.App.CorTools;
  20. using XdCxRhDW.App.EFContext;
  21. using System.Data.Entity;
  22. using System.IO;
  23. using XdCxRhDW.App.Model;
  24. using System.Windows.Shapes;
  25. namespace XdCxRhDW
  26. {
  27. public partial class MainForm : DevExpress.XtraBars.Ribbon.RibbonForm
  28. {
  29. Dictionary<string, Type> ctrlTypes = new Dictionary<string, Type>();
  30. public MainForm()
  31. {
  32. InitializeComponent();
  33. ribbon.UseDefault();
  34. tabbedView1.UseDefault();
  35. ctrlTypes.Add("任务管理", typeof(CtrlHome));
  36. ctrlTypes.Add("参估结果", typeof(CtrlCgRes));
  37. ctrlTypes.Add("测向结果", typeof(CtrlCxRes));
  38. ctrlTypes.Add("定位结果", typeof(CtrlPosRes));
  39. ctrlTypes.Add("星历管理", typeof(CtrlXl));
  40. ctrlTypes.Add("卫星管理", typeof(CtrlSat));
  41. ctrlTypes.Add("天线管理", typeof(CtrlTx));
  42. ctrlTypes.Add("目标管理", typeof(CtrlTarget));
  43. ctrlTypes.Add("系统设置", typeof(CtrlSysSettings));
  44. ctrlTypes.Add("参估工具", typeof(CorToolForm));
  45. ctrlTypes.Add("检测工具", typeof(DetectToolForm));
  46. ctrlTypes.Add("星历推算", typeof(CtrlXlCalculate));
  47. btn_ItemClick(null, null);
  48. XlScan();
  49. }
  50. private async void XlScan()
  51. {
  52. await Task.Run(async () =>
  53. {
  54. while (true)
  55. {
  56. await Task.Delay(10000);
  57. using (RHDWContext db = new RHDWContext())
  58. {
  59. var settings = await db.SysSetings.FirstOrDefaultAsync();
  60. if (settings.XLDirectory == null || !Directory.Exists(settings.XLDirectory))
  61. continue;
  62. string[] files = Directory.GetFiles(settings.XLDirectory, "*.txt");
  63. foreach (string file in files)
  64. {
  65. var lines = File.ReadAllLines(file).ToList();
  66. lines.RemoveAll(p => string.IsNullOrWhiteSpace(p));
  67. List<XlInfo> tmp = new List<XlInfo>();
  68. for (int i = 0; i < lines.Count; i += 3)
  69. {
  70. var satName = lines[i].Trim();
  71. if (satName.StartsWith("0 "))
  72. satName = satName.Substring(2).Trim();
  73. if (satName.StartsWith("TBA"))//待发布的卫星
  74. continue;
  75. XlInfo xl = new XlInfo()
  76. {
  77. SatName = satName,
  78. Line1 = lines[i + 1],
  79. Line2 = lines[i + 2],
  80. SatCode = Convert.ToInt32(lines[i + 1].Substring(2, 5))
  81. };
  82. var timeStr = lines[i + 1].Substring(18, 14).Replace(" ", "");//https://www.space-track.org/documentation#tle星历接口中说这里面可以接受空格
  83. var yearStr = timeStr.Substring(0, 2);
  84. var dayStr = timeStr.Substring(2, timeStr.Length - 2);
  85. var day = Convert.ToDouble(dayStr);
  86. var year = 2000 + Convert.ToInt32(yearStr);
  87. DateTime dt = new DateTime(year, 1, 1, 0, 0, 0);
  88. dt = dt.AddDays(day);
  89. xl.TimeBJ = dt.AddHours(8);
  90. tmp.Add(xl);
  91. }
  92. foreach (var item in db.XlInfos)
  93. {
  94. var findItem = tmp.Find(p => p.SatCode == item.SatCode && p.TimeBJ == item.TimeBJ);
  95. if (findItem != null)
  96. {
  97. item.Line1 = findItem.Line1;
  98. item.Line2 = findItem.Line2;
  99. item.UpdateTime = DateTime.Now;
  100. }
  101. tmp.Remove(findItem);
  102. }
  103. db.XlInfos.AddRange(tmp);
  104. await db.SaveChangesAsync();
  105. var baseDirectory = System.IO.Path.GetDirectoryName(file) + "\\XLBackUp";
  106. Directory.CreateDirectory(baseDirectory);
  107. File.Move(file, baseDirectory + "\\" + System.IO.Path.GetFileName(file));//修改名称
  108. }
  109. }
  110. }
  111. });
  112. }
  113. private void btn_ItemClick(object sender, ItemClickEventArgs e)
  114. {
  115. var btnTxt = e?.Item?.Caption ?? "任务管理";
  116. BaseDocument doc = null;
  117. doc = tabbedView1.Documents.Find(p => p.Control.GetType() == ctrlTypes[btnTxt]).FirstOrDefault();
  118. if (doc == null)
  119. {
  120. doc = tabbedView1.AddDocument((Control)Activator.CreateInstance(ctrlTypes[btnTxt]), btnTxt);
  121. if (doc.Control is Form form)
  122. {
  123. form.Text = "";
  124. doc.Caption = btnTxt;
  125. }
  126. if (btnTxt == "任务管理")
  127. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.False;
  128. else
  129. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.True;
  130. }
  131. tabbedView1.ActivateDocument(doc.Control);
  132. }
  133. protected override void OnFormClosing(FormClosingEventArgs e)
  134. {
  135. if (e.CloseReason == CloseReason.UserClosing)
  136. {
  137. if (!DxHelper.MsgBoxHelper.ShowConfirm("确定要退出当前系统吗?"))
  138. {
  139. e.Cancel = true;
  140. return;
  141. }
  142. }
  143. Application.Exit();
  144. }
  145. private async void btnOpenApi_ItemClick(object sender, ItemClickEventArgs e)
  146. {
  147. using (RHDWContext db = new RHDWContext())
  148. {
  149. var settings = await db.SysSetings.FirstOrDefaultAsync();
  150. if (settings == null)
  151. {
  152. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  153. return;
  154. }
  155. if (string.IsNullOrEmpty(settings.ServerIp))
  156. {
  157. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  158. return;
  159. }
  160. if (settings.HttpPort < 1)
  161. {
  162. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  163. return;
  164. }
  165. string addr = $"http://{settings.ServerIp}:{settings.HttpPort}/swagger";
  166. try
  167. {
  168. System.Diagnostics.Process.Start(addr);
  169. }
  170. catch
  171. {
  172. db.Dispose();
  173. DxHelper.MsgBoxHelper.ShowError($"无法打开默认浏览器,请手动查看接口文档.地址{addr}");
  174. }
  175. }
  176. }
  177. }
  178. }