CtrlHome.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. using DevExpress.Utils;
  2. using DevExpress.Utils.Drawing;
  3. using DevExpress.Utils.Drawing.Helpers;
  4. using DevExpress.Utils.Svg;
  5. using DevExpress.XtraEditors.ButtonsPanelControl;
  6. using DevExpress.XtraGrid.Views.Grid;
  7. using DevExpress.XtraGrid.Views.Grid.ViewInfo;
  8. using DevExpress.XtraTreeList.Data;
  9. using DxHelper;
  10. using Microsoft.Owin.Hosting;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel.DataAnnotations;
  14. using System.Data;
  15. using System.Data.Entity;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Net;
  19. using System.Reflection;
  20. using System.Text;
  21. using System.Windows.Forms;
  22. using XdCxRhDW.App.Api;
  23. using XdCxRhDW.App.EditForms;
  24. using XdCxRhDW.Repostory.Model;
  25. using System.Windows.Documents;
  26. using XdCxRhDW.Repostory.EFContext;
  27. using XdCxRhDW.Core.Api;
  28. using XdCxRhDW.WebApi;
  29. using XdCxRhDW.Core.ObServer;
  30. namespace XdCxRhDW.App.UserControl
  31. {
  32. public partial class CtrlHome : DevExpress.XtraEditors.XtraUserControl
  33. {
  34. List<TaskInfo> list = new List<TaskInfo>();
  35. public CtrlHome()
  36. {
  37. InitializeComponent();
  38. gridHomeTask.Init();
  39. gridHomePosRes.Init().UseMultiSelect().UseRowNumber();
  40. btnDrawDto.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\DtoLine.svg");
  41. btnDrawDfo.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\DfoLine.svg");
  42. btnGDOP.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Image\\GDOP.svg");
  43. var mapService = string.Empty;//http://ows.mundialis.de/services/service
  44. using (RHDWContext db = new RHDWContext())
  45. {
  46. mapService = db.SysSetings.FirstOrDefault()?.MapService;
  47. }
  48. mapControl1.UseDefalutOptions()
  49. //.UseCluster()//定位点使用内置聚合
  50. .UseClearAll()
  51. .UseDistanceLine()
  52. .UseMarkDot()
  53. .UseExportImg()
  54. .UseExportXlsx()
  55. .UseExportCsv()
  56. .SetMapLayerType(mapService)
  57. //.SetMapLayerType("")
  58. //.UseHJ(item =>
  59. //{
  60. // (double Lon, double Lat) = item;
  61. // PosRes pos = new PosRes();
  62. // pos.PosLon = Lon;
  63. // pos.PosLat = Lat;
  64. // pos.SigTime = DateTime.Now;
  65. // mapControl1.AddHJPosItem(pos);
  66. //})
  67. .UseDrawRect(rect =>
  68. {
  69. (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
  70. });
  71. PosObServer.Instance.Sub(PosSubEvent);
  72. }
  73. private void PosSubEvent(PosRes posRes)
  74. {
  75. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  76. if (currentTask.ID == posRes.TaskInfoID)
  77. {
  78. var ds = this.gridHomePosRes.DataSource as List<PosRes>;
  79. ds.Insert(0, posRes);
  80. this.Invoke(new Action(() =>
  81. {
  82. gridView2.RefreshData();
  83. mapControl1.AddPosItem(posRes);
  84. }));
  85. }
  86. }
  87. private async void GridView1_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
  88. {
  89. var tsk = (e.Row as TaskInfo);
  90. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  91. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  92. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  93. List<PosRes> listPos = new List<PosRes>();
  94. using (RHDWContext db = new RHDWContext())
  95. {
  96. var items = await db.PosRes.Where(p => p.TaskInfoID == tsk.ID).OrderByDescending(p => p.SigTime).ToListAsync();
  97. listPos.AddRange(items);
  98. }
  99. this.gridHomePosRes.DataSource = listPos;
  100. mapControl1.SetPosDataSource(listPos.Where(p => p.PosLon <= 180), false);
  101. }
  102. private async void CtrlHome_Load(object sender, EventArgs e)
  103. {
  104. gridView1.FocusedRowObjectChanged += GridView1_FocusedRowObjectChanged;
  105. try
  106. {
  107. List<SatInfo> satList = new List<SatInfo>();
  108. List<TxInfo> txList = new List<TxInfo>();
  109. using (RHDWContext db = new RHDWContext())
  110. {
  111. var qq = db.TaskInfos.OrderByDescending(p => p.CreateTime).ToList();
  112. list.AddRange(qq);
  113. var runningList = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running).ToListAsync();
  114. foreach (var item in runningList)
  115. {
  116. item.TaskState = EnumTaskState.Stopped;
  117. }
  118. await db.SaveChangesAsync();
  119. var satres = db.SatInfos.OrderBy(p => p.SatName).OrderBy(p => p.SatName);
  120. satList.AddRange(await satres.ToListAsync());
  121. var txres = await db.TxInfos.ToListAsync();
  122. txList.AddRange(txres);
  123. }
  124. foreach (var sat in satList)
  125. {
  126. if (!sat.SatLon.HasValue) continue;
  127. mapControl1.Invoke(new Action(() =>
  128. {
  129. mapControl1.DrawFixedImg("sat", 10, sat.SatLon.Value, DxHelper.SvgHelper.CreateSat(), new Size(24, 24), $"{sat.Sat}\r\n");
  130. }));
  131. }
  132. foreach (var txitem in txList)
  133. {
  134. if ((txitem.Lon >= 180 || txitem.Lon <= 180) && txitem.Lat >= -90 || txitem.Lat <= 90)//画天线
  135. {
  136. mapControl1.Invoke(new Action(() =>
  137. {
  138. switch (txitem.TxType)
  139. {
  140. #warning 天线图片需要邹大哥给
  141. case EnumTxType.MainSat:
  142. mapControl1.DrawFixedImg("MainSatTx", txitem.Lat, txitem.Lon, DxHelper.SvgHelper.CreatePentagram(), new Size(24, 24), $"[{txitem.Name}]\r\n主星天线经度:{txitem.Lon}°\r\n主星天线纬度:{txitem.Lat}°\r\n");
  143. break;
  144. case EnumTxType.AdjaSat:
  145. mapControl1.DrawFixedImg("AdjaSatTx", txitem.Lat, txitem.Lon, DxHelper.SvgHelper.CreatePentagram(), new Size(24, 24), $"[{txitem.Name}]\r\n邻星天线经度:{txitem.Lon}°\r\n邻星天线纬度:{txitem.Lat}°\r\n");
  146. break;
  147. case EnumTxType.Cdb:
  148. mapControl1.DrawFixedImg("CdbStation", txitem.Lat, txitem.Lon, DxHelper.SvgHelper.CreatePentagram(), new Size(24, 24), $"[{txitem.Name}]\r\n超短站经度:{txitem.Lon}°\r\n超短站纬度:{txitem.Lat}°\r\n");
  149. break;
  150. case EnumTxType.Cx:
  151. mapControl1.DrawFixedImg("CxStation", txitem.Lat, txitem.Lon, DxHelper.SvgHelper.CreatePentagram(), new Size(24, 24), $"[{txitem.Name}]\r\n测向站经度:{txitem.Lon}°\r\n测向站纬度:{txitem.Lat}°\r\n");
  152. break;
  153. case EnumTxType.Ref:
  154. mapControl1.DrawFixedImg("RefStation", txitem.Lat, txitem.Lon, DxHelper.SvgHelper.CreatePentagram(), new Size(24, 24), $"参考站经度:{txitem.Lon}°\r\n参考站纬度:{txitem.Lat}°\r\n");
  155. break;
  156. default:
  157. break;
  158. }
  159. }));
  160. }
  161. }
  162. mapControl1.AddPosMenu<PosRes>("绘制时差线", SvgHelper.LoadFromFile("Image\\DtoLine.svg"), item =>
  163. {
  164. var posType = GetPosRes(item, "绘制时差线");
  165. DrawDtoLine(item, posType);
  166. })
  167. .AddPosMenu<PosRes>("绘制频差线", SvgHelper.LoadFromFile("Image\\DfoLine.svg"), item =>
  168. {
  169. var posType = GetPosRes(item, "绘制频差线");
  170. DrawDfoLine(item, posType);
  171. })
  172. //.AddPosMenu<PosRes>("绘制GDOP", SvgHelper.LoadFromFile("Image\\GDOP.svg"), item =>
  173. // {
  174. // var posType = GetPosRes(item, "绘制GDOP");
  175. // DrawGDOP(item.SigTime, posType);
  176. // })
  177. .AddPosMenu<PosRes>("绘制测向线", btnDrawCX.ImageOptions.SvgImage, item =>
  178. {
  179. DrawCXLine(item);
  180. });
  181. }
  182. catch (Exception ex)
  183. {
  184. Serilog.Log.Error(ex, "加载任务信息异常");
  185. DxHelper.MsgBoxHelper.ShowError("加载任务信息异常");
  186. }
  187. gridHomeTask.DataSource = list;
  188. gridView1.Columns["TaskName"].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  189. this.svgImageCollection1.Add("Stopped", SvgHelper.CreateCycle("#1E8B58"));
  190. this.svgImageCollection1.Add("Running", SvgHelper.CreateCycle("#2E8B57"));
  191. gridView1.CustomDrawCell += GridView1_CustomDrawCell;
  192. using (RHDWContext db = new RHDWContext())
  193. {
  194. var settings = await db.SysSetings.FirstOrDefaultAsync();
  195. if (settings == null)
  196. {
  197. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP端口信息");
  198. return;
  199. }
  200. try
  201. {
  202. StartOptions options = new StartOptions();
  203. options.Urls.Add($"http://+:{settings.HttpPort}");
  204. httpServer = WebApp.Start<Startup>(options);
  205. }
  206. catch (System.Reflection.TargetInvocationException ex)
  207. {
  208. httpServer = null;
  209. Serilog.Log.Error(ex, $"启动Http服务失败!");
  210. if (ex.InnerException is HttpListenerException)
  211. {
  212. DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败,请以管理员身份运行程序!");
  213. }
  214. else
  215. {
  216. DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. httpServer = null;
  222. Serilog.Log.Error(ex, $"启动Http服务失败!");
  223. DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!");
  224. }
  225. }
  226. WaitHelper.CloseForm();
  227. }
  228. private void GridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  229. {
  230. if (e.Column.FieldName == "TaskName" && (EnumTaskState)gridView1.GetRowCellValue(e.RowHandle, "TaskState") == EnumTaskState.Running)
  231. {
  232. var palette = SvgPaletteHelper.GetSvgPalette(this.LookAndFeel, ObjectState.Normal);
  233. 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);
  234. Rectangle txtBounds = e.Bounds;
  235. txtBounds.Width -= 24;
  236. txtBounds.X += 24;
  237. e.Appearance.DrawString(e.Cache, e.DisplayText, txtBounds);
  238. e.Handled = true;
  239. }
  240. }
  241. //public void SetEnumColumnImage(GridView gv, string columnFieldName, object imageCollection)
  242. //{
  243. // var repositoryItemImageComboBoxStatus = new RepositoryItemImageEdit();
  244. // var col = gv.Columns[columnFieldName];
  245. // col.MaxWidth = 40;
  246. // repositoryItemImageComboBoxStatus.Images = imageCollection;
  247. // col.ColumnEdit = repositoryItemImageComboBoxStatus;
  248. //}
  249. private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
  250. {
  251. GridHitInfo hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition);
  252. if (hitInfo.RowHandle < 0 || hitInfo.Column == null || hitInfo.HitTest != GridHitTest.RowCell)
  253. {
  254. toolTipController1.HideHint();
  255. return;
  256. }
  257. if (hitInfo.Column.FieldName == "TaskName")
  258. {
  259. var state = (EnumTaskState)gridView1.GetRowCellValue(hitInfo.RowHandle, "TaskState");
  260. if (state == EnumTaskState.Running)
  261. e.Info = new ToolTipControlInfo(hitInfo.RowHandle, "执行中");
  262. }
  263. }
  264. private void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
  265. {
  266. if (gridView1.FocusedRowHandle < 0) return;
  267. var state = (EnumTaskState)gridView1.GetFocusedRowCellValue("TaskState");
  268. btnStart.Enabled = state == EnumTaskState.Stopped;
  269. btnStop.Enabled = state == EnumTaskState.Running;
  270. popupMenu1.ShowPopup(MousePosition);
  271. }
  272. private void gridView2_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
  273. {
  274. if (gridView2.FocusedRowHandle < 0) return;
  275. if (!gridView2.GetSelectedRows().Any())
  276. {
  277. btnDelPos.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  278. }
  279. else
  280. {
  281. btnDelPos.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  282. }
  283. var posRes = GetPosRes("");
  284. switch (posRes.Item2)
  285. {
  286. case EnumPosType.X1D1CX:
  287. //一星一地 测向线 GDOP
  288. btnDrawDto.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  289. btnGDOP.Visibility = btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  290. break;
  291. case EnumPosType.X2D1:
  292. //两星一地 GDOP 时差线
  293. btnDrawDto.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  294. btnDrawCX.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  295. break;
  296. case EnumPosType.RH:
  297. //融合DW 时差线 测向线
  298. btnDrawDto.Visibility = btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  299. btnGDOP.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  300. break;
  301. case EnumPosType.X3TwoDto:
  302. //三星双时差DW GDOP 时差线
  303. btnDrawDto.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  304. btnDrawCX.Visibility = btnDrawDfo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  305. break;
  306. case EnumPosType.X3TwoDfo:
  307. //三星双频差DW GDOP 频差线
  308. btnDrawDfo.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  309. btnDrawDto.Visibility = btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  310. break;
  311. case EnumPosType.X2Dfo:
  312. //双星时频差DW GDOP 时频差线
  313. btnDrawDto.Visibility = btnDrawDfo.Visibility = btnGDOP.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  314. btnDrawCX.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  315. break;
  316. default:
  317. break;
  318. }
  319. popupMenu2.ShowPopup(MousePosition);
  320. }
  321. private async void layoutControlGroup1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
  322. {
  323. var txt = (e.Button as GroupBoxButton).Caption;
  324. if (txt == "新建任务")
  325. {
  326. try
  327. {
  328. TaskEditor frm = new TaskEditor();
  329. if (frm.ShowDialog() != DialogResult.OK) return;
  330. var addItem = frm.info;
  331. using (RHDWContext db = new RHDWContext())
  332. {
  333. if (await db.TaskInfos.AnyAsync(p => p.TaskName == addItem.TaskName))
  334. {
  335. DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  336. return;
  337. }
  338. db.TaskInfos.Add(addItem);
  339. await db.SaveChangesAsync();
  340. }
  341. list.Insert(0, addItem);
  342. gridView1.RefreshData();
  343. gridView1.FocusedRowHandle = 0;
  344. }
  345. catch (Exception ex)
  346. {
  347. Serilog.Log.Error(ex, "保存任务异常");
  348. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  349. }
  350. }
  351. else if (txt == "编辑任务")
  352. {
  353. try
  354. {
  355. var editItem = gridView1.GetFocusedRow() as TaskInfo;
  356. TaskEditor frm = new TaskEditor(editItem);
  357. if (frm.ShowDialog() != DialogResult.OK) return;
  358. editItem = frm.info;
  359. using (RHDWContext db = new RHDWContext())
  360. {
  361. if (await db.TaskInfos.AnyAsync(p => p.ID != editItem.ID && p.TaskName == editItem.TaskName))
  362. {
  363. DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  364. return;
  365. }
  366. var find = await db.TaskInfos.Where(p => p.ID == editItem.ID).FirstOrDefaultAsync();
  367. find.TaskName = editItem.TaskName;
  368. find.PosType = editItem.PosType;
  369. await db.SaveChangesAsync();
  370. }
  371. gridView1.RefreshData();
  372. }
  373. catch (Exception ex)
  374. {
  375. Serilog.Log.Error(ex, "保存任务异常");
  376. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  377. }
  378. }
  379. else
  380. {
  381. try
  382. {
  383. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  384. if (tsk == null) return;
  385. if (!DxHelper.MsgBoxHelper.ShowConfirm($"删除任务[{tsk.TaskName}]?"))
  386. return;
  387. using (RHDWContext db = new RHDWContext())
  388. {
  389. var item = db.TaskInfos.FirstOrDefault(p => p.ID == tsk.ID);
  390. db.TaskInfos.Remove(item);
  391. db.SaveChanges();
  392. }
  393. gridView1.DeleteSelectedRows();
  394. }
  395. catch (Exception ex)
  396. {
  397. Serilog.Log.Error(ex, "删除任务异常");
  398. DxHelper.MsgBoxHelper.ShowError("删除任务异常");
  399. }
  400. }
  401. }
  402. IDisposable httpServer;
  403. private async void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  404. {
  405. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  406. if (e.Item.Caption == "启动任务")
  407. {
  408. try
  409. {
  410. using (RHDWContext db = new RHDWContext())
  411. {
  412. var find = await db.TaskInfos.FirstOrDefaultAsync(p => p.TaskState == EnumTaskState.Running && p.PosType == tsk.PosType);
  413. if (find != null)
  414. {
  415. var field = typeof(EnumPosType).GetField(Enum.GetName(typeof(EnumPosType), find.PosType));
  416. DxHelper.MsgBoxHelper.ShowWarning($"已经有一个[{field.GetCustomAttribute<DisplayAttribute>().Name}]任务正在执行,请先停止!");
  417. return;
  418. }
  419. var settings = await db.SysSetings.FirstOrDefaultAsync();
  420. if (settings == null)
  421. {
  422. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP端口信息");
  423. return;
  424. }
  425. if (httpServer == null)
  426. {
  427. try
  428. {
  429. StartOptions options = new StartOptions();
  430. options.Urls.Add($"http://+:{settings.HttpPort}");
  431. httpServer = WebApp.Start<Startup>(options);
  432. }
  433. catch (Exception ex)
  434. {
  435. Serilog.Log.Error(ex, "启动任务异常,Http定位接口服务启动失败");
  436. DxHelper.MsgBoxHelper.ShowError($"启动任务异常,Http定位接口服务启动失败");
  437. }
  438. }
  439. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  440. item.TaskState = EnumTaskState.Running;
  441. await db.SaveChangesAsync();
  442. tsk.TaskState = EnumTaskState.Running;
  443. Serilog.Log.Information($"用户启动了任务,ID={tsk.ID}");
  444. }
  445. }
  446. catch (Exception ex)
  447. {
  448. Serilog.Log.Error(ex, "启动任务异常");
  449. DxHelper.MsgBoxHelper.ShowError($"启动任务异常.{ex.Message}");
  450. }
  451. }
  452. else
  453. {
  454. try
  455. {
  456. using (RHDWContext db = new RHDWContext())
  457. {
  458. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  459. item.TaskState = EnumTaskState.Stopped;
  460. await db.SaveChangesAsync();
  461. //if (!db.TaskInfos.Any(p => p.TaskState == EnumTaskState.Running))
  462. //{
  463. // server?.StopListening();
  464. // server = null;
  465. //}
  466. }
  467. tsk.TaskState = EnumTaskState.Stopped;
  468. Serilog.Log.Information($"用户停止了任务,ID={tsk.ID}");
  469. }
  470. catch (Exception ex)
  471. {
  472. Serilog.Log.Error(ex, "停止任务异常");
  473. DxHelper.MsgBoxHelper.ShowError($"停止任务异常.{ex.Message}");
  474. }
  475. }
  476. gridView1.RefreshData();
  477. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  478. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  479. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  480. }
  481. private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
  482. {
  483. if (gridView1.RowCount == 0)
  484. {
  485. string txt = "点击+创建任务";
  486. var s = e.Appearance.CalcTextSize(e.Cache, txt, e.Bounds.Width).ToSize();
  487. var x = (e.Bounds.Width - s.Width) / 2;
  488. var y = (e.Bounds.Height - s.Height) / 2;
  489. //e.Appearance.DrawString(e.Cache, txt, new Rectangle(x,y,s.Width,s.Height));
  490. e.DrawHtml(htmlTemplate1);
  491. }
  492. }
  493. private async void btnDelPos_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  494. {
  495. try
  496. {
  497. var ids = gridView2.GetSelectedRows();
  498. using (RHDWContext db = new RHDWContext())
  499. {
  500. foreach (var id in ids)
  501. {
  502. var item = gridView2.GetRow(id) as PosRes;
  503. var delItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  504. if (delItem != null)
  505. {
  506. db.PosRes.Remove(delItem);
  507. mapControl1.DelPosItem<PosRes>(item);
  508. }
  509. }
  510. await db.SaveChangesAsync();
  511. }
  512. gridView2.DeleteSelectedRows();
  513. }
  514. catch (Exception ex)
  515. {
  516. Serilog.Log.Error(ex, "删除定位结果异常");
  517. DxHelper.MsgBoxHelper.ShowError("删除定位结果异常");
  518. }
  519. }
  520. private void gridView2_RowClick(object sender, RowClickEventArgs e)
  521. {
  522. var p = gridView2.GetFocusedRow() as PosRes;
  523. p.Selected = true;
  524. mapControl1.UpdatePosItem(p);
  525. }
  526. private async void btnTar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  527. {
  528. try
  529. {
  530. var ids = gridView2.GetSelectedRows();
  531. if (ids.Length <= 0) return;
  532. var fisrtitem = gridView2.GetRow(ids[0]) as PosRes;
  533. EditorTar frm = new EditorTar(new TargetInfo() { ID = fisrtitem.TargetID.HasValue ? fisrtitem.TargetID.Value : 0, TargetName = fisrtitem.TarName });
  534. if (frm.ShowDialog() != DialogResult.OK) return;
  535. var tar = frm.info;
  536. using (RHDWContext db = new RHDWContext())
  537. {
  538. foreach (var id in ids)
  539. {
  540. var item = gridView2.GetRow(id) as PosRes;
  541. var tarItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  542. if (tarItem != null)
  543. {
  544. item.TargetID = tarItem.TargetID = tar.ID;
  545. item.TarName = tarItem.TarName = tar.TargetName;
  546. }
  547. }
  548. await db.SaveChangesAsync();
  549. }
  550. }
  551. catch (Exception ex)
  552. {
  553. Serilog.Log.Error(ex, "编辑定位目标异常");
  554. DxHelper.MsgBoxHelper.ShowError("编辑定位目标异常");
  555. }
  556. }
  557. private void btnDrawDto_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  558. {
  559. var info = GetPosRes("绘制时差");
  560. var posRes = info.Item1;
  561. if (posRes == null) return;
  562. var posType = info.Item2;
  563. DrawDtoLine(posRes, posType);
  564. }
  565. private (PosRes, EnumPosType) GetPosRes(string msg)
  566. {
  567. var ids = gridView2.GetSelectedRows();
  568. if (ids.Length <= 0)
  569. {
  570. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要{msg}的定位数据信息!");
  571. return (null, default);
  572. }
  573. var item = gridView2.GetRow(ids[0]) as PosRes;
  574. var taskInfo = list.Find(m => m.ID == item.TaskInfoID);
  575. if (taskInfo == null)
  576. {
  577. DxHelper.MsgBoxHelper.ShowWarning($"{msg}未找到任务[{item.TaskInfoID}]!");
  578. return (null, default);
  579. }
  580. return (item, taskInfo.PosType);
  581. }
  582. private EnumPosType GetPosRes(PosRes posRes, string msg)
  583. {
  584. var taskInfo = list.Find(m => m.ID == posRes.TaskInfoID);
  585. if (taskInfo == null)
  586. {
  587. DxHelper.MsgBoxHelper.ShowWarning($"{msg}未找到任务[{posRes.TaskInfoID}]!");
  588. return default;
  589. }
  590. return taskInfo.PosType;
  591. }
  592. private void btnDrawDfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  593. {
  594. var info = GetPosRes("绘制频差");
  595. var posRes = info.Item1;
  596. if (posRes == null) return;
  597. var posType = info.Item2;
  598. DrawDfoLine(posRes, posType);
  599. }
  600. private void btnDrawCX_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  601. {
  602. var ids = gridView2.GetSelectedRows();
  603. if (ids.Length <= 0)
  604. {
  605. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要绘制测向线的定位数据信息!");
  606. return;
  607. }
  608. var item = gridView2.GetRow(ids[0]) as PosRes;
  609. DrawCXLine(item);
  610. }
  611. private void btnGDOP_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  612. {
  613. var info = GetPosRes("绘制GDOP");
  614. var posRes = info.Item1;
  615. if (posRes == null) return;
  616. var posType = info.Item2;
  617. DrawGDOP(posRes, posType);
  618. }
  619. private void DrawGDOP(PosRes item, EnumPosType posType)
  620. {
  621. try
  622. {
  623. switch (posType)
  624. {
  625. //case EnumPosType.X1D1CX:
  626. // X1D1GDOPParam x1D1GdopParam = new X1D1GDOPParam(item);
  627. // x1D1GdopParam.mapControl1 = mapControl1;
  628. // DxHelper.PopupHelper.ShowPopup(x1D1GdopParam, mapControl1, mapControl1.Width / 4);
  629. // break;
  630. //case EnumPosType.X2D1:
  631. // X2D1GDOPParam x2D1GdopParam = new X2D1GDOPParam(item);
  632. // x2D1GdopParam.mapControl1 = mapControl1;
  633. // DxHelper.PopupHelper.ShowPopup(x2D1GdopParam, mapControl1, mapControl1.Width / 4);
  634. // break;
  635. //case EnumPosType.X3TwoDto:
  636. // X3GDOPParam x3GdopParam = new X3GDOPParam(item);
  637. // x3GdopParam.mapControl1 = mapControl1;
  638. // DxHelper.PopupHelper.ShowPopup(x3GdopParam, mapControl1, mapControl1.Width / 4);
  639. // break;
  640. //case EnumPosType.X3TwoDfo:
  641. // X3DFGDOPParam x3DFGdopParam = new X3DFGDOPParam(item);
  642. // x3DFGdopParam.mapControl1 = mapControl1;
  643. // DxHelper.PopupHelper.ShowPopup(x3DFGdopParam, mapControl1, mapControl1.Width / 4);
  644. // break;
  645. //case EnumPosType.X2Dfo:
  646. // X2DFGDOPParam x2DFGdopParam = new X2DFGDOPParam(item);
  647. // x2DFGdopParam.mapControl1 = mapControl1;
  648. // DxHelper.PopupHelper.ShowPopup(x2DFGdopParam, mapControl1, mapControl1.Width / 4);
  649. // break;
  650. //default:
  651. // break;
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. DxHelper.MsgBoxHelper.ShowWarning($"绘制{posType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
  657. }
  658. }
  659. private void DrawDtoLine(PosRes item, EnumPosType posType)
  660. {
  661. switch (posType)
  662. {
  663. case EnumPosType.X1D1CX:
  664. case EnumPosType.X2D1:
  665. DrawXDtoLine(item, posType);
  666. break;
  667. case EnumPosType.RH:
  668. DrawXDtoLine(item, EnumPosType.X1D1CX);
  669. DrawXDtoLine(item, EnumPosType.X2D1);
  670. break;
  671. case EnumPosType.X3TwoDto:
  672. case EnumPosType.X2Dfo:
  673. DrawX3toLine(item, posType);
  674. break;
  675. default:
  676. break;
  677. }
  678. }
  679. private async void DrawXDtoLine(PosRes item, EnumPosType posType)
  680. {
  681. try
  682. {
  683. StationRes station;
  684. List<SatInfo> listSat = new List<SatInfo>();
  685. CgRes cg;
  686. using (RHDWContext db = new RHDWContext())
  687. {
  688. listSat = db.SatInfos.ToList();
  689. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  690. station = await db.StationRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  691. }
  692. if (cg == null)
  693. {
  694. DxHelper.MsgBoxHelper.ShowWarning($"未找到定位相关的计算[{item.CgResID}]信息");
  695. return;
  696. }
  697. if (station == null)
  698. {
  699. DxHelper.MsgBoxHelper.ShowWarning($"站点信息为空!");
  700. return;
  701. }
  702. if (station.SatTxLon == 0 || station.SatTxLat == 0)
  703. {
  704. DxHelper.MsgBoxHelper.ShowWarning($"天线信息为空!");
  705. return;
  706. }
  707. if (station.CdbTxLon == 0 || station.CdbTxLat == 0)
  708. {
  709. DxHelper.MsgBoxHelper.ShowWarning($"超短波信息为空!");
  710. return;
  711. }
  712. if (station.RefLon == 0 || station.RefLat == 0)
  713. {
  714. DxHelper.MsgBoxHelper.ShowWarning($"参考站信息为空!");
  715. return;
  716. }
  717. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  718. dtoLineXd.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, 0, 0, 0 };
  719. dtoLineXd.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  720. dtoLineXd.CDBAnt = new double[] { station.CdbTxLon.Value, station.CdbTxLat.Value, 0 };
  721. dtoLineXd.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  722. dtoLineXd.xdDto = cg.DtoCdb.Value;
  723. dtoLineXd.RefDto = cg.YbMainDto.Value;
  724. dtoLineXd.PosLon = item.PosLon;
  725. dtoLineXd.PosLat = item.PosLat;
  726. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  727. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  728. mapControl1.DrawDtoPonit($"星地[{msat},[{station.CdbTxLon}°]]时差线", xdDtoLine);
  729. if (posType == EnumPosType.X2D1)
  730. {
  731. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  732. twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, 0, 0, 0 };
  733. twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, 0, 0, 0 };
  734. twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  735. twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  736. twoStartOption.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  737. twoStartOption.TargetDto = cg.Dto1.Value;
  738. twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja1Dto.Value;
  739. twoStartOption.PosLon = item.PosLon;
  740. twoStartOption.PosLat = item.PosLat;
  741. var tsDtoLine = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
  742. mapControl1.DrawDtoPonit($"双星[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat}]时差线", tsDtoLine);
  743. }
  744. }
  745. catch (Exception ex)
  746. {
  747. Serilog.Log.Error($"绘制{posType.GetEnumDisplayName()}时差线失败", ex);
  748. DxHelper.MsgBoxHelper.ShowWarning($"绘制{posType.GetEnumDisplayName()}时差线失败,失败信息:{ex.Message}");
  749. }
  750. }
  751. private async void DrawX3toLine(PosRes item, EnumPosType posType)
  752. {
  753. try
  754. {
  755. StationRes station;
  756. List<SatInfo> listSat = new List<SatInfo>();
  757. CgRes cg;
  758. using (RHDWContext db = new RHDWContext())
  759. {
  760. listSat = db.SatInfos.ToList();
  761. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  762. station = await db.StationRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  763. }
  764. if (cg == null)
  765. {
  766. DxHelper.MsgBoxHelper.ShowWarning($"未找到定位相关的计算[{item.CgResID}]信息");
  767. return;
  768. }
  769. if (station == null)
  770. {
  771. DxHelper.MsgBoxHelper.ShowWarning($"站点信息为空!");
  772. return;
  773. }
  774. if (station.RefLon == 0 || station.RefLat == 0)
  775. {
  776. DxHelper.MsgBoxHelper.ShowWarning($"参考站信息为空!");
  777. return;
  778. }
  779. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  780. twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, 0, 0, 0 };
  781. twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, 0, 0, 0 };
  782. twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  783. twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  784. twoStartOption.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  785. twoStartOption.TargetDto = cg.Dto1.Value;
  786. twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja1Dto.Value;
  787. twoStartOption.PosLon = item.PosLon;
  788. twoStartOption.PosLat = item.PosLat;
  789. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  790. var tsDtoLine = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
  791. mapControl1.DrawDtoPonit($"{posType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat}]时差线", tsDtoLine);
  792. if (posType == EnumPosType.X3TwoDto)
  793. {
  794. twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, 0, 0, 0 };
  795. twoStartOption.TargetDto = cg.Dto2.Value;
  796. twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja2Dto.Value;
  797. twoStartOption.PosLon = item.PosLon;
  798. twoStartOption.PosLat = item.PosLat;
  799. var tsDtoLine1 = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
  800. mapControl1.DrawDtoPonit($"{posType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat}]时差线", tsDtoLine1);
  801. }
  802. }
  803. catch (Exception ex)
  804. {
  805. Serilog.Log.Error($"绘制{posType.GetEnumDisplayName()}时差线失败", ex);
  806. DxHelper.MsgBoxHelper.ShowWarning($"绘制{posType.GetEnumDisplayName()}时差线失败,失败信息:{ex.Message}");
  807. }
  808. }
  809. private void DrawDfoLine(PosRes item, EnumPosType posType)
  810. {
  811. switch (posType)
  812. {
  813. case EnumPosType.X3TwoDfo:
  814. case EnumPosType.X2Dfo:
  815. DrawX3DfoLine(item, posType);
  816. break;
  817. default:
  818. break;
  819. }
  820. }
  821. private async void DrawX3DfoLine(PosRes item, EnumPosType posType)
  822. {
  823. try
  824. {
  825. StationRes station;
  826. List<SatInfo> listSat = new List<SatInfo>();
  827. CgRes cg;
  828. using (RHDWContext db = new RHDWContext())
  829. {
  830. listSat = db.SatInfos.ToList();
  831. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  832. station = await db.StationRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  833. }
  834. if (cg == null)
  835. {
  836. DxHelper.MsgBoxHelper.ShowWarning($"未找到定位相关的计算[{item.CgResID}]信息");
  837. return;
  838. }
  839. if (station == null)
  840. {
  841. DxHelper.MsgBoxHelper.ShowWarning($"站点信息为空!");
  842. return;
  843. }
  844. if (station.SatTxLon == 0 || station.SatTxLat == 0)
  845. {
  846. DxHelper.MsgBoxHelper.ShowWarning($"天线信息为空!");
  847. return;
  848. }
  849. if (station.RefLon == 0 || station.RefLat == 0)
  850. {
  851. DxHelper.MsgBoxHelper.ShowWarning($"参考站信息为空!");
  852. return;
  853. }
  854. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  855. twoStartOption.Freq = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value : 0;
  856. twoStartOption.RefFreq = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value : 0;
  857. twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, cg.MainVx.Value, cg.MainVy.Value, cg.MainVz.Value };
  858. twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, cg.Adja1Vx.Value, cg.Adja1Vy.Value, cg.Adja1Vz.Value };
  859. twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  860. twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  861. twoStartOption.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  862. twoStartOption.TargetDfo = cg.Dfo1.Value;
  863. twoStartOption.Turn1 = Math.Abs(twoStartOption.Freq - (cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value : 0));
  864. twoStartOption.Turn2 = Math.Abs(twoStartOption.RefFreq - (cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value : 0));
  865. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja1Dfo.Value;
  866. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  867. var tsDtoLine = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  868. mapControl1.DrawDtoPonit($"{posType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja1X.Value)?.Sat}]频差线", tsDtoLine);
  869. if (posType == EnumPosType.X3TwoDfo)
  870. {
  871. twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, cg.Adja2Vx.Value, cg.Adja2Vy.Value, cg.Adja2Vz.Value };
  872. twoStartOption.TargetDfo = cg.Dfo2.Value;
  873. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja2Dfo.Value;
  874. var tsDtoLine1 = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  875. mapControl1.DrawDtoPonit($"{posType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat}]频差线", tsDtoLine1);
  876. }
  877. }
  878. catch (Exception ex)
  879. {
  880. Serilog.Log.Error($"绘制{posType.GetEnumDisplayName()}频差线失败", ex);
  881. DxHelper.MsgBoxHelper.ShowWarning($"绘制{posType.GetEnumDisplayName()}频差线失败,失败信息:{ex.Message}");
  882. }
  883. }
  884. private async void DrawCXLine(PosRes item)
  885. {
  886. if (!item.CxResID.HasValue)
  887. {
  888. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线未有测向编号!");
  889. return;
  890. }
  891. try
  892. {
  893. CxRes cx;
  894. StationRes station;
  895. using (RHDWContext db = new RHDWContext())
  896. {
  897. cx = await db.CxRes.Where(m => m.ID == item.CxResID.Value).FirstOrDefaultAsync();
  898. station = await db.StationRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  899. }
  900. if (cx == null)
  901. {
  902. DxHelper.MsgBoxHelper.ShowWarning($"未找到定位相关的测向[{item.CxResID.Value}]信息");
  903. return;
  904. }
  905. if (station == null)
  906. {
  907. DxHelper.MsgBoxHelper.ShowWarning($"站点信息为空!");
  908. return;
  909. }
  910. if (station.CxLon == 0 || station.CxLat == 0)
  911. {
  912. DxHelper.MsgBoxHelper.ShowWarning($"测向站信息为空!");
  913. return;
  914. }
  915. double startdeg = 360;
  916. double deg = startdeg - cx.Fx;//向北顺时针方向为夹角
  917. //计算测向站到定位点之间的距离
  918. var km = MapControlEx.CalcLineKm(station.CxLon.Value, station.CxLat.Value, item.PosLon, item.PosLat);
  919. var endpoint = MapControlEx.CalcSituation(station.CxLon.Value, station.CxLat.Value, deg, (km + 100) * 1000);
  920. List<(double, double)> points = new List<(double, double)>();
  921. points.Add((station.CxLon.Value, station.CxLat.Value));
  922. points.Add((endpoint.Item1, endpoint.Item2));
  923. mapControl1.DrawCXLine($"测向线角度:{cx.Fx}°\t\n", points);
  924. }
  925. catch (Exception ex)
  926. {
  927. Serilog.Log.Error($"绘制测向线失败", ex);
  928. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败,失败信息:{ex.Message}");
  929. }
  930. }
  931. }
  932. }