MainForm.cs 7.7 KB

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