CtrlHome.cs 67 KB

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