CtrlHome.cs 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  1. using DevExpress.Mvvm.Native;
  2. using DevExpress.Office.Crypto;
  3. using DevExpress.Utils;
  4. using DevExpress.Utils.Drawing;
  5. using DevExpress.Utils.Svg;
  6. using DevExpress.XtraEditors.ButtonsPanelControl;
  7. using DevExpress.XtraEditors.Controls;
  8. using DevExpress.XtraGrid.Views.Grid;
  9. using DPP_YH_Core.Extensions;
  10. using DxHelper;
  11. using ExtensionsDev;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Configuration;
  15. using System.Data.Entity;
  16. using System.Data.Entity.Migrations;
  17. using System.Drawing;
  18. using System.Linq;
  19. using System.Net;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. using System.Windows.Forms;
  23. using XdCxRhDW.Api;
  24. using XdCxRhDW.App.EditForms;
  25. using XdCxRhDW.App.Model;
  26. using XdCxRhDW.App.PopupControl;
  27. using XdCxRhDW.Dto;
  28. using XdCxRhDW.Entity;
  29. using XdCxRhDW.Repostory;
  30. using XdCxRhDW.WebApi;
  31. namespace XdCxRhDW.App.UserControl
  32. {
  33. public partial class CtrlHome : DevExpress.XtraEditors.XtraUserControl
  34. {
  35. List<TaskInfo> list = new List<TaskInfo>();
  36. TaskInfo tsk;
  37. List<CancellationTokenSource> listCts = new List<CancellationTokenSource>();
  38. public CtrlHome()
  39. {
  40. InitializeComponent();
  41. layoutControl1.UseDefault();
  42. if (this.splitterItem1.Location.X < 200)
  43. this.splitterItem1.Location = new Point(200, 0);
  44. txtStartTime.UseDefault();
  45. txtEndTime.UseDefault();
  46. }
  47. private async void CtrlHome_Load(object sender, EventArgs e)
  48. {
  49. Messenger.Defalut.Sub<ModelPosRes>("新增定位点", OnPosAdd);
  50. Messenger.Defalut.Sub<SysSetings>("地图类型改变", OnSysSetingsChanged);
  51. Messenger.Defalut.Sub<int>("任务状态改变", async id =>
  52. {
  53. var find = list.FirstOrDefault(p => p.ID == id);
  54. if (find == null) return;
  55. using (RHDWContext db = new RHDWContext())
  56. {
  57. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == id);
  58. if (item == null) return;
  59. find.TaskState = item.TaskState;
  60. }
  61. this.gridView1.RefreshData();
  62. if (tsk.ID != id) return;
  63. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  64. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  65. this.Invoke(new Action(() =>
  66. {
  67. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  68. }));
  69. });
  70. gridHomeTask.UseDefault(list, showScrollH: true).UseEmptyText("点击+创建任务");
  71. gridView1.BestFitColumns();
  72. gridHomePosRes.UseDefault(new List<ModelPosRes>()).UseMultiSelect().UseRowNumber().UseNullValueText()
  73. .AddRowMenu<ModelPosRes>("绘制时差线", SvgHelper.CreateDtoLine(), DrawDtoLine, item => item.PosResType != EnumPosResType.RH)
  74. .AddRowMenuAsync<ModelPosRes>("绘制频差线", SvgHelper.CreateDfoLine(), DrawDfoLine, item => item.PosResType == EnumPosResType.X2Dfo || item.PosResType == EnumPosResType.X3TwoDfo)
  75. .AddRowMenuAsync<ModelPosRes>("绘制测向线", SvgHelper.CreateDfoLine(), DrawCxLine, item => item.PosResType == EnumPosResType.X1D1CX || item.PosResType == EnumPosResType.RH)
  76. .AddRowMenu<ModelPosRes>("GDOP分析", SvgHelper.CreateGDOP(), DrawGdopLine, item => item.PosResType != EnumPosResType.RH)
  77. .AddRowMenu<ModelPosRes>("查看参估", SvgHelper.CreateShowCafRes(), ShowCafRes)
  78. .AddRowMenu<ModelPosRes>("查看测向", SvgHelper.CreateShowCxRes(), ShowCxRes)
  79. .AddRowMenu<ModelPosRes>("查看检测", SvgHelper.CreateShowCheckRes(), ShowCheckRes, item => item.PosResType == EnumPosResType.X1D1CX || item.PosResType == EnumPosResType.RH)
  80. .AddRowMenu<ModelPosRes>("手动定位", SvgHelper.CreatePosManual(), PosManual)
  81. .AddContentMenu<ModelPosRes>("重新定位", SvgHelper.CreateRepos(), Repos, true)
  82. .UseDeleteAsync<ModelPosRes>(DelPos, "删除记录")
  83. .SetDisplayText(nameof(ModelPosRes.FreqUpHz), val => (Convert.ToInt64(val) / 1e6).ToString("f3"))
  84. .MountRowMenuToMapPos<ModelPosRes>(mapControl1)//将表格单行元素菜单挂载到定位点上(实验)
  85. .MountMultRowMenuToMapRegion(mapControl1); //将表格多行元素菜单挂载到地图区域菜单上(该功能暂未实现)
  86. //mapService = "http://ows.mundialis.de/services/service";
  87. mapControl1.UseDefalutOptions()
  88. //.UseCluster()//定位点使用内置聚合
  89. .UseDrawRect()
  90. .UseClearAll()
  91. .UseDistanceLine()
  92. .UseMarkDot()
  93. .UseTrack()
  94. .UseExportImg()
  95. .UseExportXlsx();
  96. if (SysConfig.Config == null)
  97. {
  98. mapControl1.UseLocalDb();
  99. return;
  100. }
  101. OnSysSetingsChanged(SysConfig.Config);
  102. gridView1.FocusedRowObjectChanged += GridView1_FocusedRowObjectChanged;
  103. gridView2.FocusedRowObjectChanged += GridView2_FocusedRowObjectChanged;
  104. btnIncludeInvalidate.CheckedChanged += BtnIncludeInvalidate_CheckedChanged;
  105. try
  106. {
  107. List<TxInfo> txList = new List<TxInfo>();
  108. using (RHDWContext db = new RHDWContext())
  109. {
  110. var tasks = db.TaskInfos.OrderByDescending(p => p.UpdateTime).ToList();
  111. list.AddRange(tasks);
  112. var runningList = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running).ToListAsync();
  113. foreach (var item in runningList)
  114. {
  115. item.TaskState = EnumTaskState.Stopped;
  116. }
  117. await db.SaveChangesAsync();
  118. var satres = db.SatInfos.OrderBy(p => p.SatName).OrderBy(p => p.SatName);
  119. var txres = await db.TxInfos.ToListAsync();
  120. txList.AddRange(txres);
  121. }
  122. mapControl1.AddRectMenu<ModelPosRes>("删除定位点", SvgHelper.CreateClose(), async items => await DeletePosRes(items.ToList()))
  123. .AddRectMenu<ModelPosRes>("使用镜像点", SvgHelper.CreateUseMirr(), async items => await UseMirr(items.ToList()))
  124. .AddRectMenu<ModelPosRes>("编辑目标", SvgHelper.CreateEdit(), async items => await EditTarget(items.ToList()))
  125. .AddRectMenu<ModelPosRes>("转到列表", SvgHelper.CreateGoto(),
  126. items => ToPosList(items.ToList()));
  127. }
  128. catch (Exception ex)
  129. {
  130. Serilog.Log.Error(ex, "加载基础信息异常");
  131. DxHelper.MsgBoxHelper.ShowError("加载基础信息异常");
  132. }
  133. gridView1.Columns[nameof(TaskInfo.TaskName)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  134. this.svgImageCollection1.Add("Stopped", SvgHelper.CreateCycle("#1E8B58"));
  135. this.svgImageCollection1.Add("Running", SvgHelper.CreateCycle("#2E8B57"));
  136. gridView1.CustomDrawCell += GridView1_CustomDrawCell;
  137. gridView1.DoubleClick += GridView1_DoubleClick;
  138. txtTimeCho_SelectedIndexChanged(null, null);
  139. WaitHelper.CloseForm();
  140. }
  141. private void OnSysSetingsChanged(SysSetings settings)
  142. {
  143. if (settings.MapType == 0)
  144. mapControl1.UseLocalDb();
  145. else
  146. {
  147. string url = null;
  148. try
  149. {
  150. if (settings.WmtsSource == EnumWmtsSource.ZCJ)
  151. {
  152. url = ConfigurationManager.AppSettings["ZCJ_URL"].Trim();
  153. }
  154. else
  155. {
  156. url = ConfigurationManager.AppSettings["SJZX_URL"].Trim();
  157. }
  158. if (url.EndsWith("/"))
  159. url = url.Substring(0, url.Length - 1);
  160. mapControl1.UseWMTS(url, settings.WmtsSource, settings.MapLayerType);
  161. }
  162. catch (Exception ex)
  163. {
  164. mapControl1.UseLocalDb();
  165. Serilog.Log.Error(ex, $"MapControl使用WMTS出现异常,强制使用本地地图.url={url}");
  166. }
  167. }
  168. }
  169. private void OnPosAdd(ModelPosRes posRes)
  170. {
  171. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  172. if (currentTask.ID == posRes.TaskInfoID)
  173. {
  174. var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
  175. ds.Insert(0, posRes);
  176. this.Invoke(new Action(() =>
  177. {
  178. gridView2.RefreshData();
  179. mapControl1.AddPosItem(posRes);
  180. }));
  181. }
  182. }
  183. private async void GridView1_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
  184. {
  185. listCts.ForEach(t => t.Cancel());
  186. listCts.Clear();
  187. var cts = new CancellationTokenSource();
  188. listCts.Add(cts);
  189. mapControl1.DelFixedImg("Sat");
  190. mapControl1.DelFixedImg("Tx");
  191. tsk = (e.Row as TaskInfo);
  192. if (tsk == null) return;
  193. if (tsk.PosType == EnumPosType.X1D1CX || tsk.PosType == EnumPosType.RH)
  194. {
  195. gridView2.Columns[nameof(ModelPosRes.CxResID)].Visible = true;
  196. }
  197. else
  198. {
  199. gridView2.Columns[nameof(ModelPosRes.CxResID)].Visible = false;
  200. }
  201. using (RHDWContext db = new RHDWContext())
  202. {
  203. this.txtFrequpMHz.Properties.Items.Clear();
  204. this.txtFrequpMHz.Properties.Items.Add(new ImageComboBoxItem("全部", null));
  205. var sigs = await db.TaskSigs.Where(w => w.TaskInfoID == tsk.ID).ToListAsync();
  206. foreach (var item in sigs)
  207. {
  208. this.txtFrequpMHz.Properties.Items.Add(new ImageComboBoxItem((item.FreqUp / 1e6).ToString("f3"), item.FreqUp));
  209. }
  210. }
  211. txtFrequpMHz.SelectedIndex = 0;
  212. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  213. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  214. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  215. List<ModelPosRes> listPos = null;
  216. if (txtTimeCho.Text == "自定义" && (txtStartTime.EditValue == null || txtEndTime.EditValue == null || txtStartTime.DateTime > txtEndTime.DateTime))
  217. {
  218. listPos = new List<ModelPosRes>();
  219. this.gridHomePosRes.DataSource = listPos;
  220. mapControl1.SetPosDataSource(listPos);
  221. }
  222. else
  223. {
  224. listPos = await searchPos(cts.Token);
  225. this.gridHomePosRes.DataSource = listPos;
  226. mapControl1.SetPosDataSource(listPos);
  227. }
  228. using (RHDWContext db = new RHDWContext())
  229. {
  230. var sat1 = db.SatInfos.Where(p => p.SatCode == tsk.MainSat).FirstOrDefault();
  231. var sat2 = db.SatInfos.Where(p => p.SatCode == tsk.Adja1Sat).FirstOrDefault();
  232. var sat3 = db.SatInfos.Where(p => p.SatCode == tsk.Adja2Sat).FirstOrDefault();
  233. if (sat1 != null && sat1.SatLon != null)
  234. mapControl1.DrawFixedImg("Sat", 0, sat1.SatLon.Value, DxHelper.SvgHelper.CreateSat(width: 16, height: 16), $"主星\r\n{sat1.Sat}");
  235. if (sat2 != null && sat2.SatLon != null)
  236. mapControl1.DrawFixedImg("Sat", 0, sat2.SatLon.Value, DxHelper.SvgHelper.CreateSat(width: 16, height: 16), $"邻1星\r\n{sat2.Sat}");
  237. if (sat3 != null && sat3.SatLon != null)
  238. mapControl1.DrawFixedImg("Sat", 0, sat3.SatLon.Value, DxHelper.SvgHelper.CreateSat(width: 16, height: 16), $"邻2星\r\n{sat3.Sat}");
  239. }
  240. }
  241. private void GridView1_DoubleClick(object sender, EventArgs e)
  242. {
  243. layoutControlGroup1_CustomButtonClick(null, new DevExpress.XtraBars.Docking2010.BaseButtonEventArgs(new GroupBoxButton() { Caption = "编辑任务" }));
  244. }
  245. private void GridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  246. {
  247. if (e.Column.FieldName == nameof(TaskInfo.TaskName) && (EnumTaskState)gridView1.GetRowCellValue(e.RowHandle, nameof(TaskInfo.TaskState)) == EnumTaskState.Running)
  248. {
  249. var palette = SvgPaletteHelper.GetSvgPalette(this.LookAndFeel, ObjectState.Normal);
  250. 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);
  251. Rectangle txtBounds = e.Bounds;
  252. txtBounds.Width -= 24;
  253. txtBounds.X += 24;
  254. e.Appearance.DrawString(e.Cache, e.DisplayText, txtBounds);
  255. e.Handled = true;
  256. }
  257. }
  258. private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
  259. {
  260. if (gridView1.FocusedRowHandle < 0) return;
  261. var state = (EnumTaskState)gridView1.GetFocusedRowCellValue(nameof(TaskInfo.TaskState));
  262. btnStart.Enabled = state == EnumTaskState.Stopped;
  263. btnStop.Enabled = state == EnumTaskState.Running;
  264. popupMenu1.ShowPopup(MousePosition);
  265. }
  266. private void GridView2_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
  267. {
  268. mapControl1.DelFixedImg("Tx");
  269. var posItem = (e.Row as ModelPosRes);
  270. if (posItem == null) return;
  271. using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
  272. {
  273. var station = db?.StationRes.Where(p => p.ID == posItem.StationResID).FirstOrDefault();
  274. if (station != null)
  275. {
  276. mapControl1.DrawFixedImg("Tx", station.SatTxLat, station.SatTxLon, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[卫星接收天线]\r\n经度:{station.SatTxLon}°\r\n纬度:{station.SatTxLat}°");
  277. if (station.CdbTxLon != null)
  278. mapControl1.DrawFixedImg("Tx", station.CdbTxLat.Value, station.CdbTxLon.Value, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[超短接收天线]\r\n经度:{station.CdbTxLon.Value}°\r\n纬度:{station.CdbTxLat.Value}°");
  279. if (station.RefLon != null)
  280. mapControl1.DrawFixedImg("Tx", station.RefLat.Value, station.RefLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[参考站]\r\n经度:{station.RefLon.Value}°\r\n纬度:{station.RefLat.Value}°");
  281. if (station.CxLon != null)
  282. mapControl1.DrawFixedImg("Tx", station.CxLat.Value, station.CxLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[测向站]\r\n经度:{station.CxLon.Value}°\r\n纬度:{station.CxLat.Value}°");
  283. }
  284. }
  285. }
  286. private void gridView2_RowClick(object sender, RowClickEventArgs e)
  287. {
  288. var p = gridView2.GetFocusedRow() as ModelPosRes;
  289. p.Selected = true;
  290. mapControl1.UpdatePosItem(p, true);
  291. }
  292. private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
  293. {
  294. var hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition);
  295. if (hitInfo.RowHandle < 0 || hitInfo.Column == null || hitInfo.HitTest != DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitTest.RowCell)
  296. {
  297. toolTipController1.HideHint();
  298. return;
  299. }
  300. if (hitInfo.Column.FieldName == nameof(TaskInfo.TaskName))
  301. {
  302. var state = (EnumTaskState)gridView1.GetRowCellValue(hitInfo.RowHandle, nameof(TaskInfo.TaskState));
  303. if (state == EnumTaskState.Running)
  304. e.Info = new ToolTipControlInfo(hitInfo.RowHandle, "执行中");
  305. }
  306. }
  307. private async void layoutControlGroup1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
  308. {
  309. var txt = (e.Button as GroupBoxButton).Caption;
  310. if (txt == "新建任务")
  311. {
  312. try
  313. {
  314. TaskEditor frm = new TaskEditor();
  315. if (frm.ShowDialog() != DialogResult.OK) return;
  316. var addItem = frm.info;
  317. var addItemSignal = frm.selectedItem;
  318. using (RHDWContext db = new RHDWContext())
  319. {
  320. if (addItem.PosType == EnumPosType.X1D1CX)
  321. {
  322. addItem.Adja1Sat = null;
  323. addItem.Adja2Sat = null;
  324. }
  325. else if (addItem.PosType == EnumPosType.X2D1 || addItem.PosType == EnumPosType.X2Dfo || addItem.PosType == EnumPosType.RH)
  326. {
  327. addItem.Adja2Sat = null;
  328. }
  329. var taskInfo = db.TaskInfos.Add(addItem);
  330. List<TaskSig> sigList = new List<TaskSig>();
  331. foreach (var item in addItemSignal)
  332. {
  333. TaskSig taskSig = new TaskSig
  334. {
  335. TaskInfoID = taskInfo.ID,
  336. SigInfoID = item.ID,
  337. FreqUp = item.FreqUp,
  338. FreqDown = item.FreqDown,
  339. };
  340. sigList.Add(taskSig);
  341. }
  342. db.TaskSigs.AddRange(sigList);
  343. await db.SaveChangesAsync();
  344. }
  345. list.Insert(0, addItem);
  346. gridView1.RefreshData();
  347. gridView1.FocusedRowHandle = 0;
  348. }
  349. catch (Exception ex)
  350. {
  351. Serilog.Log.Error(ex, "保存任务异常");
  352. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  353. }
  354. }
  355. else if (txt == "编辑任务")
  356. {
  357. try
  358. {
  359. var editItem = gridView1.GetFocusedRow() as TaskInfo;
  360. if (editItem == null) return;
  361. using (RHDWContext db = new RHDWContext())
  362. {
  363. List<TaskSig> taskSig = await db.TaskSigs.Where(w => w.TaskInfoID == editItem.ID).ToListAsync();
  364. var taskSigID = taskSig.Select(s => s.SigInfoID);
  365. var items = await db.SigInfos.ToListAsync();
  366. var taskSigInfo = items.Where(w => taskSigID.Contains(w.ID)).ToList();
  367. TaskEditor frm = new TaskEditor(editItem, taskSigInfo);
  368. if (frm.ShowDialog() != DialogResult.OK) return;
  369. editItem = frm.info;
  370. List<SigInfo> editItemSig = frm.selectedItem;
  371. if (await db.TaskInfos.AnyAsync(p => p.ID != editItem.ID && p.TaskName == editItem.TaskName))
  372. {
  373. DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  374. return;
  375. }
  376. var find = await db.TaskInfos.Where(p => p.ID == editItem.ID).FirstOrDefaultAsync();
  377. find.TaskName = editItem.TaskName;
  378. find.PosType = editItem.PosType;
  379. find.UpdateTime = DateTime.Now;
  380. find.MainSat = editItem.MainSat;
  381. find.CapDir = editItem.CapDir;
  382. find.CapDirFormat = editItem.CapDirFormat;
  383. if (find.PosType == EnumPosType.X1D1CX)
  384. {
  385. find.Adja1Sat = null;
  386. find.Adja2Sat = null;
  387. }
  388. else if (find.PosType == EnumPosType.X2D1 || find.PosType == EnumPosType.X2Dfo || find.PosType == EnumPosType.RH)
  389. {
  390. find.Adja2Sat = null;
  391. }
  392. else
  393. {
  394. find.Adja1Sat = editItem.Adja1Sat;
  395. find.Adja2Sat = editItem.Adja2Sat;
  396. }
  397. db.TaskInfos.AddOrUpdate(find);
  398. db.TaskSigs.RemoveRange(taskSig);
  399. List<TaskSig> sigList = new List<TaskSig>();
  400. foreach (var item in editItemSig)
  401. {
  402. TaskSig taskSigEdit = new TaskSig();
  403. taskSigEdit.TaskInfoID = editItem.ID;
  404. taskSigEdit.SigInfoID = item.ID;
  405. taskSigEdit.FreqUp = item.FreqUp;
  406. taskSigEdit.FreqDown = item.FreqDown;
  407. sigList.Add(taskSigEdit);
  408. }
  409. db.TaskSigs.AddRange(sigList);
  410. await db.SaveChangesAsync();
  411. }
  412. gridView1.RefreshData();
  413. }
  414. catch (Exception ex)
  415. {
  416. Serilog.Log.Error(ex, "编辑任务异常");
  417. DxHelper.MsgBoxHelper.ShowError("编辑任务异常");
  418. }
  419. }
  420. else
  421. {
  422. try
  423. {
  424. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  425. if (tsk == null) return;
  426. if (!DxHelper.MsgBoxHelper.ShowConfirm($"删除任务[{tsk.TaskName}]?"))
  427. return;
  428. using (RHDWContext db = new RHDWContext())
  429. {
  430. var item = db.TaskInfos.FirstOrDefault(p => p.ID == tsk.ID);
  431. db.TaskInfos.Remove(item);
  432. var taskSig = db.TaskSigs.Where(w => w.TaskInfoID == tsk.ID);
  433. db.TaskSigs.RemoveRange(taskSig);
  434. db.SaveChanges();
  435. }
  436. gridView1.DeleteSelectedRows();
  437. }
  438. catch (Exception ex)
  439. {
  440. Serilog.Log.Error(ex, "删除任务异常");
  441. DxHelper.MsgBoxHelper.ShowError("删除任务异常");
  442. }
  443. }
  444. }
  445. private async void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  446. {
  447. var tsk = gridView1.GetFocusedRow() as TaskInfo;
  448. if (e.Item.Caption == "启动任务")
  449. {
  450. try
  451. {
  452. if (tsk.TaskType != EnumTaskType.Group)
  453. {
  454. TxInfo tx;
  455. List<TaskSigDto> tskSigsDto = new List<TaskSigDto>();
  456. using (RHDWContext db = new RHDWContext())
  457. {
  458. var dbSigs = await db.TaskSigs.Where(w => w.TaskInfoID == tsk.ID).Include(p => p.SigInfo).ToListAsync();
  459. if (!dbSigs.Any())
  460. {
  461. DxHelper.MsgBoxHelper.ShowWarning($"请添加任务信号");
  462. return;
  463. }
  464. foreach (var item in dbSigs)
  465. {
  466. TaskSigDto sigDto = new TaskSigDto()
  467. {
  468. FreqDown = item.SigInfo.FreqDown,
  469. FreqUp = item.SigInfo.FreqUp,
  470. SigType = (EnumSigCheckTypeDto)item.SigInfo.SigType,
  471. Snr = item.SigInfo.Snr,
  472. TaskInfoID = item.TaskInfoID,
  473. };
  474. var sigDelay = await db.SigDelays.Where(p => p.SigInfoId == item.SigInfo.ID).ToListAsync();
  475. sigDto.SigDelay.AddRange(sigDelay.MapTo<List<SigDelayDto>>());
  476. tskSigsDto.Add(sigDto);
  477. }
  478. tx = db.TxInfos.FirstOrDefault();
  479. if (tx == null)
  480. {
  481. DxHelper.MsgBoxHelper.ShowWarning($"未配置天线信息");
  482. return;
  483. }
  484. }
  485. if (tsk.PosType == EnumPosType.X2D1)
  486. {
  487. //下发任务
  488. var svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefHistoryTask);
  489. if (svtItem == null)
  490. {
  491. DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的处理服务");
  492. return;
  493. }
  494. TaskHistoryTimeEditor frm = new TaskHistoryTimeEditor(tsk);
  495. if (frm.ShowDialog() != DialogResult.OK) return;
  496. var startTime = frm.start;
  497. var endTime = frm.end;
  498. X2D1NoRefTaskHandleDto dto = new X2D1NoRefTaskHandleDto()
  499. {
  500. MainSatCode = tsk.MainSat,
  501. TaskType = (EnumTaskTypeDto)((int)tsk.TaskType),
  502. AdjaSatCode = tsk.Adja1Sat.Value,
  503. ID = tsk.ID,
  504. StartTime = startTime,
  505. EndTime = endTime,
  506. TaskName = tsk.TaskName,
  507. CapDir = tsk.CapDir,
  508. CapLon = tx.Lon,
  509. CapLat = tx.Lat,
  510. DateDirFormat = tsk.CapDirFormat,
  511. Sigs = tskSigsDto,
  512. };
  513. var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + "/api/X2D1NoRefTaskProcessing/Run", dto);
  514. if (res.code != 200)
  515. {
  516. Serilog.Log.Error(res.msg);
  517. DxHelper.MsgBoxHelper.ShowError($"{res.msg}");
  518. return;
  519. }
  520. }
  521. else if (tsk.PosType == EnumPosType.X3TwoDto)
  522. {
  523. //下发任务
  524. var svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X3NoRefHistoryTask);
  525. if (svtItem == null)
  526. {
  527. DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的处理服务");
  528. return;
  529. }
  530. TaskHistoryTimeEditor frm = new TaskHistoryTimeEditor(tsk);
  531. if (frm.ShowDialog() != DialogResult.OK) return;
  532. var startTime = frm.start;
  533. var endTime = frm.end;
  534. X2D1NoRefTaskHandleDto dto = new X2D1NoRefTaskHandleDto()
  535. {
  536. MainSatCode = tsk.MainSat,
  537. AdjaSatCode = tsk.Adja1Sat.Value,
  538. ID = tsk.ID,
  539. StartTime = startTime,
  540. EndTime = endTime,
  541. TaskName = tsk.TaskName,
  542. CapDir = tsk.CapDir,
  543. DateDirFormat = tsk.CapDirFormat,
  544. CapLon = tx.Lon,
  545. CapLat = tx.Lat,
  546. Sigs = tskSigsDto.ToList()
  547. };
  548. var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + "/api/X2D1NoRefTaskProcessing/Run", dto);
  549. if (res.code != 200)
  550. {
  551. Serilog.Log.Error(res.msg);
  552. DxHelper.MsgBoxHelper.ShowError($"{res.msg}");
  553. return;
  554. }
  555. }
  556. else
  557. {
  558. DxHelper.MsgBoxHelper.ShowError($"暂不支持{tsk.PosType.GetEnumDisplayName()}类型的历史任务");
  559. return;
  560. }
  561. }
  562. using (RHDWContext db = new RHDWContext())
  563. {
  564. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  565. item.TaskState = EnumTaskState.Running;
  566. await db.SaveChangesAsync();
  567. tsk.TaskState = EnumTaskState.Running;
  568. Serilog.Log.Information($"用户启动了任务,ID={tsk.ID}");
  569. }
  570. }
  571. catch (Exception ex)
  572. {
  573. Serilog.Log.Error(ex, "启动任务异常");
  574. DxHelper.MsgBoxHelper.ShowError($"启动任务异常.{ex.Message}");
  575. }
  576. }
  577. else
  578. {
  579. try
  580. {
  581. if (tsk.TaskType != EnumTaskType.Group)
  582. {
  583. ModelSvr svtItem = null;
  584. if (tsk.PosType == EnumPosType.X2D1)
  585. svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X2D1NoRefHistoryTask);
  586. else if (tsk.PosType == EnumPosType.X3TwoDto)
  587. svtItem = ServerContext.Instance.GetRandomOne(EnumSvrType.X3NoRefHistoryTask);
  588. if (svtItem == null)
  589. {
  590. DxHelper.MsgBoxHelper.ShowWarning($"未找到注册的处理服务");
  591. return;
  592. }
  593. TaskStopHandleDto dto = new TaskStopHandleDto();
  594. dto.ID = tsk.ID;
  595. var res = await HttpHelper.PostRequestAsync<AjaxResult>(svtItem.BaseHttpAddr + "/api/X2D1NoRefTaskProcessing/Stop", dto);
  596. if (res.code != 200)
  597. {
  598. Serilog.Log.Error(res.msg);
  599. DxHelper.MsgBoxHelper.ShowWarning(res.msg);
  600. }
  601. }
  602. using (RHDWContext db = new RHDWContext())
  603. {
  604. var item = await db.TaskInfos.FirstOrDefaultAsync(p => p.ID == tsk.ID);
  605. item.TaskState = EnumTaskState.Stopped;
  606. await db.SaveChangesAsync();
  607. }
  608. tsk.TaskState = EnumTaskState.Stopped;
  609. Serilog.Log.Warning($"用户停止了任务,ID={tsk.ID}");
  610. }
  611. catch (Exception ex)
  612. {
  613. Serilog.Log.Error(ex, "停止任务异常");
  614. DxHelper.MsgBoxHelper.ShowError($"停止任务异常.{ex.Message}");
  615. }
  616. }
  617. gridView1.RefreshData();
  618. var btnEdit = (layoutControlGroup1.CustomHeaderButtons[1] as GroupBoxButton);
  619. var btnDel = (layoutControlGroup1.CustomHeaderButtons[2] as GroupBoxButton);
  620. btnDel.Enabled = btnEdit.Enabled = tsk.TaskState != EnumTaskState.Running;
  621. }
  622. private void txtFrequpMHz_SelectedIndexChanged(object sender, EventArgs e)
  623. {
  624. txtTimeCho_SelectedIndexChanged(null, null);
  625. }
  626. private async void txtTimeCho_SelectedIndexChanged(object sender, EventArgs e)
  627. {
  628. listCts.ForEach(t => t.Cancel());
  629. listCts.Clear();
  630. this.gridHomePosRes.DataSource = new List<ModelPosRes>();//先设为空,数据相同时便于观察结果有没有变化
  631. this.mapControl1.SetPosDataSource(new List<ModelPosRes>());
  632. if (tsk == null)
  633. {
  634. return;
  635. }
  636. var cts = new CancellationTokenSource();
  637. listCts.Add(cts);
  638. switch (txtTimeCho.Text)
  639. {
  640. case "最近1小时":
  641. case "最近6小时":
  642. case "最近12小时":
  643. case "最近1天":
  644. case "最近3天":
  645. itemStart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  646. itemEnd.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  647. layoutControlItemSearch.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  648. var list = await searchPos(cts.Token);
  649. this.gridHomePosRes.DataSource = list;
  650. this.mapControl1.SetPosDataSource(list);
  651. break;
  652. case "自定义":
  653. itemStart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  654. itemEnd.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  655. layoutControlItemSearch.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  656. break;
  657. }
  658. }
  659. private async void BtnIncludeInvalidate_CheckedChanged(object sender, EventArgs e)
  660. {
  661. if (txtTimeCho.Text != "自定义")
  662. {
  663. listCts.ForEach(t => t.Cancel());
  664. listCts.Clear();
  665. this.gridHomePosRes.DataSource = new List<ModelPosRes>();//先设为空,数据相同时便于观察结果有没有变化
  666. if (tsk == null)
  667. {
  668. return;
  669. }
  670. var cts = new CancellationTokenSource();
  671. listCts.Add(cts);
  672. this.gridHomePosRes.DataSource = await searchPos(cts.Token);
  673. }
  674. }
  675. private async void btnSearch_Click(object sender, EventArgs e)
  676. {
  677. if (txtStartTime.EditValue == null)
  678. {
  679. DxHelper.MsgBoxHelper.ShowError($"请选择信号开始时间!");
  680. return;
  681. }
  682. if (txtEndTime.EditValue == null)
  683. {
  684. DxHelper.MsgBoxHelper.ShowError($"请选择信号结束时间!");
  685. return;
  686. }
  687. if (txtStartTime.DateTime > txtEndTime.DateTime)
  688. {
  689. DxHelper.MsgBoxHelper.ShowError($"开始时间不能大于结束时间!");
  690. return;
  691. }
  692. listCts.ForEach(t => t.Cancel());
  693. listCts.Clear();
  694. var cts = new CancellationTokenSource();
  695. listCts.Add(cts);
  696. var listPos = await searchPos(cts.Token);
  697. this.gridHomePosRes.DataSource = listPos;
  698. this.mapControl1.SetPosDataSource(listPos);
  699. }
  700. private async Task<List<ModelPosRes>> searchPos(CancellationToken ct = default)
  701. {
  702. gridView2.ClearSorting();
  703. gridView2.ClearFindFilter();
  704. gridView2.ClearColumnsFilter();
  705. string baseUrl = null;
  706. if (SysConfig.Config != null)
  707. {
  708. baseUrl = $"http://{IpHelper.GetLocalIp()}:{SysConfig.Config.HttpPort}/api/";
  709. }
  710. try
  711. {
  712. List<ModelPosRes> list = new List<ModelPosRes>();
  713. if (txtTimeCho.Text == "自定义")
  714. {
  715. var dto = new PosRequestByTimeRangeDto()
  716. {
  717. TarFrequpHz = (long?)txtFrequpMHz.EditValue,
  718. BeginTime = txtStartTime.DateTime,
  719. EndTime = txtEndTime.DateTime,
  720. TaskInfoID = tsk.ID,
  721. IncludeInvalidate = btnIncludeInvalidate.Checked
  722. };
  723. var res = await HttpHelper.PostRequestAsync<List<ModelPosRes>>(baseUrl + "Pos/GetPosResByTimeRangeObsolete", dto, token: ct);
  724. if (res.code == 200)
  725. {
  726. if (res.msg.Length > 10)
  727. {
  728. MsgBoxHelper.ShowWarning(res.msg);
  729. }
  730. list = res.data;
  731. }
  732. else
  733. {
  734. MsgBoxHelper.ShowError(res.msg);
  735. }
  736. }
  737. else
  738. {
  739. var dto = new PosRequestByLastRangeDto()
  740. {
  741. TaskInfoID = tsk.ID,
  742. Hours = Convert.ToInt32(txtTimeCho.EditValue),
  743. IncludeInvalidate = btnIncludeInvalidate.Checked
  744. };
  745. if (txtFrequpMHz.EditValue != null)
  746. {
  747. dto.TarFrequpHz = Convert.ToInt64(txtFrequpMHz.EditValue);
  748. }
  749. var res = await HttpHelper.PostRequestAsync<List<ModelPosRes>>(baseUrl + "Pos/GetPosResByLastHoursObsolete", dto, token: ct);
  750. if (res.code == 200)
  751. {
  752. if (res.msg.Length > 10)
  753. {
  754. MsgBoxHelper.ShowWarning(res.msg);
  755. }
  756. list = res.data;
  757. }
  758. else
  759. {
  760. MsgBoxHelper.ShowError(res.msg);
  761. }
  762. }
  763. return list;
  764. }
  765. catch (TaskCanceledException) { }//屏蔽掉取消查询的异常
  766. catch (Exception ex)
  767. {
  768. Serilog.Log.Error(ex, "定位结果查询异常");
  769. MsgBoxHelper.ShowError("定位结果查询异常");
  770. }
  771. return new List<ModelPosRes>();
  772. }
  773. #region 定位点右键事件函数
  774. //删除定位点
  775. public async Task<bool> DelPos(List<ModelPosRes> items)
  776. {
  777. try
  778. {
  779. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  780. foreach (var groupItem in groupItems)
  781. {
  782. var ids = groupItem.Select(m => m.ID).ToList();
  783. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  784. {
  785. if (db == null) continue;
  786. var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  787. db.PosRes.RemoveRange(array);
  788. await db.SaveChangesAsync();
  789. mapControl1.DelPosItem(array);
  790. }
  791. }
  792. return true;
  793. }
  794. catch (Exception ex)
  795. {
  796. Serilog.Log.Error(ex, "表格中删除定位点异常!");
  797. DxHelper.MsgBoxHelper.ShowError("删除定位点异常!");
  798. return false;
  799. }
  800. }
  801. //绘制时差线
  802. public void DrawDtoLine(ModelPosRes item)
  803. {
  804. switch (item.PosResType)
  805. {
  806. case EnumPosResType.X1D1CX:
  807. X1D1DTOParamEditor frm = new X1D1DTOParamEditor(item, mapControl1);
  808. DxHelper.PopupHelper.ShowPopup(frm, layoutControl1, 600);
  809. break;
  810. case EnumPosResType.X2D1:
  811. case EnumPosResType.X2D1NoRef:
  812. X2D1DTOParamEditor X2D1frm = new X2D1DTOParamEditor(item, mapControl1);
  813. DxHelper.PopupHelper.ShowPopup(X2D1frm, layoutControl1, 600);
  814. break;
  815. case EnumPosResType.X3:
  816. case EnumPosResType.X3NoRef:
  817. X3DTOParamEditor X3frm = new X3DTOParamEditor(item, mapControl1);
  818. DxHelper.PopupHelper.ShowPopup(X3frm, layoutControl1, 600);
  819. break;
  820. case EnumPosResType.X2Dfo:
  821. X2DTOParamEditor X2Dfofrm = new X2DTOParamEditor(item, mapControl1);
  822. DxHelper.PopupHelper.ShowPopup(X2Dfofrm, layoutControl1, 600);
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. //绘制频差线
  829. public async Task DrawDfoLine(ModelPosRes item)
  830. {
  831. switch (item.PosResType)
  832. {
  833. case EnumPosResType.X3TwoDfo:
  834. case EnumPosResType.X2Dfo:
  835. try
  836. {
  837. StationRes station = null;
  838. CgRes cg = null;
  839. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  840. {
  841. cg = await db?.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  842. station = await db?.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
  843. }
  844. if (cg == null)
  845. {
  846. Serilog.Log.Error($"绘制三星频差线错误,未找到定位关联的参估计信息.PosID={item.ID},SigTime={item.SigTime}");
  847. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的参估计信息");
  848. return;
  849. }
  850. if (station == null)
  851. {
  852. Serilog.Log.Error($"绘制三星频差线错误,未找到定位关联的站点信息.PosID={item.ID},SigTime={item.SigTime}");
  853. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的站点信息");
  854. return;
  855. }
  856. if (station.SatTxLon == 0 || station.SatTxLat == 0)
  857. {
  858. Serilog.Log.Error($"绘制三星频差线错误,天线信息为空.PosID={item.ID},SigTime={item.SigTime}");
  859. DxHelper.MsgBoxHelper.ShowError($"天线信息为空!");
  860. return;
  861. }
  862. if (station.RefLon == 0 || station.RefLat == 0)
  863. {
  864. Serilog.Log.Error($"绘制三星频差线错误,参考站信息为空.PosID={item.ID},SigTime={item.SigTime}");
  865. DxHelper.MsgBoxHelper.ShowError($"参考站信息为空!");
  866. return;
  867. }
  868. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  869. twoStartOption.Freq = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value : 0;
  870. twoStartOption.RefFreq = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value : 0;
  871. twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, cg.MainVx.Value, cg.MainVy.Value, cg.MainVz.Value };
  872. twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, cg.Adja1Vx.Value, cg.Adja1Vy.Value, cg.Adja1Vz.Value };
  873. twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  874. twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
  875. twoStartOption.RefGeod = new double[] { station.RefLon.Value, station.RefLat.Value, 0 };
  876. twoStartOption.TargetDfo = cg.Dfo1.Value;
  877. twoStartOption.Turn1 = Math.Abs(twoStartOption.Freq - (cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value : 0));
  878. twoStartOption.Turn2 = Math.Abs(twoStartOption.RefFreq - (cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value : 0));
  879. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja1Dfo.Value;
  880. var tsDtoLine = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  881. List<SatInfo> listSat = null;
  882. using (RHDWContext db = new RHDWContext())
  883. {
  884. listSat = await db.SatInfos.ToListAsync();
  885. }
  886. var msat = listSat?.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; ;
  887. var ad1sat = listSat?.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  888. if (msat == null) msat = cg.MainCode.ToString();
  889. if (ad1sat == null) ad1sat = cg.Adja1Code.ToString();
  890. mapControl1.DrawDtoLine($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]频差线", tsDtoLine);
  891. if (item.PosResType == EnumPosResType.X3TwoDfo)
  892. {
  893. twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, cg.Adja2Vx.Value, cg.Adja2Vy.Value, cg.Adja2Vz.Value };
  894. twoStartOption.TargetDfo = cg.Dfo2.Value;
  895. twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja2Dfo.Value;
  896. var tsDtoLine1 = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  897. string ad2sat = string.Empty;
  898. if (cg.Adja2Code.HasValue)
  899. {
  900. ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  901. }
  902. mapControl1.DrawDtoLine($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]频差线", tsDtoLine1);
  903. }
  904. }
  905. catch (Exception ex)
  906. {
  907. Serilog.Log.Error(ex, $"绘制{item.PosResType.GetEnumDisplayName()}频差线失败.PosID={item.ID},SigTime={item.SigTime}");
  908. DxHelper.MsgBoxHelper.ShowError($"绘制{item.PosResType.GetEnumDisplayName()}频差线失败");
  909. }
  910. break;
  911. default:
  912. break;
  913. }
  914. }
  915. private async Task DrawCxLine(ModelPosRes item)
  916. {
  917. try
  918. {
  919. CxRes cx = null;
  920. StationRes station = null;
  921. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  922. {
  923. cx = await db?.CxRes.Where(m => m.ID == item.CxResID.Value).FirstOrDefaultAsync();
  924. station = await db?.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
  925. }
  926. if (cx == null)
  927. {
  928. Serilog.Log.Error($"绘制测向线错误,未找到定位关联的测向信息.PosID={item.ID},SigTime={item.SigTime}");
  929. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的测向信息");
  930. return;
  931. }
  932. if (station == null)
  933. {
  934. Serilog.Log.Error($"绘制测向线错误,未找到定位关联的站点信息.PosID={item.ID},SigTime={item.SigTime}");
  935. DxHelper.MsgBoxHelper.ShowError($"未找到定位关联的站点信息!");
  936. return;
  937. }
  938. if (station.CxLon == 0 || station.CxLat == 0)
  939. {
  940. Serilog.Log.Error($"绘制测向线错误,测向站信息为空.PosID={item.ID},SigTime={item.SigTime}");
  941. DxHelper.MsgBoxHelper.ShowError($"测向站信息为空!");
  942. return;
  943. }
  944. double deg = cx.Fx;//向北顺时针方向为夹角
  945. //计算测向站到定位点之间的距离
  946. var km = MapControlEx.CalcLineKm(station.CxLon.Value, station.CxLat.Value, item.PosLon, item.PosLat);
  947. var endpoint = MapControlEx.CalcSituation(station.CxLon.Value, station.CxLat.Value, deg, (km + 100) * 1000);
  948. List<(double, double)> points = new List<(double, double)>();
  949. points.Add((station.CxLon.Value, station.CxLat.Value));
  950. points.Add((endpoint.Item1, endpoint.Item2));
  951. mapControl1.DrawCXLine($"测向线角度:{cx.Fx}°\t\n", points, true);
  952. }
  953. catch (Exception ex)
  954. {
  955. Serilog.Log.Error(ex, $"绘制测向线失败.PosID={item.ID},SigTime={item.SigTime}");
  956. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败");
  957. }
  958. }
  959. //绘制GDOP
  960. public void DrawGdopLine(ModelPosRes item)
  961. {
  962. try
  963. {
  964. switch (item.PosResType)
  965. {
  966. case EnumPosResType.X1D1CX:
  967. X1D1GDOPParam x1D1GdopParam = new X1D1GDOPParam(item);
  968. x1D1GdopParam.mapControl1 = mapControl1;
  969. DxHelper.PopupHelper.ShowPopup(x1D1GdopParam, layoutControl1, 500);
  970. break;
  971. case EnumPosResType.X2D1:
  972. case EnumPosResType.X2D1NoRef:
  973. X2D1GDOPParam x2D1GdopParam = new X2D1GDOPParam(item);
  974. x2D1GdopParam.mapControl1 = mapControl1;
  975. DxHelper.PopupHelper.ShowPopup(x2D1GdopParam, layoutControl1, 500);
  976. break;
  977. case EnumPosResType.X3:
  978. case EnumPosResType.X3NoRef:
  979. X3GDOPParam x3GdopParam = new X3GDOPParam(item);
  980. x3GdopParam.mapControl1 = mapControl1;
  981. DxHelper.PopupHelper.ShowPopup(x3GdopParam, layoutControl1, 500);
  982. break;
  983. case EnumPosResType.X3TwoDfo:
  984. X3DFGDOPParam x3DFGdopParam = new X3DFGDOPParam(item);
  985. x3DFGdopParam.mapControl1 = mapControl1;
  986. DxHelper.PopupHelper.ShowPopup(x3DFGdopParam, layoutControl1, 500);
  987. break;
  988. case EnumPosResType.X2Dfo:
  989. X2DFGDOPParam x2DFGdopParam = new X2DFGDOPParam(item);
  990. x2DFGdopParam.mapControl1 = mapControl1;
  991. DxHelper.PopupHelper.ShowPopup(x2DFGdopParam, layoutControl1, 500);
  992. break;
  993. default:
  994. break;
  995. }
  996. }
  997. catch (Exception ex)
  998. {
  999. Serilog.Log.Error(ex, $"绘制{item.PosResType.GetEnumDisplayName()}GDOP失败");
  1000. DxHelper.MsgBoxHelper.ShowWarning($"绘制{item.PosResType.GetEnumDisplayName()}GDOP失败!");
  1001. }
  1002. }
  1003. //查看参估结果
  1004. public void ShowCafRes(ModelPosRes item)
  1005. {
  1006. DxHelper.PopupHelper.ShowPopup(new ShowCgCtrl(item), gridHomePosRes, gridHomePosRes.Height + 80, EnumPopupDirection.Bottom, showCloseButton: true);
  1007. }
  1008. //查看测向结果
  1009. public void ShowCxRes(ModelPosRes item)
  1010. {
  1011. DxHelper.PopupHelper.ShowPopup(new ShowCxCtrl(item), gridHomePosRes, gridHomePosRes.Height + 80, EnumPopupDirection.Bottom, showCloseButton: true);
  1012. }
  1013. //查看检测结果
  1014. public void ShowCheckRes(ModelPosRes item)
  1015. {
  1016. DxHelper.PopupHelper.ShowPopup(new ShowCheckCtrl(item), gridHomePosRes, gridHomePosRes.Height + 80, EnumPopupDirection.Bottom, showCloseButton: true);
  1017. }
  1018. //手动定位
  1019. public void PosManual(ModelPosRes item)
  1020. {
  1021. switch (item.PosResType)
  1022. {
  1023. case EnumPosResType.X1D1CX:
  1024. X1D1PosParamEditor frm = new X1D1PosParamEditor(item, mapControl1);
  1025. DxHelper.PopupHelper.ShowPopup(frm, layoutControl1, 500);
  1026. break;
  1027. case EnumPosResType.X2D1:
  1028. case EnumPosResType.X2D1NoRef:
  1029. X2D1PosParamEditor X2D1PosParamEditor = new X2D1PosParamEditor(item);
  1030. DxHelper.PopupHelper.ShowPopup(X2D1PosParamEditor, layoutControl1, 600);
  1031. break;
  1032. case EnumPosResType.X3:
  1033. case EnumPosResType.X3NoRef:
  1034. X3PosParamEditor X3frm = new X3PosParamEditor(item, mapControl1);
  1035. DxHelper.PopupHelper.ShowPopup(X3frm, layoutControl1, 500);
  1036. break;
  1037. case EnumPosResType.X3TwoDfo:
  1038. X3DfoPosParamEditor X3df0frm = new X3DfoPosParamEditor(item);
  1039. DxHelper.PopupHelper.ShowPopup(X3df0frm, layoutControl1, 500);
  1040. break;
  1041. case EnumPosResType.X2Dfo:
  1042. X2PosParamEditor X2PosParamEditor = new X2PosParamEditor(item);
  1043. DxHelper.PopupHelper.ShowPopup(X2PosParamEditor, layoutControl1, 600);
  1044. break;
  1045. default:
  1046. break;
  1047. }
  1048. }
  1049. public void RePosition(List<RePosRes> items, PosRequestByTimeRangeDto dto)
  1050. {
  1051. if (items.Count == 0)
  1052. {
  1053. MsgBoxHelper.ShowWarning($"查询任务[{dto.TaskInfoID}]开始时间:{dto.BeginTime:yyyy-MM-dd HH:mm:ss} 结束时间:{dto.EndTime:yyyy-MM-dd HH:mm:ss}无定位结果数据");
  1054. return;
  1055. }
  1056. Task.Run(async () =>
  1057. {
  1058. foreach (var item in items)
  1059. {
  1060. double[] res = new double[6];
  1061. var StationRes = new StationRes()
  1062. {
  1063. SatTxLon = item.StationRes.SatTxLon,
  1064. SatTxLat = item.StationRes.SatTxLat,
  1065. CdbTxLon = item.StationRes.CdbTxLon,
  1066. CdbTxLat = item.StationRes.CdbTxLat,
  1067. CxLon = item.StationRes.CxLon,
  1068. CxLat = item.StationRes.CxLat,
  1069. RefLon = item.StationRes.RefLon,
  1070. RefLat = item.StationRes.RefLat,
  1071. };
  1072. var mainxlInfo = await XlRepository.GetLatestAsync(item.CgRes.MainCode.Value, item.SigTime);
  1073. if (mainxlInfo == null)
  1074. {
  1075. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.MainCode.Value}未找到对应的星历信息,请导入星历");
  1076. continue;
  1077. }
  1078. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, item.SigTime.ToUtc());
  1079. var CgRes = new CgRes()
  1080. {
  1081. SigTime = item.SigTime,
  1082. MainX = maineph.X,
  1083. MainY = maineph.Y,
  1084. MainZ = maineph.Z,
  1085. MainVx = maineph.VX,
  1086. MainVy = maineph.VY,
  1087. MainVz = maineph.VZ,
  1088. };
  1089. switch (item.PosResType)
  1090. {
  1091. case EnumPosResType.X1D1CX:
  1092. CgRes.DtoCdb = item.CgRes.DtoCdb;
  1093. CgRes.YbMainDto = item.CgRes.YbMainDto;
  1094. var cxRes = new CxRes()
  1095. {
  1096. SigTime = item.SigTime,
  1097. Fx = item.CxRes.Fx,
  1098. };
  1099. res = PosApi.X1D1_Pos(CgRes, StationRes, cxRes);
  1100. item.PosLon = res[0];
  1101. item.PosLat = res[1];
  1102. item.MirrLon = res[3];
  1103. item.MirrLat = res[4];
  1104. break;
  1105. case EnumPosResType.X2D1:
  1106. case EnumPosResType.X2D1NoRef:
  1107. var x2lInfo1 = await XlRepository.GetLatestAsync(item.CgRes.Adja1Code.Value, item.SigTime);
  1108. if (x2lInfo1 == null)
  1109. {
  1110. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  1111. continue;
  1112. }
  1113. var eph1 = EphHelper.Calc(x2lInfo1.TwoLine, item.SigTime.ToUtc());
  1114. CgRes.Dto1 = item.CgRes.Dto1;
  1115. CgRes.Dfo1 = item.CgRes.Dfo1;
  1116. CgRes.Snr1 = item.CgRes.Snr1;
  1117. CgRes.DtoCdb = item.CgRes.DtoCdb;
  1118. CgRes.DfoCdb = item.CgRes.DfoCdb;
  1119. CgRes.SnrCdb = item.CgRes.SnrCdb;
  1120. CgRes.YbMainDto = item.CgRes.YbMainDto;
  1121. CgRes.YbAdja1Dto = item.CgRes.YbAdja1Dto;
  1122. CgRes.MainCode = item.CgRes.MainCode;
  1123. CgRes.Adja1Code = item.CgRes.Adja1Code;
  1124. CgRes.Adja1X = eph1.X;
  1125. CgRes.Adja1Y = eph1.Y;
  1126. CgRes.Adja1Z = eph1.Z;
  1127. res = item.PosResType == EnumPosResType.X2D1 ? PosApi.X2D1_Pos(CgRes, StationRes) : PosApi.X2D1_PosNoRef(CgRes, StationRes);
  1128. item.PosLon = res[0];
  1129. item.PosLat = res[1];
  1130. item.MirrLon = res[3];
  1131. item.MirrLat = res[4];
  1132. break;
  1133. case EnumPosResType.X3:
  1134. case EnumPosResType.X3NoRef:
  1135. var x3lInfo1 = await XlRepository.GetLatestAsync(item.CgRes.Adja1Code.Value, item.SigTime);
  1136. if (x3lInfo1 == null)
  1137. {
  1138. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  1139. continue;
  1140. }
  1141. var X3eph1 = EphHelper.Calc(x3lInfo1.TwoLine, item.SigTime.ToUtc());
  1142. var x3lInfo2 = await XlRepository.GetLatestAsync(item.CgRes.Adja2Code.Value, item.SigTime);
  1143. if (x3lInfo2 == null)
  1144. {
  1145. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  1146. continue;
  1147. }
  1148. var X3eph2 = EphHelper.Calc(x3lInfo2.TwoLine, item.SigTime.ToUtc());
  1149. CgRes.Dto1 = item.CgRes.Dto1;
  1150. CgRes.Dto2 = item.CgRes.Dto2;
  1151. CgRes.YbMainDto = item.CgRes.YbMainDto;
  1152. CgRes.YbAdja1Dto = item.CgRes.YbAdja1Dto;
  1153. CgRes.YbAdja2Dto = item.CgRes.YbAdja2Dto;
  1154. CgRes.Adja1X = X3eph1.X;
  1155. CgRes.Adja1Y = X3eph1.Y;
  1156. CgRes.Adja1Z = X3eph1.Z;
  1157. CgRes.Adja2X = X3eph2.X;
  1158. CgRes.Adja2Y = X3eph2.Y;
  1159. CgRes.Adja2Z = X3eph2.Z;
  1160. res = item.PosResType == EnumPosResType.X3 ? PosApi.X3_Pos(CgRes, StationRes) : PosApi.X3_PosNoRef(CgRes, StationRes);
  1161. item.PosLon = res[0];
  1162. item.PosLat = res[1];
  1163. item.MirrLon = res[3];
  1164. item.MirrLat = res[4];
  1165. break;
  1166. case EnumPosResType.X3TwoDfo:
  1167. var x3dflInfo1 = await XlRepository.GetLatestAsync(item.CgRes.Adja1Code.Value, item.SigTime);
  1168. if (x3dflInfo1 == null)
  1169. {
  1170. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  1171. continue;
  1172. }
  1173. var X3dfeph1 = EphHelper.Calc(x3dflInfo1.TwoLine, item.SigTime.ToUtc());
  1174. var x3dflInfo2 = await XlRepository.GetLatestAsync(item.CgRes.Adja2Code.Value, item.SigTime);
  1175. if (x3dflInfo2 == null)
  1176. {
  1177. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  1178. continue;
  1179. }
  1180. var X3dfeph2 = EphHelper.Calc(x3dflInfo2.TwoLine, item.SigTime.ToUtc());
  1181. CgRes.Dfo1 = item.CgRes.Dfo1;
  1182. CgRes.Dfo2 = item.CgRes.Dfo2;
  1183. CgRes.YbMainDfo = item.CgRes.YbMainDfo;
  1184. CgRes.YbAdja1Dfo = item.CgRes.YbAdja1Dfo;
  1185. CgRes.YbAdja2Dfo = item.CgRes.YbAdja2Dfo;
  1186. CgRes.TarFreqUp = item.CgRes.TarFreqUp;
  1187. CgRes.TarFreqDown = item.CgRes.TarFreqDown;
  1188. CgRes.RefFreqUp = item.CgRes.RefFreqUp;
  1189. CgRes.RefFreqDown = item.CgRes.RefFreqDown;
  1190. CgRes.Adja1X = X3dfeph1.X;
  1191. CgRes.Adja1Y = X3dfeph1.Y;
  1192. CgRes.Adja1Z = X3dfeph1.Z;
  1193. CgRes.Adja1Vx = X3dfeph1.VX;
  1194. CgRes.Adja1Vy = X3dfeph1.VY;
  1195. CgRes.Adja1Vz = X3dfeph1.VZ;
  1196. CgRes.Adja2X = X3dfeph2.X;
  1197. CgRes.Adja2Y = X3dfeph2.Y;
  1198. CgRes.Adja2Z = X3dfeph2.Z;
  1199. CgRes.Adja2Vx = X3dfeph2.VX;
  1200. CgRes.Adja2Vy = X3dfeph2.VY;
  1201. CgRes.Adja2Vz = X3dfeph2.VZ;
  1202. res = PosApi.X3_PosTwoDfo(CgRes, StationRes);
  1203. item.PosLon = res[0];
  1204. item.PosLat = res[1];
  1205. item.MirrLon = res[3];
  1206. item.MirrLat = res[4];
  1207. break;
  1208. case EnumPosResType.X2Dfo:
  1209. var x2dflInfo1 = await XlRepository.GetLatestAsync(item.CgRes.Adja1Code.Value, item.SigTime);
  1210. if (x2dflInfo1 == null)
  1211. {
  1212. Serilog.Log.Error($"重新定位异常:卫星:{item.CgRes.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  1213. continue;
  1214. }
  1215. var X2dfeph1 = EphHelper.Calc(x2dflInfo1.TwoLine, item.SigTime.ToUtc());
  1216. CgRes.Dto1 = item.CgRes.Dto1;
  1217. CgRes.Dfo1 = item.CgRes.Dfo1;
  1218. CgRes.Snr1 = item.CgRes.Snr1;
  1219. CgRes.YbMainDto = item.CgRes.YbMainDto;
  1220. CgRes.YbMainDfo = item.CgRes.YbMainDfo;
  1221. CgRes.YbAdja1Dto = item.CgRes.YbAdja1Dto;
  1222. CgRes.YbAdja1Dfo = item.CgRes.YbAdja1Dfo;
  1223. CgRes.TarFreqUp = item.CgRes.TarFreqUp;
  1224. CgRes.TarFreqDown = item.CgRes.TarFreqDown;
  1225. CgRes.RefFreqUp = item.CgRes.RefFreqUp;
  1226. CgRes.RefFreqDown = item.CgRes.RefFreqDown;
  1227. CgRes.Adja1X = X2dfeph1.X;
  1228. CgRes.Adja1Y = X2dfeph1.Y;
  1229. CgRes.Adja1Z = X2dfeph1.Z;
  1230. CgRes.Adja1Vx = X2dfeph1.VX;
  1231. CgRes.Adja1Vy = X2dfeph1.VY;
  1232. CgRes.Adja1Vz = X2dfeph1.VZ;
  1233. res = PosApi.X2_PosDtoDfo(CgRes, StationRes);
  1234. item.PosLon = res[0];
  1235. item.PosLat = res[1];
  1236. item.MirrLon = res[3];
  1237. item.MirrLat = res[4];
  1238. break;
  1239. default:
  1240. break;
  1241. }
  1242. }
  1243. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  1244. foreach (var groupItem in groupItems)
  1245. {
  1246. var ids = groupItem.Select(m => m.ID).ToList();
  1247. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  1248. {
  1249. if (db == null) continue;
  1250. var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  1251. tarItems.ForEach(t =>
  1252. {
  1253. var repos = items.First(p => p.ID == t.ID);
  1254. t.PosLon = repos.PosLon;
  1255. t.PosLat = repos.PosLat;
  1256. t.MirrLon = repos.MirrLon;
  1257. t.MirrLat = repos.MirrLat;
  1258. });
  1259. db.PosRes.AddOrUpdate(tarItems);
  1260. await db.SaveChangesAsync();
  1261. }
  1262. }
  1263. Serilog.Log.Warning($"共重新定位了{items.Count()}个定位点的目标信息");
  1264. MsgBoxHelper.ShowInfo($"共重新定位了{items.Count()}个定位点的目标信息");
  1265. });
  1266. }
  1267. //重新定位
  1268. public async void Repos(List<ModelPosRes> dataSource)
  1269. {
  1270. if (tsk == null)
  1271. {
  1272. MsgBoxHelper.ShowWarning("请选择需要重新定位的任务");
  1273. return;
  1274. }
  1275. PosTimeEditor frm = new PosTimeEditor(tsk);
  1276. if (frm.ShowDialog() != DialogResult.OK) return;
  1277. var dto = new PosRequestByTimeRangeDto()
  1278. {
  1279. BeginTime = frm.start,
  1280. EndTime = frm.end,
  1281. TaskInfoID = tsk.ID
  1282. };
  1283. string baseUrl = null;
  1284. if (SysConfig.Config != null)
  1285. {
  1286. baseUrl = $"http://{IpHelper.GetLocalIp()}:{SysConfig.Config.HttpPort}/api/";
  1287. }
  1288. try
  1289. {
  1290. var ct = new CancellationTokenSource();
  1291. var res = await HttpHelper.PostRequestAsync<List<RePosRes>>(baseUrl + "Pos/GetPosCgResByTimeRangeObsolete", dto, token: ct.Token);
  1292. if (res.code == 200)
  1293. {
  1294. RePosition(res.data, dto);
  1295. }
  1296. else
  1297. {
  1298. MsgBoxHelper.ShowError(res.msg);
  1299. }
  1300. }
  1301. catch (Exception ex)
  1302. {
  1303. string msg = $"任务[{dto.TaskInfoID}]重新定位结果查询开始时间:{dto.BeginTime:yyyy-MM-dd HH:mm:ss} 结束时间:{dto.EndTime:yyyy-MM-dd HH:mm:ss}异常";
  1304. Serilog.Log.Error(ex, msg);
  1305. MsgBoxHelper.ShowError(msg);
  1306. }
  1307. }
  1308. #endregion
  1309. #region 地图区域右键菜单
  1310. //编辑目标
  1311. private async Task EditTarget(List<ModelPosRes> items)
  1312. {
  1313. try
  1314. {
  1315. if (items.Count == 0) return;
  1316. long? targetID = 0;
  1317. using (RHDWPartContext db = RHDWPartContext.GetContext(items.First().SigTime))
  1318. {
  1319. if (db != null)
  1320. {
  1321. var idRes = items.First().ID;
  1322. var target = await db.PosRes.Where(p => p.ID == idRes).FirstOrDefaultAsync() as PosRes;
  1323. targetID = target.TargetInfoID;
  1324. }
  1325. }
  1326. TargetInfo info = null;
  1327. if (targetID > 0)
  1328. {
  1329. using (RHDWContext db = new RHDWContext())
  1330. {
  1331. info = db.TargetInfos.FirstOrDefault(p => p.ID == targetID);
  1332. }
  1333. }
  1334. EditorTar frm = new EditorTar(info);
  1335. if (frm.ShowDialog() != DialogResult.OK) return;
  1336. var tar = frm.info;
  1337. var groupData = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  1338. List<long> posResIdList = new List<long>();
  1339. foreach (var groupItems in groupData)
  1340. {
  1341. var ids = groupItems.Select(p => p.ID);
  1342. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItems.First().SigTime))
  1343. {
  1344. if (db == null) continue;
  1345. var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  1346. tarItems.ForEach(t =>
  1347. {
  1348. t.TargetInfoID = tar.ID;
  1349. t.ColorKey = tar.TargeColor;
  1350. });
  1351. posResIdList.AddRange(tarItems.Select(s => s.ID));
  1352. mapControl1.UpdatePosItem(tarItems);
  1353. db.PosRes.AddOrUpdate(tarItems);
  1354. await db.SaveChangesAsync();
  1355. }
  1356. }
  1357. var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
  1358. ds.Where(w => posResIdList.Contains(w.ID)).ForEach(p =>
  1359. {
  1360. p.TargetInfoID = tar.ID;
  1361. p.TargetInfo = tar;
  1362. p.ColorKey = tar.TargeColor;
  1363. });
  1364. gridView2.RefreshData();
  1365. Serilog.Log.Warning($"共修改了{items.Count()}个定位点的目标信息");
  1366. MsgBoxHelper.ShowInfo($"共修改了{items.Count()}个定位点的目标信息");
  1367. }
  1368. catch (Exception ex)
  1369. {
  1370. Serilog.Log.Error(ex, "编辑定位目标异常");
  1371. DxHelper.MsgBoxHelper.ShowError("编辑定位目标异常");
  1372. }
  1373. }
  1374. //转到列表
  1375. private void ToPosList(List<ModelPosRes> items)
  1376. {
  1377. if (items == null || items.Count() == 0)
  1378. {
  1379. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要转到列表的定位数据信息!");
  1380. return;
  1381. }
  1382. try
  1383. {
  1384. var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
  1385. var ids = items.Select(p => p.ID).ToList();
  1386. //删除地图
  1387. var deleteItems = ds.Where(m => !ids.Contains(m.ID)).ToList();
  1388. mapControl1.DelPosItem(deleteItems);
  1389. //删除列表
  1390. ds.RemoveAll(m => !ids.Contains(m.ID));
  1391. gridView2.RefreshData();
  1392. }
  1393. catch (Exception ex)
  1394. {
  1395. Serilog.Log.Error(ex, "转到列表异常!");
  1396. MsgBoxHelper.ShowError("转到列表异常!");
  1397. }
  1398. }
  1399. //批量使用镜像点
  1400. private async Task UseMirr(List<ModelPosRes> items)
  1401. {
  1402. if (items == null || items.Count() == 0)
  1403. {
  1404. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要使用镜像点的定位数据信息!");
  1405. return;
  1406. }
  1407. try
  1408. {
  1409. if (!MsgBoxHelper.ShowConfirm($"确认使用镜像点?共{items.Count}条记录")) return;
  1410. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  1411. foreach (var groupItem in groupItems)
  1412. {
  1413. var ids = groupItem.Select(m => m.ID).ToList();
  1414. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  1415. {
  1416. if (db == null) continue;
  1417. var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
  1418. UseMirror(array);
  1419. await db.SaveChangesAsync();
  1420. }
  1421. }
  1422. UseMirror(items);
  1423. mapControl1.UpdatePosItem(items);
  1424. gridView2.RefreshData();
  1425. Serilog.Log.Warning($"用户修改了{items.Count()}个定位点的镜像点");
  1426. MsgBoxHelper.ShowInfo($"共修改了{items.Count()}个定位点的镜像点");
  1427. }
  1428. catch (Exception ex)
  1429. {
  1430. Serilog.Log.Error(ex, "使用镜像点失败!");
  1431. MsgBoxHelper.ShowError("使用镜像点失败!");
  1432. }
  1433. }
  1434. //批量删除
  1435. private async Task DeletePosRes(List<ModelPosRes> items)
  1436. {
  1437. if (items == null || items.Count() == 0)
  1438. {
  1439. DxHelper.MsgBoxHelper.ShowWarning($"请选择需要删除的定位数据信息!");
  1440. return;
  1441. }
  1442. try
  1443. {
  1444. if (!MsgBoxHelper.ShowConfirm($"确认删除定位点?共{items.Count}条记录")) return;
  1445. var groupItems = items.GroupBy(p => p.SigTime.ToString("yyyyMMdd"));
  1446. foreach (var groupItem in groupItems)
  1447. {
  1448. var ids = groupItem.Select(m => m.ID).ToList();
  1449. using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
  1450. {
  1451. if (db == null) continue;
  1452. var list = await db.PosRes.Where(p => ids.Contains(p.ID)).ToListAsync();
  1453. db.PosRes.RemoveRange(list);
  1454. await db.SaveChangesAsync();
  1455. }
  1456. }
  1457. mapControl1.DelPosItem(items);
  1458. var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
  1459. ds.RemoveAll(m => items.Select(p => p.ID).Contains(m.ID));
  1460. gridView2.RefreshData();
  1461. Serilog.Log.Warning($"用户删除了{items.Count()}个定位点");
  1462. MsgBoxHelper.ShowInfo($"共删除了{items.Count()}个定位点");
  1463. }
  1464. catch (Exception ex)
  1465. {
  1466. Serilog.Log.Error(ex, "删除定位点失败");
  1467. MsgBoxHelper.ShowError("删除定位点失败!");
  1468. }
  1469. }
  1470. private void UseMirror(IEnumerable<PosRes> pos)
  1471. {
  1472. foreach (var item in pos)
  1473. {
  1474. var mirrlon = item.MirrLon;
  1475. var mirrLat = item.MirrLat;
  1476. if (mirrlon == 999)
  1477. {
  1478. continue;
  1479. }
  1480. item.MirrLon = item.PosLon;
  1481. item.MirrLat = item.PosLat;
  1482. item.PosLon = mirrlon;
  1483. item.PosLat = mirrLat;
  1484. }
  1485. }
  1486. #endregion
  1487. }
  1488. }