MainForm.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. using (RHDWContext db = new RHDWContext())
  52. {
  53. var settings = await db.SysSetings.FirstOrDefaultAsync();
  54. if (settings.XLDirectory == null || !Directory.Exists(settings.XLDirectory))
  55. return;
  56. string line = null;
  57. await Task.Run(async () =>
  58. {
  59. while (true)
  60. {
  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. line = lines[i];
  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. Thread.Sleep(10000);
  110. }
  111. });
  112. }
  113. }
  114. private void btn_ItemClick(object sender, ItemClickEventArgs e)
  115. {
  116. var btnTxt = e?.Item?.Caption ?? "任务管理";
  117. BaseDocument doc = null;
  118. doc = tabbedView1.Documents.Find(p => p.Control.GetType() == ctrlTypes[btnTxt]).FirstOrDefault();
  119. if (doc == null)
  120. {
  121. doc = tabbedView1.AddDocument((Control)Activator.CreateInstance(ctrlTypes[btnTxt]), btnTxt);
  122. if (doc.Control is Form form)
  123. {
  124. form.Text = "";
  125. doc.Caption = btnTxt;
  126. }
  127. if (btnTxt == "任务管理")
  128. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.False;
  129. else
  130. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.True;
  131. }
  132. tabbedView1.ActivateDocument(doc.Control);
  133. }
  134. protected override void OnFormClosing(FormClosingEventArgs e)
  135. {
  136. if (e.CloseReason == CloseReason.UserClosing)
  137. {
  138. if (!DxHelper.MsgBoxHelper.ShowConfirm("确定要退出当前系统吗?"))
  139. {
  140. e.Cancel = true;
  141. return;
  142. }
  143. }
  144. Application.Exit();
  145. }
  146. private async void btnOpenApi_ItemClick(object sender, ItemClickEventArgs e)
  147. {
  148. using (RHDWContext db = new RHDWContext())
  149. {
  150. var settings = await db.SysSetings.FirstOrDefaultAsync();
  151. if (settings == null)
  152. {
  153. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  154. return;
  155. }
  156. if (string.IsNullOrEmpty(settings.ServerIp))
  157. {
  158. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  159. return;
  160. }
  161. if (settings.HttpPort < 1)
  162. {
  163. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  164. return;
  165. }
  166. string addr = $"http://{settings.ServerIp}:{settings.HttpPort}/swagger";
  167. try
  168. {
  169. System.Diagnostics.Process.Start(addr);
  170. }
  171. catch
  172. {
  173. db.Dispose();
  174. DxHelper.MsgBoxHelper.ShowError($"无法打开默认浏览器,请手动查看接口文档.地址{addr}");
  175. }
  176. }
  177. }
  178. }
  179. }