CtrlHome.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. using DevExpress.Utils;
  2. using DevExpress.Utils.Drawing;
  3. using DevExpress.Utils.Svg;
  4. using DevExpress.XtraEditors.ButtonsPanelControl;
  5. using DevExpress.XtraGrid.Views.Grid;
  6. using DxHelper;
  7. using Microsoft.Owin.Hosting;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel.DataAnnotations;
  11. using System.Data;
  12. using System.Data.Entity;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Net;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Windows.Forms;
  19. using XdCxRhDW.App.Api;
  20. using XdCxRhDW.App.EditForms;
  21. using XdCxRhDW.Repostory.Model;
  22. using XdCxRhDW.Repostory.EFContext;
  23. using XdCxRhDW.WebApi;
  24. using XdCxRhDW.Core.ObServer;
  25. using ExtensionsDev;
  26. using DevExpress.XtraEditors;
  27. using System.Data.Entity.Migrations;
  28. using System.Threading;
  29. using System.Threading.Tasks;
  30. using System.IO;
  31. using XdCxRhDW.App.PopupControl;
  32. namespace XdCxRhDW.App.UserControl
  33. {
  34. public partial class CtrlHome : DevExpress.XtraEditors.XtraUserControl
  35. {
  36. List<TaskInfo> list = new List<TaskInfo>();
  37. TaskInfo tsk = new TaskInfo();
  38. List<CancellationTokenSource> listCts = new List<CancellationTokenSource>();
  39. public CtrlHome()
  40. {
  41. InitializeComponent();
  42. gridHomeTask.Init<TaskInfo>().UseFilter();
  43. gridHomePosRes.Init<PosRes>().UseMultiSelect().UseRowNumber().UseFilter();
  44. layoutControl1.UseDefault();
  45. txtStartTime.UseDefault();
  46. txtEndTime.UseDefault();
  47. btnDrawDto.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\DtoLine.svg");
  48. btnDrawDfo.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\DfoLine.svg");
  49. btnGDOP.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\GDOP.svg");
  50. var mapService = string.Empty;//http://ows.mundialis.de/services/service
  51. using (RHDWContext db = new RHDWContext())
  52. {
  53. mapService = db.SysSetings.FirstOrDefault()?.MapService;
  54. }
  55. mapControl1.UseDefalutOptions()
  56. //.UseCluster()//定位点使用内置聚合
  57. .UseClearAll()
  58. .UseDistanceLine()
  59. .UseMarkDot()
  60. .UseExportImg()
  61. .UseExportXlsx()
  62. .UseExportCsv()
  63. .SetMapLayerType(mapService)
  64. //.SetMapLayerType("")
  65. //.UseHJ(item =>
  66. //{
  67. // (double Lon, double Lat) = item;
  68. // PosRes pos = new PosRes();
  69. // pos.PosLon = Lon;
  70. // pos.PosLat = Lat;
  71. // pos.SigTime = DateTime.Now;
  72. // mapControl1.AddHJPosItem(pos);
  73. //})
  74. .UseDrawRect(rect =>
  75. {
  76. (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
  77. });
  78. PosObServer.Instance.Sub(PosSubEvent);
  79. }
  80. private void PosSubEvent(PosRes posRes)
  81. {
  82. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  83. if (currentTask.ID == posRes.TaskInfoID)
  84. {
  85. var ds = this.gridHomePosRes.DataSource as List<PosRes>;
  86. ds.Insert(0, posRes);
  87. this.Invoke(new Action(() =>
  88. {
  89. gridView2.RefreshData();
  90. mapControl1.AddPosItem(posRes);
  91. }));
  92. }
  93. }
  94. private async void CtrlHome_Load(object sender, EventArgs e)
  95. {
  96. gridView1.FocusedRowObjectChanged += GridView1_FocusedRowObjectChanged;
  97. gridView2.FocusedRowObjectChanged += GridView2_FocusedRowObjectChanged;
  98. try
  99. {
  100. List<TxInfo> txList = new List<TxInfo>();
  101. using (RHDWContext db = new RHDWContext())
  102. {
  103. var qq = db.TaskInfos.OrderByDescending(p => p.UpdateTime).ToList();
  104. list.AddRange(qq);
  105. var runningList = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running).ToListAsync();
  106. foreach (var item in runningList)
  107. {
  108. item.TaskState = EnumTaskState.Stopped;
  109. }
  110. await db.SaveChangesAsync();
  111. var satres = db.SatInfos.OrderBy(p => p.SatName).OrderBy(p => p.SatName);
  112. var txres = await db.TxInfos.ToListAsync();
  113. txList.AddRange(txres);
  114. }
  115. mapControl1.AddRectMenu<PosRes>("删除定位点", SvgHelper.CreateClose(), items =>
  116. {
  117. DeletePosRes(items.ToList());
  118. });
  119. mapControl1.AddRectMenu<PosRes>("使用镜像点", SvgHelper.LoadFromFile("Image\\Pos.svg"), items =>
  120. {
  121. UseMirr(items.ToList());
  122. });
  123. mapControl1.AddRectMenu<PosRes>("编辑目标", SvgHelper.LoadFromFile("Image\\Edit.svg"), items =>
  124. {
  125. EditTarget(items.ToList());
  126. });
  127. mapControl1.AddRectMenu<PosRes>("转到列表", SvgHelper.LoadFromFile("Image\\To.svg"), items =>
  128. {
  129. ToPosList(items.ToList());
  130. });
  131. mapControl1.AddPosMenu<PosRes>("绘制时差线", SvgHelper.LoadFromFile("Image\\DtoLine.svg"), item =>
  132. {
  133. DrawDtoLine(item);
  134. }, p =>
  135. {
  136. switch (p.PosResType)
  137. {
  138. case EnumPosResType.X3TwoDfo:
  139. case EnumPosResType.RH:
  140. default:
  141. return false;
  142. case EnumPosResType.X1D1CX:
  143. case EnumPosResType.X2D1:
  144. case EnumPosResType.X2D1NoRef:
  145. case EnumPosResType.X3:
  146. case EnumPosResType.X3NoRef:
  147. case EnumPosResType.X2Dfo:
  148. return true;
  149. }
  150. })
  151. .AddPosMenu<PosRes>("绘制频差线", SvgHelper.LoadFromFile("Image\\DfoLine.svg"), item =>
  152. {
  153. DrawDfoLine(item);
  154. }, p =>
  155. {
  156. switch (p.PosResType)
  157. {
  158. case EnumPosResType.X3TwoDfo:
  159. case EnumPosResType.X2Dfo:
  160. return true;
  161. case EnumPosResType.X2D1:
  162. case EnumPosResType.X2D1NoRef:
  163. case EnumPosResType.RH:
  164. case EnumPosResType.X3:
  165. case EnumPosResType.X3NoRef:
  166. case EnumPosResType.X1D1CX:
  167. default:
  168. return false;
  169. }
  170. })
  171. .AddPosMenu<PosRes>("绘制GDOP", SvgHelper.LoadFromFile("Image\\GDOP.svg"), item =>
  172. {
  173. DrawGDOP(item);
  174. }, p =>
  175. {
  176. switch (p.PosResType)
  177. {
  178. case EnumPosResType.X3TwoDfo:
  179. case EnumPosResType.X2Dfo:
  180. case EnumPosResType.X2D1:
  181. case EnumPosResType.X2D1NoRef:
  182. case EnumPosResType.X3:
  183. case EnumPosResType.X3NoRef:
  184. case EnumPosResType.X1D1CX:
  185. return true;
  186. case EnumPosResType.RH:
  187. default:
  188. return false;
  189. }
  190. })
  191. .AddPosMenu<PosRes>("绘制测向线", btnDrawCX.ImageOptions.SvgImage, item =>
  192. {
  193. DrawCXLine(item);
  194. }, p =>
  195. {
  196. switch (p.PosResType)
  197. {
  198. case EnumPosResType.X1D1CX:
  199. return true;
  200. case EnumPosResType.RH:
  201. case EnumPosResType.X3TwoDfo:
  202. case EnumPosResType.X2Dfo:
  203. case EnumPosResType.X2D1:
  204. case EnumPosResType.X2D1NoRef:
  205. case EnumPosResType.X3:
  206. case EnumPosResType.X3NoRef:
  207. default:
  208. return false;
  209. }
  210. })
  211. .AddPosMenu<PosRes>("查看参估", btnShowCgRes.ImageOptions.SvgImage, item =>
  212. {
  213. DxHelper.PopupHelper.ShowPopup(new ShowCgCtrl(item), gridHomePosRes, gridHomePosRes.Height, EnumPopupDirection.Bottom, showCloseButton: true);
  214. })
  215. .AddPosMenu<PosRes>("查看测向", btnShowCxRes.ImageOptions.SvgImage, item =>
  216. {
  217. DxHelper.PopupHelper.ShowPopup(new ShowCxCtrl(item), gridHomePosRes, gridHomePosRes.Height, EnumPopupDirection.Bottom, showCloseButton: true);
  218. }, p =>
  219. {
  220. switch (p.PosResType)
  221. {
  222. case EnumPosResType.X1D1CX:
  223. case EnumPosResType.RH:
  224. return true;
  225. case EnumPosResType.X3TwoDfo:
  226. case EnumPosResType.X2Dfo:
  227. case EnumPosResType.X2D1:
  228. case EnumPosResType.X2D1NoRef:
  229. case EnumPosResType.X3:
  230. case EnumPosResType.X3NoRef:
  231. default:
  232. return false;
  233. }
  234. });
  235. }
  236. catch (Exception ex)
  237. {
  238. Serilog.Log.Error(ex, "加载任务信息异常");
  239. DxHelper.MsgBoxHelper.ShowError("加载任务信息异常");
  240. }
  241. gridHomeTask.DataSource = list;
  242. gridView1.Columns[nameof(TaskInfo.TaskName)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  243. this.svgImageCollection1.Add("Stopped", SvgHelper.CreateCycle("#1E8B58"));
  244. this.svgImageCollection1.Add("Running", SvgHelper.CreateCycle("#2E8B57"));
  245. gridView1.CustomDrawCell += GridView1_CustomDrawCell;
  246. gridView1.CustomColumnDisplayText += GridView1_CustomColumnDisplayText;
  247. gridView1.RowClick += GridView1_RowClick;
  248. using (RHDWContext db = new RHDWContext())
  249. {
  250. var settings = await db.SysSetings.FirstOrDefaultAsync();
  251. if (settings == null)
  252. {
  253. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP端口信息");
  254. return;
  255. }
  256. try
  257. {
  258. StartOptions options = new StartOptions();
  259. options.Urls.Add($"http://+:{settings.HttpPort}");
  260. httpServer = WebApp.Start<Startup>(options);
  261. }
  262. catch (System.Reflection.TargetInvocationException ex)
  263. {
  264. httpServer = null;
  265. Serilog.Log.Error(ex, $"启动Http服务失败!");
  266. if (ex.InnerException is HttpListenerException)
  267. {
  268. DxHelper.MsgBoxHelper.ShowWarning($"{ex.InnerException.Message}");
  269. }
  270. else
  271. {
  272. DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. httpServer = null;
  278. Serilog.Log.Error(ex, $"启动Http服务失败!");
  279. DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
  280. }
  281. }
  282. WaitHelper.CloseForm();
  283. }
  284. private void ToPosList(List<PosRes> items)
  285. {
  286. if (items == null || items.Count() == 0)
  287. {
  288. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要转到列表的定位数据信息!");
  289. return;
  290. }
  291. try
  292. {
  293. var ds = this.gridHomePosRes.DataSource as List<PosRes>;
  294. var ids = items.Select(p => p.ID).ToList();
  295. //删除地图
  296. var deleteItems = ds.Where(m => !ids.Contains(m.ID)).ToList();
  297. mapControl1.DelPosItem(deleteItems);
  298. //删除列表
  299. ds.RemoveAll(m => !ids.Contains(m.ID));
  300. gridView2.RefreshData();
  301. }
  302. catch (Exception ex)
  303. {
  304. Serilog.Log.Error(ex, "转到列表异常!");
  305. MsgBoxHelper.ShowError("转到列表异常!");
  306. }
  307. }
  308. private async void EditTarget(List<PosRes> items)
  309. {
  310. if (items == null || items.Count() == 0)
  311. {
  312. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要编辑目标的定位数据信息!");
  313. return;
  314. }
  315. try
  316. {
  317. var firstItem = items.First();
  318. EditorTar frm = new EditorTar(new TargetInfo() { ID = firstItem.TargetID.HasValue ? firstItem.TargetID.Value : 0, TargetName = firstItem.TarName });
  319. if (frm.ShowDialog() != DialogResult.OK) return;
  320. var tar = frm.info;
  321. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  322. foreach (var groupItem in groupItems)
  323. {
  324. var ids = groupItem.Select(m => m.ID).ToList();
  325. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  326. {
  327. var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  328. EditTarget(array, tar);
  329. await db.SaveChangesAsync();
  330. }
  331. }
  332. EditTarget(items, tar);
  333. gridView2.RefreshData();
  334. }
  335. catch (Exception ex)
  336. {
  337. Serilog.Log.Error(ex, "编辑定位目标异常!");
  338. MsgBoxHelper.ShowError("编辑定位目标异常!");
  339. }
  340. }
  341. private void EditTarget(IEnumerable<PosRes> pos, TargetInfo tar)
  342. {
  343. foreach (var item in pos)
  344. {
  345. item.TargetID = tar.ID;
  346. item.TarName = tar.TargetName;
  347. }
  348. }
  349. private async void UseMirr(List<PosRes> items)
  350. {
  351. if (items == null || items.Count() == 0)
  352. {
  353. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要使用镜像点的定位数据信息!");
  354. return;
  355. }
  356. try
  357. {
  358. if (XtraMessageBox.Show("确认使用镜像点?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  359. {
  360. return;
  361. }
  362. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  363. foreach (var groupItem in groupItems)
  364. {
  365. var ids = groupItem.Select(m => m.ID).ToList();
  366. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  367. {
  368. var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  369. UseMirror(array);
  370. await db.SaveChangesAsync();
  371. }
  372. }
  373. UseMirror(items);
  374. mapControl1.UpdatePosItem(items);
  375. gridView2.RefreshData();
  376. }
  377. catch (Exception ex)
  378. {
  379. Serilog.Log.Error(ex, "使用镜像点失败!");
  380. MsgBoxHelper.ShowError("使用镜像点失败!");
  381. }
  382. }
  383. private async void DeletePosRes(List<PosRes> items)
  384. {
  385. if (items == null || items.Count() == 0)
  386. {
  387. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要删除的定位数据信息!");
  388. return;
  389. }
  390. try
  391. {
  392. if (XtraMessageBox.Show("确认删除定位点?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  393. {
  394. return;
  395. }
  396. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  397. foreach (var groupItem in groupItems)
  398. {
  399. var ids = groupItem.Select(m => m.ID).ToList();
  400. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  401. {
  402. List<PosRes> list = await db.PosRes.Where(p => ids.Contains(p.ID)).ToListAsync();
  403. db.PosRes.RemoveRange(list);
  404. await db.SaveChangesAsync();
  405. }
  406. }
  407. mapControl1.DelPosItem(items);
  408. var ds = this.gridHomePosRes.DataSource as List<PosRes>;
  409. ds.RemoveAll(m => items.Select(p => p.ID).Contains(m.ID));
  410. gridView2.RefreshData();
  411. }
  412. catch (Exception ex)
  413. {
  414. Serilog.Log.Error(ex, "删除定位点失败");
  415. MsgBoxHelper.ShowError("删除定位点失败!");
  416. }
  417. }
  418. private void UseMirror(IEnumerable<PosRes> pos)
  419. {
  420. foreach (var item in pos)
  421. {
  422. var mirrlon = item.MirrLon;
  423. var mirrLat = item.MirrLat;
  424. if (mirrlon == 999)
  425. {
  426. continue;
  427. }
  428. item.MirrLon = item.PosLon;
  429. item.MirrLat = item.PosLat;
  430. item.PosLon = mirrlon;
  431. item.PosLat = mirrLat;
  432. }
  433. }
  434. private async void GridView1_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
  435. {
  436. listCts.ForEach(t => t.Cancel());
  437. listCts.Clear();
  438. var cts = new CancellationTokenSource();
  439. listCts.Add(cts);
  440. mapControl1.DelFixedImg("Sat");
  441. mapControl1.DelFixedImg("Tx");
  442. tsk = (e.Row as TaskInfo);
  443. if (tsk == null) return;
  444. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  445. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  446. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  447. List<PosRes> listPos = await searchPos(cts.Token);
  448. this.gridHomePosRes.DataSource = listPos;
  449. using (RHDWContext db = new RHDWContext())
  450. {
  451. var sat1 = db.SatInfos.Where(p => p.SatCode == tsk.MainSat).FirstOrDefault();
  452. var sat2 = db.SatInfos.Where(p => p.SatCode == tsk.Adja1Sat).FirstOrDefault();
  453. var sat3 = db.SatInfos.Where(p => p.SatCode == tsk.Adja2Sat).FirstOrDefault();
  454. if (sat1 != null && sat1.SatLon != null)
  455. mapControl1.DrawFixedImg("Sat", 0, sat1.SatLon.Value, DxHelper.SvgHelper.CreateSat(), $"主星\r\n{sat1.Sat}");
  456. if (sat2 != null && sat2.SatLon != null)
  457. mapControl1.DrawFixedImg("Sat", 0, sat2.SatLon.Value, DxHelper.SvgHelper.CreateSat(), $"邻1星\r\n{sat2.Sat}");
  458. if (sat3 != null && sat3.SatLon != null)
  459. mapControl1.DrawFixedImg("Sat", 0, sat3.SatLon.Value, DxHelper.SvgHelper.CreateSat(), $"邻2星\r\n{sat3.Sat}");
  460. }
  461. mapControl1.SetPosDataSource(listPos);
  462. }
  463. private void GridView2_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
  464. {
  465. mapControl1.DelFixedImg("Tx");
  466. var posItem = (e.Row as PosRes);
  467. if (posItem == null) return;
  468. using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
  469. {
  470. var station = db.StationRes.Where(p => p.ID == posItem.StationResID).FirstOrDefault();
  471. if (station != null)
  472. {
  473. mapControl1.DrawFixedImg("Tx", station.SatTxLat, station.SatTxLon, DxHelper.SvgHelper.CreateAnt(), $"[卫星接收天线]\r\n经度:{station.SatTxLon}°\r\n纬度:{station.SatTxLat}°");
  474. if (station.CdbTxLon != null)
  475. mapControl1.DrawFixedImg("Tx", station.CdbTxLat.Value, station.CdbTxLon.Value, DxHelper.SvgHelper.CreateAnt(), $"[超短接收天线]\r\n经度:{station.CdbTxLon.Value}°\r\n纬度:{station.CdbTxLat.Value}°");
  476. if (station.RefLon != null)
  477. mapControl1.DrawFixedImg("Tx", station.RefLat.Value, station.RefLon.Value, DxHelper.SvgHelper.CreatePentagram(), $"[参考站]\r\n经度:{station.RefLon.Value}°\r\n纬度:{station.RefLat.Value}°");
  478. if (station.CxLon != null)
  479. mapControl1.DrawFixedImg("Tx", station.CxLat.Value, station.CxLon.Value, DxHelper.SvgHelper.CreatePentagram(), $"[测向站]\r\n经度:{station.CxLon.Value}°\r\n纬度:{station.CxLat.Value}°");
  480. }
  481. }
  482. }
  483. private void GridView1_RowClick(object sender, RowClickEventArgs e)
  484. {
  485. if (e.Clicks > 1)
  486. {
  487. layoutControlGroup1_CustomButtonClick(null, new DevExpress.XtraBars.Docking2010.BaseButtonEventArgs(new GroupBoxButton() { Caption = "编辑任务" }));
  488. }
  489. }
  490. private void GridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
  491. {
  492. if (e.Column.FieldName == nameof(TaskInfo.Freq))
  493. {
  494. e.DisplayText = $"{(long)e.Value / 1e6}MHz";
  495. }
  496. else if (e.Column.FieldName == nameof(TaskInfo.Band))
  497. {
  498. e.DisplayText = $"{(int)e.Value / 1e6}MHz";
  499. }
  500. }
  501. private void GridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  502. {
  503. if (e.Column.FieldName == nameof(TaskInfo.TaskName) && (EnumTaskState)gridView1.GetRowCellValue(e.RowHandle, nameof(TaskInfo.TaskState)) == EnumTaskState.Running)
  504. {
  505. var palette = SvgPaletteHelper.GetSvgPalette(this.LookAndFeel, ObjectState.Normal);
  506. e.Cache.DrawSvgImage(svgImageCollection1[1], new Rectangle(new Point(e.Bounds.X + 4, e.Bounds.Y + (e.Bounds.Height - 16) / 2), new Size(16, 16)), palette);
  507. Rectangle txtBounds = e.Bounds;
  508. txtBounds.Width -= 24;
  509. txtBounds.X += 24;
  510. e.Appearance.DrawString(e.Cache, e.DisplayText, txtBounds);
  511. e.Handled = true;
  512. }
  513. }
  514. private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
  515. {
  516. var hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition);
  517. if (hitInfo.RowHandle < 0 || hitInfo.Column == null || hitInfo.HitTest != DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitTest.RowCell)
  518. {
  519. toolTipController1.HideHint();
  520. return;
  521. }
  522. if (hitInfo.Column.FieldName == nameof(TaskInfo.TaskName))
  523. {
  524. var state = (EnumTaskState)gridView1.GetRowCellValue(hitInfo.RowHandle, nameof(TaskInfo.TaskState));
  525. if (state == EnumTaskState.Running)
  526. e.Info = new ToolTipControlInfo(hitInfo.RowHandle, "执行中");
  527. }
  528. }
  529. private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
  530. {
  531. if (gridView1.FocusedRowHandle < 0) return;
  532. var state = (EnumTaskState)gridView1.GetFocusedRowCellValue(nameof(TaskInfo.TaskState));
  533. btnStart.Enabled = state == EnumTaskState.Stopped;
  534. btnStop.Enabled = state == EnumTaskState.Running;
  535. popupMenu1.ShowPopup(MousePosition);
  536. }
  537. private void gridView2_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
  538. {
  539. if (gridView2.FocusedRowHandle < 0) return;
  540. var posRes = GetPosRes("");
  541. switch (posRes.PosResType)
  542. {
  543. case EnumPosResType.X1D1CX:
  544. //一星一地 测向线 GDOP
  545. btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  546. btnDrawDto.Visibility = btnGDOP.Visibility = btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  547. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  548. break;
  549. case EnumPosResType.X2D1:
  550. case EnumPosResType.X2D1NoRef:
  551. //两星一地 GDOP 时差线
  552. btnDrawDto.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  553. btnDrawCX.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  554. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  555. break;
  556. case EnumPosResType.RH:
  557. //融合DW=
  558. btnDrawDto.Visibility = btnDrawCX.Visibility = btnGDOP.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  559. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  560. break;
  561. case EnumPosResType.X3:
  562. case EnumPosResType.X3NoRef:
  563. //三星双时差DW GDOP 时差线
  564. btnDrawDto.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  565. btnDrawCX.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  566. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  567. break;
  568. case EnumPosResType.X3TwoDfo:
  569. //三星双频差DW GDOP 频差线
  570. btnDrawDfo.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  571. btnDrawDto.Visibility = btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  572. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  573. break;
  574. case EnumPosResType.X2Dfo:
  575. //双星时频差DW GDOP 时频差线
  576. btnDrawDto.Visibility = btnDrawDfo.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  577. btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  578. btnShowCxRes.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  579. break;
  580. default:
  581. break;
  582. }
  583. popupMenu2.ShowPopup(MousePosition);
  584. }
  585. private async void layoutControlGroup1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
  586. {
  587. var txt = (e.Button as GroupBoxButton).Caption;
  588. if (txt == "新建任务")
  589. {
  590. try
  591. {
  592. TaskEditor frm = new TaskEditor();
  593. if (frm.ShowDialog() != DialogResult.OK) return;
  594. var addItem = frm.info;
  595. using (RHDWContext db = new RHDWContext())
  596. {
  597. if (await db.TaskInfos.AnyAsync(p => p.TaskName == addItem.TaskName))
  598. {
  599. DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  600. return;
  601. }
  602. if (addItem.PosType == EnumPosType.X1D1CX)
  603. {
  604. addItem.Adja1Sat = null;
  605. addItem.Adja2Sat = null;
  606. }
  607. else if (addItem.PosType == EnumPosType.X2D1 || addItem.PosType == EnumPosType.X2Dfo || addItem.PosType == EnumPosType.RH)
  608. {
  609. addItem.Adja2Sat = null;
  610. }
  611. db.TaskInfos.Add(addItem);
  612. await db.SaveChangesAsync();
  613. }
  614. list.Insert(0, addItem);
  615. gridView1.RefreshData();
  616. gridView1.FocusedRowHandle = 0;
  617. }
  618. catch (Exception ex)
  619. {
  620. Serilog.Log.Error(ex, "保存任务异常");
  621. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  622. }
  623. }
  624. else if (txt == "编辑任务")
  625. {
  626. try
  627. {
  628. var editItem = gridView1.GetFocusedRow() as TaskInfo;
  629. TaskEditor frm = new TaskEditor(editItem);
  630. if (frm.ShowDialog() != DialogResult.OK) return;
  631. editItem = frm.info;
  632. using (RHDWContext db = new RHDWContext())
  633. {
  634. if (await db.TaskInfos.AnyAsync(p => p.ID != editItem.ID && p.TaskName == editItem.TaskName))
  635. {
  636. DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  637. return;
  638. }
  639. var find = await db.TaskInfos.Where(p => p.ID == editItem.ID).FirstOrDefaultAsync();
  640. find.TaskName = editItem.TaskName;
  641. find.PosType = editItem.PosType;
  642. find.UpdateTime = DateTime.Now;
  643. find.Freq = editItem.Freq;
  644. find.Band = editItem.Band;
  645. find.MainSat = editItem.MainSat;
  646. if (find.PosType == EnumPosType.X1D1CX)
  647. {
  648. find.Adja1Sat = null;
  649. find.Adja2Sat = null;
  650. }
  651. else if (find.PosType == EnumPosType.X2D1 || find.PosType == EnumPosType.X2Dfo || find.PosType == EnumPosType.RH)
  652. {
  653. find.Adja2Sat = null;
  654. }
  655. else
  656. {
  657. find.Adja1Sat = editItem.Adja1Sat;
  658. find.Adja2Sat = editItem.Adja2Sat;
  659. }
  660. await db.SaveChangesAsync();
  661. }
  662. gridView1.RefreshData();
  663. }
  664. catch (Exception ex)
  665. {
  666. Serilog.Log.Error(ex, "保存任务异常");
  667. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  668. }
  669. }
  670. else
  671. {
  672. try
  673. {
  674. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  675. if (tsk == null) return;
  676. if (!DxHelper.MsgBoxHelper.ShowConfirm($"删除任务[{tsk.TaskName}]?"))
  677. return;
  678. using (RHDWContext db = new RHDWContext())
  679. {
  680. var item = db.TaskInfos.FirstOrDefault(p => p.ID == tsk.ID);
  681. db.TaskInfos.Remove(item);
  682. db.SaveChanges();
  683. }
  684. gridView1.DeleteSelectedRows();
  685. }
  686. catch (Exception ex)
  687. {
  688. Serilog.Log.Error(ex, "删除任务异常");
  689. DxHelper.MsgBoxHelper.ShowError("删除任务异常");
  690. }
  691. }
  692. }
  693. IDisposable httpServer;
  694. private async void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  695. {
  696. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  697. if (e.Item.Caption == "启动任务")
  698. {
  699. try
  700. {
  701. using (RHDWContext db = new RHDWContext())
  702. {
  703. var find = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskState == EnumTaskState.Running && p.PosType == tsk.PosType);
  704. if (find != null)
  705. {
  706. var field = typeof(EnumPosType).GetField(Enum.GetName(typeof(EnumPosType), find.PosType));
  707. DxHelper.MsgBoxHelper.ShowWarning($"已经有一个[{field.GetCustomAttribute<DisplayAttribute>().Name}]任务正在执行,请先停止!");
  708. return;
  709. }
  710. var settings = await db.SysSetings.FirstOrDefaultAsync();
  711. if (settings == null)
  712. {
  713. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP端口信息");
  714. return;
  715. }
  716. if (httpServer == null)
  717. {
  718. try
  719. {
  720. StartOptions options = new StartOptions();
  721. options.Urls.Add($"http://+:{settings.HttpPort}");
  722. httpServer = WebApp.Start<Startup>(options);
  723. }
  724. catch (Exception ex)
  725. {
  726. Serilog.Log.Error(ex, "启动任务异常,Http定位接口服务启动失败");
  727. DxHelper.MsgBoxHelper.ShowError($"启动任务异常,Http定位接口服务启动失败");
  728. }
  729. }
  730. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  731. item.TaskState = EnumTaskState.Running;
  732. await db.SaveChangesAsync();
  733. tsk.TaskState = EnumTaskState.Running;
  734. Serilog.Log.Information($"用户启动了任务,ID={tsk.ID}");
  735. }
  736. }
  737. catch (Exception ex)
  738. {
  739. Serilog.Log.Error(ex, "启动任务异常");
  740. DxHelper.MsgBoxHelper.ShowError($"启动任务异常.{ex.Message}");
  741. }
  742. }
  743. else
  744. {
  745. try
  746. {
  747. using (RHDWContext db = new RHDWContext())
  748. {
  749. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  750. item.TaskState = EnumTaskState.Stopped;
  751. await db.SaveChangesAsync();
  752. //if (!db.TaskInfos.Any(p => p.TaskState == EnumTaskState.Running))
  753. //{
  754. // server?.StopListening();
  755. // server = null;
  756. //}
  757. }
  758. tsk.TaskState = EnumTaskState.Stopped;
  759. Serilog.Log.Information($"用户停止了任务,ID={tsk.ID}");
  760. }
  761. catch (Exception ex)
  762. {
  763. Serilog.Log.Error(ex, "停止任务异常");
  764. DxHelper.MsgBoxHelper.ShowError($"停止任务异常.{ex.Message}");
  765. }
  766. }
  767. gridView1.RefreshData();
  768. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  769. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  770. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  771. }
  772. private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
  773. {
  774. if (gridView1.RowCount == 0)
  775. {
  776. string txt = "点击+创建任务";
  777. var s = e.Appearance.CalcTextSize(e.Cache, txt, e.Bounds.Width).ToSize();
  778. var x = (e.Bounds.Width - s.Width) / 2;
  779. var y = (e.Bounds.Height - s.Height) / 2;
  780. //e.Appearance.DrawString(e.Cache, txt, new Rectangle(x,y,s.Width,s.Height));
  781. e.DrawHtml(htmlTemplate1);
  782. }
  783. }
  784. private void gridView2_RowClick(object sender, RowClickEventArgs e)
  785. {
  786. var p = gridView2.GetFocusedRow() as PosRes;
  787. p.Selected = true;
  788. mapControl1.UpdatePosItem(p);
  789. }
  790. private void btnDrawDto_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  791. {
  792. var info = GetPosRes("绘制时差");
  793. if (info == null) return;
  794. DrawDtoLine(info);
  795. }
  796. private PosRes GetPosRes(string msg)
  797. {
  798. var ids = gridView2.GetSelectedRows();
  799. if (ids.Length <= 0)
  800. {
  801. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要{msg}的定位数据信息!");
  802. return null;
  803. }
  804. var item = gridView2.GetRow(ids[0]) as PosRes;
  805. return item;
  806. }
  807. private void btnDrawDfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  808. {
  809. var info = GetPosRes("绘制频差");
  810. if (info == null) return;
  811. DrawDfoLine(info);
  812. }
  813. private void btnDrawCX_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  814. {
  815. var ids = gridView2.GetSelectedRows();
  816. if (ids.Length <= 0)
  817. {
  818. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要绘制测向线的定位数据信息!");
  819. return;
  820. }
  821. var item = gridView2.GetRow(ids[0]) as PosRes;
  822. if (item.PosResType == EnumPosResType.X1D1CX)
  823. {
  824. DrawCXLine(item);
  825. }
  826. }
  827. private void btnGDOP_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  828. {
  829. var info = GetPosRes("绘制GDOP");
  830. if (info == null) return;
  831. DrawGDOP(info);
  832. }
  833. private void btnShowCgRes_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  834. {
  835. var item = gridView2.GetFocusedRow() as PosRes;
  836. DxHelper.PopupHelper.ShowPopup(new ShowCgCtrl(item), gridHomePosRes, gridHomePosRes.Height, EnumPopupDirection.Bottom, showCloseButton: true);
  837. }
  838. private void btnShowCxRes_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  839. {
  840. var item = gridView2.GetFocusedRow() as PosRes;
  841. DxHelper.PopupHelper.ShowPopup(new ShowCxCtrl(item), gridHomePosRes, gridHomePosRes.Height, EnumPopupDirection.Bottom, showCloseButton: true);
  842. }
  843. private void DrawGDOP(PosRes item)
  844. {
  845. try
  846. {
  847. switch (item.PosResType)
  848. {
  849. case EnumPosResType.X1D1CX:
  850. X1D1GDOPParam x1D1GdopParam = new X1D1GDOPParam(item);
  851. x1D1GdopParam.mapControl1 = mapControl1;
  852. DxHelper.PopupHelper.ShowPopup(x1D1GdopParam, layoutControl1, 400);
  853. break;
  854. case EnumPosResType.X2D1:
  855. case EnumPosResType.X2D1NoRef:
  856. X2D1GDOPParam x2D1GdopParam = new X2D1GDOPParam(item);
  857. x2D1GdopParam.mapControl1 = mapControl1;
  858. DxHelper.PopupHelper.ShowPopup(x2D1GdopParam, layoutControl1, 400);
  859. break;
  860. case EnumPosResType.X3:
  861. case EnumPosResType.X3NoRef:
  862. X3GDOPParam x3GdopParam = new X3GDOPParam(item);
  863. x3GdopParam.mapControl1 = mapControl1;
  864. DxHelper.PopupHelper.ShowPopup(x3GdopParam, layoutControl1, 400);
  865. break;
  866. case EnumPosResType.X3TwoDfo:
  867. X3DFGDOPParam x3DFGdopParam = new X3DFGDOPParam(item);
  868. x3DFGdopParam.mapControl1 = mapControl1;
  869. DxHelper.PopupHelper.ShowPopup(x3DFGdopParam, layoutControl1, 400);
  870. break;
  871. case EnumPosResType.X2Dfo:
  872. X2DFGDOPParam x2DFGdopParam = new X2DFGDOPParam(item);
  873. x2DFGdopParam.mapControl1 = mapControl1;
  874. DxHelper.PopupHelper.ShowPopup(x2DFGdopParam, layoutControl1, 400);
  875. break;
  876. default:
  877. break;
  878. }
  879. }
  880. catch (Exception ex)
  881. {
  882. DxHelper.MsgBoxHelper.ShowWarning($"绘制{item.PosResType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
  883. }
  884. }
  885. private void DrawDtoLine(PosRes item)
  886. {
  887. switch (item.PosResType)
  888. {
  889. case EnumPosResType.X1D1CX:
  890. X1D1DTOParamEditor frm = new X1D1DTOParamEditor(item, mapControl1);
  891. DxHelper.PopupHelper.ShowPopup(frm, layoutControl1, 500);
  892. break;
  893. case EnumPosResType.X2D1:
  894. case EnumPosResType.X2D1NoRef:
  895. X2D1DTOParamEditor X2D1frm = new X2D1DTOParamEditor(item, mapControl1);
  896. DxHelper.PopupHelper.ShowPopup(X2D1frm, layoutControl1, 500);
  897. break;
  898. case EnumPosResType.X3:
  899. case EnumPosResType.X3NoRef:
  900. X3DTOParamEditor X3frm = new X3DTOParamEditor(item, mapControl1);
  901. DxHelper.PopupHelper.ShowPopup(X3frm, layoutControl1, 500);
  902. break;
  903. case EnumPosResType.X2Dfo:
  904. X2DTOParamEditor X2Dfofrm = new X2DTOParamEditor(item, mapControl1);
  905. DxHelper.PopupHelper.ShowPopup(X2Dfofrm, layoutControl1, 500);
  906. break;
  907. default:
  908. break;
  909. }
  910. }
  911. private void DrawDfoLine(PosRes item)
  912. {
  913. switch (item.PosResType)
  914. {
  915. case EnumPosResType.X3TwoDfo:
  916. case EnumPosResType.X2Dfo:
  917. DrawX3DfoLine(item);
  918. break;
  919. default:
  920. break;
  921. }
  922. }
  923. private async void DrawX3DfoLine(PosRes item)
  924. {
  925. try
  926. {
  927. StationRes station;
  928. CgRes cg;
  929. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  930. {
  931. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  932. station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
  933. }
  934. if (cg == null)
  935. {
  936. Serilog.Log.Error($"绘制三星频差线错误,未找到定位关联的参估计信息.PosID={item.ID},SigTime={item.SigTime}");
  937. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的参估计信息");
  938. return;
  939. }
  940. if (station == null)
  941. {
  942. Serilog.Log.Error($"绘制三星频差线错误,未找到定位关联的站点信息.PosID={item.ID},SigTime={item.SigTime}");
  943. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的站点信息");
  944. return;
  945. }
  946. if (station.SatTxLon == 0 || station.SatTxLat == 0)
  947. {
  948. Serilog.Log.Error($"绘制三星频差线错误,天线信息为空.PosID={item.ID},SigTime={item.SigTime}");
  949. DxHelper.MsgBoxHelper.ShowError($"天线信息为空!");
  950. return;
  951. }
  952. if (station.RefLon == 0 || station.RefLat == 0)
  953. {
  954. Serilog.Log.Error($"绘制三星频差线错误,参考站信息为空.PosID={item.ID},SigTime={item.SigTime}");
  955. DxHelper.MsgBoxHelper.ShowError($"参考站信息为空!");
  956. return;
  957. }
  958. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  959. twoStartOption.Freq = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value : 0;
  960. twoStartOption.RefFreq = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value : 0;
  961. twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, cg.MainVx.Value, cg.MainVy.Value, cg.MainVz.Value };
  962. twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, cg.Adja1Vx.Value, cg.Adja1Vy.Value, cg.Adja1Vz.Value };
  963. twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  964. twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  965. twoStartOption.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  966. twoStartOption.TargetDfo = cg.Dfo1.Value;
  967. twoStartOption.Turn1 = Math.Abs(twoStartOption.Freq - (cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value : 0));
  968. twoStartOption.Turn2 = Math.Abs(twoStartOption.RefFreq - (cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value : 0));
  969. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja1Dfo.Value;
  970. var tsDtoLine = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  971. List<SatInfo> listSat = null;
  972. using (RHDWContext db = new RHDWContext())
  973. {
  974. listSat = await db.SatInfos.ToListAsync();
  975. }
  976. var msat = listSat?.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; ;
  977. var ad1sat = listSat?.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  978. if (msat == null) msat = cg.MainCode.ToString();
  979. if (ad1sat == null) ad1sat = cg.Adja1Code.ToString();
  980. mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]频差线", tsDtoLine);
  981. if (item.PosResType == EnumPosResType.X3TwoDfo)
  982. {
  983. twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, cg.Adja2Vx.Value, cg.Adja2Vy.Value, cg.Adja2Vz.Value };
  984. twoStartOption.TargetDfo = cg.Dfo2.Value;
  985. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja2Dfo.Value;
  986. var tsDtoLine1 = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  987. string ad2sat = string.Empty;
  988. if (cg.Adja2Code.HasValue)
  989. {
  990. ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  991. }
  992. mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]频差线", tsDtoLine1);
  993. }
  994. }
  995. catch (Exception ex)
  996. {
  997. Serilog.Log.Error(ex, $"绘制{item.PosResType.GetEnumDisplayName()}频差线失败.PosID={item.ID},SigTime={item.SigTime}");
  998. DxHelper.MsgBoxHelper.ShowError($"绘制{item.PosResType.GetEnumDisplayName()}频差线失败");
  999. }
  1000. }
  1001. private async void DrawCXLine(PosRes item)
  1002. {
  1003. try
  1004. {
  1005. CxRes cx;
  1006. StationRes station;
  1007. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  1008. {
  1009. cx = await db.CxRes.Where(m => m.ID == item.CxResID.Value).FirstOrDefaultAsync();
  1010. station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
  1011. }
  1012. if (cx == null)
  1013. {
  1014. Serilog.Log.Error($"绘制测向线错误,未找到定位关联的测向信息.PosID={item.ID},SigTime={item.SigTime}");
  1015. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的测向信息");
  1016. return;
  1017. }
  1018. if (station == null)
  1019. {
  1020. Serilog.Log.Error($"绘制测向线错误,未找到定位关联的站点信息.PosID={item.ID},SigTime={item.SigTime}");
  1021. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的站点信息!");
  1022. return;
  1023. }
  1024. if (station.CxLon == 0 || station.CxLat == 0)
  1025. {
  1026. Serilog.Log.Error($"绘制测向线错误,测向站信息为空.PosID={item.ID},SigTime={item.SigTime}");
  1027. DxHelper.MsgBoxHelper.ShowError($"测向站信息为空!");
  1028. return;
  1029. }
  1030. double deg = cx.Fx;//向北顺时针方向为夹角
  1031. //计算测向站到定位点之间的距离
  1032. var km = MapControlEx.CalcLineKm(station.CxLon.Value, station.CxLat.Value, item.PosLon, item.PosLat);
  1033. var endpoint = MapControlEx.CalcSituation(station.CxLon.Value, station.CxLat.Value, deg, (km + 100) * 1000);
  1034. List<(double, double)> points = new List<(double, double)>();
  1035. points.Add((station.CxLon.Value, station.CxLat.Value));
  1036. points.Add((endpoint.Item1, endpoint.Item2));
  1037. mapControl1.DrawCXLine($"测向线角度:{cx.Fx}°\t\n", points, true);
  1038. }
  1039. catch (Exception ex)
  1040. {
  1041. Serilog.Log.Error(ex, $"绘制测向线失败.PosID={item.ID},SigTime={item.SigTime}");
  1042. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败");
  1043. }
  1044. }
  1045. private async void txtTimeCho_SelectedIndexChanged(object sender, EventArgs e)
  1046. {
  1047. listCts.ForEach(t => t.Cancel());
  1048. listCts.Clear();
  1049. this.gridHomePosRes.DataSource = new List<PosRes>();//先设为空,数据相同时便于观察结果有没有变化
  1050. if (tsk == null)
  1051. {
  1052. return;
  1053. }
  1054. var cts = new CancellationTokenSource();
  1055. listCts.Add(cts);
  1056. switch (txtTimeCho.Text)
  1057. {
  1058. case "最近1小时":
  1059. case "最近6小时":
  1060. case "最近12小时":
  1061. case "最近1天":
  1062. case "最近3天":
  1063. layoutControlItemStartTime.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  1064. layoutControlItemEndTime.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  1065. layoutControlItemSearch.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  1066. this.gridHomePosRes.DataSource = await searchPos(cts.Token);
  1067. break;
  1068. case "自定义":
  1069. layoutControlItemStartTime.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  1070. layoutControlItemEndTime.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  1071. layoutControlItemSearch.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  1072. break;
  1073. }
  1074. }
  1075. private async void btnSearch_Click(object sender, EventArgs e)
  1076. {
  1077. if (txtStartTime.EditValue == null)
  1078. {
  1079. DxHelper.MsgBoxHelper.ShowError($"请选择信号开始时间!");
  1080. return;
  1081. }
  1082. if (txtEndTime.EditValue == null)
  1083. {
  1084. DxHelper.MsgBoxHelper.ShowError($"请选择信号结束时间!");
  1085. return;
  1086. }
  1087. if (txtStartTime.DateTime > txtEndTime.DateTime)
  1088. {
  1089. DxHelper.MsgBoxHelper.ShowError($"开始时间不能大于结束时间!");
  1090. return;
  1091. }
  1092. if ((txtEndTime.DateTime - txtStartTime.DateTime).TotalDays > 10)
  1093. {
  1094. MsgBoxHelper.ShowWarning("时间跨度不能超过10天!");
  1095. return;
  1096. }
  1097. listCts.ForEach(t => t.Cancel());
  1098. listCts.Clear();
  1099. var cts = new CancellationTokenSource();
  1100. listCts.Add(cts);
  1101. var listPos = await searchPos(cts.Token);
  1102. this.gridHomePosRes.DataSource = listPos;
  1103. }
  1104. private async Task<List<PosRes>> searchPos(CancellationToken ct = default)
  1105. {
  1106. try
  1107. {
  1108. DateTime start, end = DateTime.MinValue;
  1109. if (txtTimeCho.SelectedText == "自定义")
  1110. {
  1111. start = txtStartTime.DateTime;
  1112. end = txtEndTime.DateTime;
  1113. }
  1114. else
  1115. {
  1116. if (!Directory.Exists("DbPart")) return new List<PosRes>();
  1117. var yearDirs = Directory.EnumerateDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart")).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
  1118. foreach (var yearDir in yearDirs)
  1119. {
  1120. //每一天的db文件,倒序排列
  1121. var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir), "*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
  1122. foreach (var dayFile in dayFiles)
  1123. {
  1124. using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
  1125. {
  1126. if (db.PosRes.Any(p => p.TaskInfoID == tsk.ID))
  1127. end = await db.PosRes.Where(p => p.TaskInfoID == tsk.ID).MaxAsync(p => p.SigTime);
  1128. }
  1129. if (end != DateTime.MinValue)
  1130. {
  1131. goto skip;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. skip:
  1137. if (end == DateTime.MinValue)
  1138. {
  1139. return new List<PosRes>();//没有数据不查询
  1140. }
  1141. start = end.AddHours(-(int)txtTimeCho.EditValue);
  1142. DateTime endDay = new DateTime(end.Year, end.Month, end.Day);
  1143. DateTime startDay = new DateTime(start.Year, start.Month, start.Day);
  1144. List<PosRes> list = new List<PosRes>();
  1145. while (endDay >= startDay)
  1146. {
  1147. using (RHDWPartContext db = RHDWPartContext.GetContext(endDay))
  1148. {
  1149. var posRes = await db.PosRes
  1150. .Where(w => w.SigTime >= start && w.SigTime <= end && w.TaskInfoID == tsk.ID)
  1151. .OrderByDescending(o => o.SigTime).ToListAsync(ct);
  1152. list.AddRange(posRes);
  1153. }
  1154. endDay = endDay.AddDays(-1);
  1155. }
  1156. return list;
  1157. }
  1158. catch (TaskCanceledException) { }//屏蔽掉取消查询的异常
  1159. catch (Exception ex)
  1160. {
  1161. Serilog.Log.Error(ex, "定位结果查询异常");
  1162. MsgBoxHelper.ShowError("定位结果查询异常");
  1163. }
  1164. return new List<PosRes>();
  1165. }
  1166. }
  1167. }