using DevExpress.XtraBars; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraBars.Docking2010.Views; using XdCxRhDW.App.UserControl; using DevExpress.XtraBars.Ribbon; using System.Threading; using XdCxRhDw.CpuCgTools; using DevExpress.XtraEditors; using ExtensionsDev; using DevExpress.XtraBars.Forms; using XdCxRhDW.App.CorTools; using XdCxRhDW.Repostory.EFContext; using System.Data.Entity; using System.IO; using XdCxRhDW.Repostory.Model; using System.Windows.Shapes; using XdCxRhDW.Core; namespace XdCxRhDW { public partial class MainForm : DevExpress.XtraBars.Ribbon.RibbonForm { Dictionary ctrlTypes = new Dictionary(); public MainForm() { InitializeComponent(); ribbon.UseDefault(); tabbedView1.UseDefault(); ctrlTypes.Add("任务管理", typeof(CtrlHome)); ctrlTypes.Add("参估结果", typeof(CtrlCgRes)); ctrlTypes.Add("测向结果", typeof(CtrlCxRes)); ctrlTypes.Add("定位结果", typeof(CtrlPosRes)); ctrlTypes.Add("星历管理", typeof(CtrlXl)); ctrlTypes.Add("卫星管理", typeof(CtrlSat)); ctrlTypes.Add("天线管理", typeof(CtrlTx)); ctrlTypes.Add("目标管理", typeof(CtrlTarget)); ctrlTypes.Add("系统设置", typeof(CtrlSysSettings)); //ctrlTypes.Add("参估工具", typeof(CorToolForm)); ctrlTypes.Add("检测参估工具", typeof(DetectToolForm)); ctrlTypes.Add("星历推算", typeof(XlCalculateForm)); btn_ItemClick(null, null); XlScan(); } private async void XlScan() { await Task.Run(async () => { while (true) { await Task.Delay(10000); using (RHDWContext db = new RHDWContext()) { var settings = await db.SysSetings.FirstOrDefaultAsync(); if (settings==null||settings.XLDirectory == null || !Directory.Exists(settings.XLDirectory)) continue; string[] files = Directory.GetFiles(settings.XLDirectory, "*.txt"); foreach (string file in files) { var lines = File.ReadAllLines(file).ToList(); lines.RemoveAll(p => string.IsNullOrWhiteSpace(p)); List tmp = new List(); for (int i = 0; i < lines.Count; i += 3) { var satName = lines[i].Trim(); if (satName.StartsWith("0 ")) satName = satName.Substring(2).Trim(); if (satName.StartsWith("TBA"))//待发布的卫星 continue; XlInfo xl = new XlInfo() { SatName = satName, Line1 = lines[i + 1], Line2 = lines[i + 2], SatCode = Convert.ToInt32(lines[i + 1].Substring(2, 5)) }; var timeStr = lines[i + 1].Substring(18, 14).Replace(" ", "");//https://www.space-track.org/documentation#tle星历接口中说这里面可以接受空格 var yearStr = timeStr.Substring(0, 2); var dayStr = timeStr.Substring(2, timeStr.Length - 2); var day = Convert.ToDouble(dayStr); var year = 2000 + Convert.ToInt32(yearStr); DateTime dt = new DateTime(year, 1, 1, 0, 0, 0); dt = dt.AddDays(day); xl.TimeBJ = dt.AddHours(8); tmp.Add(xl); } foreach (var item in db.XlInfos) { var findItem = tmp.Find(p => p.SatCode == item.SatCode && p.TimeBJ == item.TimeBJ); if (findItem != null) { item.Line1 = findItem.Line1; item.Line2 = findItem.Line2; item.UpdateTime = DateTime.Now; } tmp.Remove(findItem); } db.XlInfos.AddRange(tmp); await db.SaveChangesAsync(); var baseDirectory = System.IO.Path.GetDirectoryName(file) + "\\XLBackUp"; Directory.CreateDirectory(baseDirectory); File.Move(file, baseDirectory + "\\" + System.IO.Path.GetFileName(file));//修改名称 } } } }); } private void btn_ItemClick(object sender, ItemClickEventArgs e) { var btnTxt = e?.Item?.Caption ?? "任务管理"; BaseDocument doc = null; doc = tabbedView1.Documents.Find(p => p.Control.GetType() == ctrlTypes[btnTxt]).FirstOrDefault(); if (doc == null) { doc = tabbedView1.AddDocument((Control)Activator.CreateInstance(ctrlTypes[btnTxt]), btnTxt); if (doc.Control is Form form) { form.Text = ""; doc.Caption = btnTxt; } if (btnTxt == "任务管理") doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.False; else doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.True; } tabbedView1.ActivateDocument(doc.Control); } protected override void OnFormClosing(FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (!DxHelper.MsgBoxHelper.ShowConfirm("确定要退出当前系统吗?")) { e.Cancel = true; return; } } Application.Exit(); } private async void btnOpenApi_ItemClick(object sender, ItemClickEventArgs e) { using (RHDWContext db = new RHDWContext()) { var settings = await db.SysSetings.FirstOrDefaultAsync(); if (settings == null) { DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口"); return; } if (settings.HttpPort < 1) { DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置Http端口"); return; } string addr = $"http://{IpHelper.GetLocalIp()}:{settings.HttpPort}/swagger"; try { System.Diagnostics.Process.Start(addr); } catch { db.Dispose(); DxHelper.MsgBoxHelper.ShowError($"无法打开默认浏览器,请手动查看接口文档.地址{addr}"); } } } } }