MainForm.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. btn_ItemClick(null, null);
  47. XlScan();
  48. }
  49. private async void XlScan()
  50. {
  51. await Task.Run(async () =>
  52. {
  53. while (true)
  54. {
  55. await Task.Delay(10000);
  56. using (RHDWContext db = new RHDWContext())
  57. {
  58. var settings = await db.SysSetings.FirstOrDefaultAsync();
  59. if (settings.XLDirectory == null || !Directory.Exists(settings.XLDirectory))
  60. continue;
  61. string[] files = Directory.GetFiles(settings.XLDirectory, "*.txt");
  62. foreach (string file in files)
  63. {
  64. var lines = File.ReadAllLines(file).ToList();
  65. lines.RemoveAll(p => string.IsNullOrWhiteSpace(p));
  66. List<XlInfo> tmp = new List<XlInfo>();
  67. for (int i = 0; i < lines.Count; i += 3)
  68. {
  69. var satName = lines[i].Trim();
  70. if (satName.StartsWith("0 "))
  71. satName = satName.Substring(2).Trim();
  72. if (satName.StartsWith("TBA"))//待发布的卫星
  73. continue;
  74. XlInfo xl = new XlInfo()
  75. {
  76. SatName = satName,
  77. Line1 = lines[i + 1],
  78. Line2 = lines[i + 2],
  79. SatCode = Convert.ToInt32(lines[i + 1].Substring(2, 5))
  80. };
  81. var timeStr = lines[i + 1].Substring(18, 14).Replace(" ", "");//https://www.space-track.org/documentation#tle星历接口中说这里面可以接受空格
  82. var yearStr = timeStr.Substring(0, 2);
  83. var dayStr = timeStr.Substring(2, timeStr.Length - 2);
  84. var day = Convert.ToDouble(dayStr);
  85. var year = 2000 + Convert.ToInt32(yearStr);
  86. DateTime dt = new DateTime(year, 1, 1, 0, 0, 0);
  87. dt = dt.AddDays(day);
  88. xl.TimeBJ = dt.AddHours(8);
  89. tmp.Add(xl);
  90. }
  91. foreach (var item in db.XlInfos)
  92. {
  93. var findItem = tmp.Find(p => p.SatCode == item.SatCode && p.TimeBJ == item.TimeBJ);
  94. if (findItem != null)
  95. {
  96. item.Line1 = findItem.Line1;
  97. item.Line2 = findItem.Line2;
  98. item.UpdateTime = DateTime.Now;
  99. }
  100. tmp.Remove(findItem);
  101. }
  102. db.XlInfos.AddRange(tmp);
  103. await db.SaveChangesAsync();
  104. var baseDirectory = System.IO.Path.GetDirectoryName(file) + "\\XLBackUp";
  105. Directory.CreateDirectory(baseDirectory);
  106. File.Move(file, baseDirectory + "\\" + System.IO.Path.GetFileName(file));//修改名称
  107. }
  108. }
  109. }
  110. });
  111. }
  112. private void btn_ItemClick(object sender, ItemClickEventArgs e)
  113. {
  114. var btnTxt = e?.Item?.Caption ?? "任务管理";
  115. BaseDocument doc = null;
  116. doc = tabbedView1.Documents.Find(p => p.Control.GetType() == ctrlTypes[btnTxt]).FirstOrDefault();
  117. if (doc == null)
  118. {
  119. doc = tabbedView1.AddDocument((Control)Activator.CreateInstance(ctrlTypes[btnTxt]), btnTxt);
  120. if (doc.Control is Form form)
  121. {
  122. form.Text = "";
  123. doc.Caption = btnTxt;
  124. }
  125. if (btnTxt == "任务管理")
  126. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.False;
  127. else
  128. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.True;
  129. }
  130. tabbedView1.ActivateDocument(doc.Control);
  131. }
  132. protected override void OnFormClosing(FormClosingEventArgs e)
  133. {
  134. if (e.CloseReason == CloseReason.UserClosing)
  135. {
  136. if (!DxHelper.MsgBoxHelper.ShowConfirm("确定要退出当前系统吗?"))
  137. {
  138. e.Cancel = true;
  139. return;
  140. }
  141. }
  142. Application.Exit();
  143. }
  144. private async void btnOpenApi_ItemClick(object sender, ItemClickEventArgs e)
  145. {
  146. using (RHDWContext db = new RHDWContext())
  147. {
  148. var settings = await db.SysSetings.FirstOrDefaultAsync();
  149. if (settings == null)
  150. {
  151. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  152. return;
  153. }
  154. if (string.IsNullOrEmpty(settings.ServerIp))
  155. {
  156. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  157. return;
  158. }
  159. if (settings.HttpPort < 1)
  160. {
  161. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  162. return;
  163. }
  164. string addr = $"http://{settings.ServerIp}:{settings.HttpPort}/swagger";
  165. try
  166. {
  167. System.Diagnostics.Process.Start(addr);
  168. }
  169. catch
  170. {
  171. db.Dispose();
  172. DxHelper.MsgBoxHelper.ShowError($"无法打开默认浏览器,请手动查看接口文档.地址{addr}");
  173. }
  174. }
  175. }
  176. }
  177. }