MainWindow.xaml.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. using Panuon.WPF.UI;
  2. using SWRIS.Core;
  3. using SWRIS.Dtos;
  4. using SWRIS.Enums;
  5. using SWRIS.Events;
  6. using SWRIS.Extensions;
  7. using SWRIS.Models;
  8. using SWRIS.Models.ViewModel;
  9. using SWRIS.Pages;
  10. using SWRIS.Repository;
  11. using System;
  12. using System.ComponentModel;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Speech.Synthesis;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Markup;
  21. namespace SWRIS
  22. {
  23. /// <summary>
  24. /// MainWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MainWindow : WindowX, IComponentConnector
  27. {
  28. private readonly SpeechSynthesizer speech;
  29. public MainViewModel MainView { get; set; }
  30. private readonly IRecordRepository _recordRepository;
  31. private readonly IAlarmRepository _alarmRepository;
  32. public MainWindow()
  33. {
  34. InitializeComponent();
  35. _recordRepository = new RecordRepository();
  36. _alarmRepository = new AlarmRepository();
  37. speech = new SpeechSynthesizer()
  38. {
  39. Rate = 1,
  40. Volume = 100
  41. };
  42. MainView = new MainViewModel()
  43. {
  44. AppName = App.Config.AppName,
  45. Version = App.Config.Version,
  46. Copyright = App.Config.Copyright,
  47. SwitchInstances = App.Config.SwitchInstances
  48. };
  49. Application.Current.MainWindow = this;
  50. App.TcpServer.ClientConnected += TcpServer_ClientConnected;
  51. App.TcpServer.ClientDisconnected += TcpServer_ClientDisconnected;
  52. App.TcpServer.AlarmDataReceived += TcpServer_AlarmDataReceived;
  53. App.TcpServer.DetectionDataReceived += TcpServer_DetectionDataReceived;
  54. App.TcpServer.RealTimeDataReceived += TcpServer_RealTimeDataReceived;
  55. App.TcpServer.FaultDataReceived += TcpServer_FaultDataReceived;
  56. App.TcpServer.DetectionRawDataReceived += TcpServer_DetectionRawDataReceived;
  57. App.TcpServer.DetectionRawDataResultReceived += TcpServer_DetectionRawDataResultReceived;
  58. App.TcpServer.DetectionStatusResultReceived += TcpServer_DetectionStatusResultReceived;
  59. App.TcpServer.DebugMessageReceived += TcpServer_DebugMessageReceived;
  60. App.TcpServer.HeartbeatReceived += TcpServer_HeartbeatReceived;
  61. App.TcpServer.UpgradedRequestResultReceived += TcpServer_UpgradedRequestResultReceived;
  62. App.Calibration.ConnectionStateChanged += Calibration_ConnectionStateChanged;
  63. App.Calibration.LimitStateChanged += Calibration_LimitStateChanged;
  64. App.TcpServer.Start();
  65. DataContext = MainView;
  66. }
  67. /// <summary>
  68. /// 接收心跳数据
  69. /// </summary>
  70. private void TcpServer_HeartbeatReceived(object sender, HeartbeatReceviedEventArgs e)
  71. {
  72. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  73. if (equipmentData != null)
  74. {
  75. equipmentData.IsHeartbeatReceived = true;
  76. }
  77. }
  78. /// <summary>
  79. /// 接收调试信息
  80. /// </summary>
  81. private void TcpServer_DebugMessageReceived(object sender, DebugMessageReceivedEventArgs e)
  82. {
  83. if (e.IpAddress.IsNullOrEmpty() && e.SerialNo.IsNullOrEmpty())
  84. {
  85. DebugMessageShow(e.Message);
  86. }
  87. else
  88. {
  89. DebugMessageShow(e.Message, e.IpAddress, e.SerialNo);
  90. }
  91. }
  92. public void DebugMessageShow(string message, string ipAddress, string serialNo)
  93. {
  94. if (App.Config.ShowDebugMessage)
  95. {
  96. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == ipAddress || (serialNo != null && c.SerialNo == serialNo));
  97. if (equipmentData != null)
  98. {
  99. equipmentData.DebugMessage.DateTime = DateTime.Now;
  100. equipmentData.DebugMessage.Message = message;
  101. }
  102. }
  103. }
  104. public void DebugMessageShow(string message)
  105. {
  106. if (App.Config.ShowDebugMessage)
  107. {
  108. MainView.DebugMessage.DateTime = DateTime.Now;
  109. MainView.DebugMessage.Message = message;
  110. }
  111. }
  112. /// <summary>
  113. /// 标定限位状态更改
  114. /// </summary>
  115. private void Calibration_LimitStateChanged(object sender, LimitData limitData)
  116. {
  117. foreach (var equipment in App.DataCenter.Equipments)
  118. {
  119. foreach (var limit in equipment.Limits)
  120. {
  121. if (limit.Name == limitData.Name && limit.IsEnable)
  122. {
  123. if (limitData.State == LimitState.AtLimit)
  124. {
  125. limit.State = LimitState.AtLimit;
  126. // 当前运行状态添加预标定状态
  127. equipment.RunningStatus |= RunningStatus.PreCalibration;
  128. if (App.TcpServer.SendRealTimeAbsolutePositionData((float)limitData.Position, equipment.SerialNo, equipment.ClientSocket))
  129. {
  130. DebugMessageShow($"{limitData.Name}标定成功", equipment.IpAddress, equipment.SerialNo);
  131. }
  132. }
  133. else if (limitData.State == LimitState.NotInLimit)
  134. {
  135. limit.State = LimitState.NotInLimit;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. /// <summary>
  142. /// 标定模块连接状态更改
  143. /// </summary>
  144. private void Calibration_ConnectionStateChanged(object sender, bool isConnect)
  145. {
  146. foreach (var equipment in App.DataCenter.Equipments)
  147. {
  148. foreach (var limit in equipment.Limits)
  149. {
  150. if (isConnect)
  151. {
  152. if (limit.State == LimitState.Offline)
  153. {
  154. limit.State = LimitState.NotInLimit;
  155. }
  156. }
  157. else
  158. {
  159. if (limit.State != LimitState.Offline)
  160. {
  161. limit.State = LimitState.Offline;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// 接收检测状态开关结果
  169. /// </summary>
  170. private void TcpServer_DetectionStatusResultReceived(object sender, DetectionStatusResultReceivedEventArgs e)
  171. {
  172. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  173. if (equipmentData != null)
  174. {
  175. if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreStop))
  176. {
  177. equipmentData.RunningStatus = RunningStatus.Stopped;
  178. Application.Current.Dispatcher.Invoke(() =>
  179. {
  180. NoticeBox.Show("自动检测停止", "通知", MessageBoxIcon.Warning, true, 3000);
  181. });
  182. }
  183. else if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreRunning))
  184. {
  185. equipmentData.RunningStatus = RunningStatus.SpatialNormal;
  186. Application.Current.Dispatcher.Invoke(() =>
  187. {
  188. NoticeBox.Show("自动检测恢复", "通知", MessageBoxIcon.Success, true, 3000);
  189. });
  190. }
  191. else if (equipmentData.RunningStatus.HasFlag(RunningStatus.PreCalibration))
  192. {
  193. equipmentData.RunningStatus = RunningStatus.SpatialNormal;
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 接收故障数据
  199. /// </summary>
  200. private void TcpServer_FaultDataReceived(object sender, FaultDataReceivedEventArgs e)
  201. {
  202. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  203. if (equipmentData != null)
  204. {
  205. if (equipmentData.Faults.TryGetValue(e.FaultData.FaultType, out var faultData))
  206. {
  207. if (e.FaultData.FaultCode == 0)
  208. {
  209. equipmentData.Faults.Remove(e.FaultData.FaultType);
  210. }
  211. else
  212. {
  213. equipmentData.Faults[e.FaultData.FaultType] = e.FaultData;
  214. }
  215. }
  216. else
  217. {
  218. equipmentData.Faults.Add(e.FaultData.FaultType, e.FaultData);
  219. }
  220. Application.Current.Dispatcher.Invoke(() =>
  221. {
  222. if (equipmentData.Messages.Any())
  223. {
  224. equipmentData.Messages.Clear();
  225. }
  226. foreach (var fault in equipmentData.Faults)
  227. {
  228. if (fault.Value != null)
  229. {
  230. equipmentData.Messages.Add(fault.Value.ToString());
  231. }
  232. }
  233. });
  234. }
  235. }
  236. /// <summary>
  237. /// 接收实时数据
  238. /// </summary>
  239. private void TcpServer_RealTimeDataReceived(object sender, RealTimeDataReceivedEventArgs e)
  240. {
  241. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  242. if (equipmentData != null)
  243. {
  244. equipmentData.Speed = Math.Round(e.RealTimeData.Speed * 60, 2);
  245. equipmentData.Position = e.RealTimeData.Position;
  246. equipmentData.RunningStatus = e.RealTimeData.Status;
  247. equipmentData.AbsolutePosition = e.RealTimeData.AbsolutePosition;
  248. equipmentData.LiftHeight = (equipmentData.RopeLength - equipmentData.AbsolutePosition) / equipmentData.LiftHightRatio;
  249. equipmentData.Direction = equipmentData.Speed > 0 ? DirectionState.Forward :
  250. (equipmentData.Speed == 0f ? DirectionState.Stoped : DirectionState.Reverse);
  251. equipmentData.AddSpeedData(equipmentData.Speed);
  252. }
  253. }
  254. /// <summary>
  255. /// 客户端连接成功
  256. /// </summary>
  257. private void TcpServer_ClientConnected(object sender, ClientConnectedEventArgs e)
  258. {
  259. var equipment = App.Config.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  260. if (equipment == null)
  261. {
  262. LogHelper.Error($"未找到设备,IP地址:{e.IpAddress}");
  263. return;
  264. }
  265. var server = (TcpServerFrame)sender;
  266. server.SendTurnLiveStreamData(true, equipment.SerialNo, e.ClientSocket);
  267. Thread.Sleep(20);
  268. server.SendSetClockData(DateTime.Now.DateTimeToTimestamp(), equipment.SerialNo, e.ClientSocket);
  269. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  270. if (equipmentData != null)
  271. {
  272. equipmentData.IsConnect = true;
  273. equipmentData.ClientSocket = e.ClientSocket;
  274. if (equipmentData.RunningStatus != RunningStatus.SpatialNormal)
  275. {
  276. equipmentData.RunningStatus |= RunningStatus.SpatialNormal;
  277. }
  278. }
  279. }
  280. /// <summary>
  281. /// 客户端连接断开
  282. /// </summary>
  283. private void TcpServer_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
  284. {
  285. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  286. if (equipmentData != null)
  287. {
  288. equipmentData.IsConnect = false;
  289. equipmentData.ClientSocket = null;
  290. equipmentData.Speed = 0;
  291. equipmentData.AbsolutePosition = 0;
  292. equipmentData.Position = 0;
  293. equipmentData.Direction = DirectionState.Stoped;
  294. }
  295. }
  296. /// <summary>
  297. /// 接收检测结果
  298. /// </summary>
  299. private void TcpServer_DetectionDataReceived(object sender, DetectionDataReceivedEventArgs e)
  300. {
  301. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  302. if (equipmentData != null)
  303. {
  304. e.DetectionData.DetectionNo = equipmentData.DetectionNo;
  305. equipmentData.DetectionData = e.DetectionData;
  306. }
  307. }
  308. /// <summary>
  309. /// 接检测原始数据结果
  310. /// </summary>
  311. private void TcpServer_DetectionRawDataResultReceived(object sender, DetectionRawDataResultReceivedEventArgs e)
  312. {
  313. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  314. if (equipmentData != null)
  315. {
  316. // 处理检测原始结果数据
  317. if (e.DetectionRawResultData.Code == 0)
  318. {
  319. if (equipmentData.DetectionData != null)
  320. {
  321. equipmentData.DetectionData.RawResultData = e.DetectionRawResultData;
  322. }
  323. }
  324. else
  325. {
  326. LogHelper.Error($"获取检测原始数据失败,错误码:{e.DetectionRawResultData.Code}");
  327. }
  328. }
  329. }
  330. /// <summary>
  331. /// 接受检测结果原始数据
  332. /// </summary>
  333. private async void TcpServer_DetectionRawDataReceived(object sender, DetectionRawDataReceivedEventArgs e)
  334. {
  335. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  336. if (equipmentData != null)
  337. {
  338. if (equipmentData.DisableAlarm)
  339. {
  340. DebugMessageShow($"获取检测结果原始数据结束", equipmentData.IpAddress, equipmentData.SerialNo);
  341. return;
  342. }
  343. await Task.Run(() =>
  344. {
  345. if (equipmentData.DetectionData != null && equipmentData.DetectionData.RawResultData != null)
  346. {
  347. DebugMessageShow($"数据接收:{e.DetectionRawData.PacketNumber}/{e.DetectionRawData.TotalPackets}", equipmentData.IpAddress, equipmentData.SerialNo);
  348. if (e.DetectionRawData.PacketNumber == 1)
  349. {
  350. equipmentData.DetectionData.RawDataReceiving = true;
  351. equipmentData.DetectionData.RawData = new MemoryStream();
  352. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  353. }
  354. else if (e.DetectionRawData.PacketNumber <= e.DetectionRawData.TotalPackets)
  355. {
  356. // 添加原始数据到检测数据中
  357. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  358. // 如果是最后一包数据,处理检测数据
  359. if (e.DetectionRawData.PacketNumber == e.DetectionRawData.TotalPackets)
  360. {
  361. // 生成数据文件路径
  362. (string absolutePath, string relativePath) = DatFileHandler.GetDatFilePath(equipmentData.SerialNo);
  363. // 处理检测数据逻辑
  364. var record = new RecordDto
  365. {
  366. RopeName = equipmentData.RopeName,
  367. RopeNumber = equipmentData.RopeNumber,
  368. StartPoint = equipmentData.DetectionData.StartPoint,
  369. EndPoint = equipmentData.DetectionData.EndPoint,
  370. DetectedSpeed = equipmentData.DetectionData.DetectedSpeed,
  371. DetectionLength = equipmentData.DetectionData.DetectionLength,
  372. StartTime = equipmentData.DetectionData.StartTime.TimestampToDateTime(),
  373. EndTime = equipmentData.DetectionData.EndTime.TimestampToDateTime(),
  374. SensorCount = equipmentData.DetectionData.RawResultData.SensorCount,
  375. SamplingStep = equipmentData.DetectionData.RawResultData.SamplingStep,
  376. DataFilePath = relativePath,
  377. InUseSensors = string.Join(",", equipmentData.InUseSensor)
  378. };
  379. foreach (var damage in equipmentData.DetectionData.Damages)
  380. {
  381. var alarmCount = _alarmRepository.AddAlarm(new AlarmDataModel
  382. {
  383. DamageLevel = damage.DamageLevel,
  384. DamagePosition = damage.DamagePoint,
  385. DamageValue = damage.DamageValue,
  386. RopeNumber = equipmentData.RopeNumber
  387. }, AlarmSourceType.Detection, App.Config.DamageExtent);
  388. if (alarmCount >= App.Config.AlarmValidCount)
  389. {
  390. record.Damages.Add(new DamageDto
  391. {
  392. DamageLevel = damage.DamageLevel,
  393. DamagePoint = damage.DamagePoint,
  394. DamageValue = damage.DamageValue,
  395. });
  396. record.DamageCount++;
  397. //纠正健康度 以客户端上传的损伤数据 重新计算
  398. if ((int)record.RiskLevel < (int)damage.DamageLevel)
  399. {
  400. record.RiskLevel = (RiskLevel)damage.DamageLevel;
  401. }
  402. }
  403. }
  404. equipmentData.RiskLevel = record.RiskLevel;
  405. if (record.DamageCount > 0)
  406. {
  407. int? recordId = _recordRepository.CreateRecord(record);
  408. if (recordId.HasValue)
  409. {
  410. record.Id = recordId.Value;
  411. AddRecordToPageRecords(record);
  412. if (!DatFileHandler.CreateDatFile(absolutePath, equipmentData.DetectionData.RawData))
  413. {
  414. LogHelper.Error($"创建检测数据文件失败,路径:{absolutePath}");
  415. }
  416. DebugMessageShow($"检测数据记录成功", equipmentData.IpAddress, equipmentData.SerialNo);
  417. if ((int)record.RiskLevel >= (int)App.Config.SoundRiskLevel)
  418. {
  419. Application.Current.Dispatcher.Invoke(() =>
  420. {
  421. speech.SpeakAsync($"{equipmentData.RopeName},检测到{record.DamageCount}处损伤");
  422. });
  423. }
  424. }
  425. else
  426. {
  427. LogHelper.Error("检测数据记录失败");
  428. }
  429. }
  430. else
  431. {
  432. DebugMessageShow($"检测完成,未发现损伤,本次检测不做记录。", equipmentData.IpAddress, equipmentData.SerialNo);
  433. }
  434. equipmentData.DetectionData.RawDataReceiving = false;
  435. }
  436. }
  437. }
  438. });
  439. }
  440. }
  441. /// <summary>
  442. /// 接收报警数据
  443. /// </summary>
  444. private void TcpServer_AlarmDataReceived(object sender, AlarmDataReceivedEventArgs e)
  445. {
  446. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  447. if (equipmentData != null && equipmentData.IsSpeedStable && !equipmentData.DisableAlarm)
  448. {
  449. Dispatcher.InvokeAsync(() =>
  450. {
  451. e.AlarmData.RopeNumber = equipmentData.RopeNumber;
  452. var alarmCount = _alarmRepository.AddAlarm(e.AlarmData, AlarmSourceType.RealTime, App.Config.DamageExtent);
  453. if (alarmCount >= App.Config.AlarmValidCount)
  454. {
  455. equipmentData.AddAlarm(e.AlarmData);
  456. }
  457. });
  458. }
  459. }
  460. private void TcpServer_UpgradedRequestResultReceived(object sender, UpgradedResultReceivedEventArgs e)
  461. {
  462. Dispatcher.InvokeAsync(async () =>
  463. {
  464. if (e.Code == 0)
  465. {
  466. await Task.Delay(2000);
  467. string url = $"http://192.168.1.200"; // 替换为您的网页地址
  468. Extensions.Tools.OpenUrl(url);
  469. }
  470. });
  471. }
  472. public void AddRecordToPageRecords(RecordDto record)
  473. {
  474. Application.Current.Dispatcher.Invoke(() =>
  475. {
  476. if (main_frame.Content is Page currentPage && currentPage != null)
  477. {
  478. var simpleRecord = record.ToSimpleRecordDto();
  479. switch (currentPage.Title)
  480. {
  481. case "OneRopePage":
  482. if (currentPage.DataContext is OneRopeViewModel oneRopeView)
  483. {
  484. oneRopeView.AddRecord(simpleRecord);
  485. }
  486. break;
  487. case "TwoRopesPage":
  488. if (currentPage.DataContext is TwoRopesViewModel twoRopesView)
  489. {
  490. twoRopesView.AddRecord(simpleRecord);
  491. }
  492. break;
  493. case "ThreeRopesPage":
  494. if (currentPage.DataContext is ThreeRopesViewModel threeRopesView)
  495. {
  496. threeRopesView.AddRecord(simpleRecord);
  497. }
  498. break;
  499. case "FourRopesPage":
  500. if (currentPage.DataContext is FourRopesViewModel fourRopesView)
  501. {
  502. fourRopesView.AddRecord(simpleRecord);
  503. }
  504. break;
  505. }
  506. }
  507. });
  508. }
  509. private void WindowX_Loaded(object sender, RoutedEventArgs e)
  510. {
  511. NavigateToPage("Home");
  512. }
  513. public void NavigatePage(Uri uri)
  514. {
  515. main_frame.NavigationService.Navigate(uri);
  516. }
  517. private void NavigateToPage(object pageName)
  518. {
  519. switch (pageName)
  520. {
  521. case "Home":
  522. MainView.CurrentPage = "Home";
  523. int equipmentCount = App.Config.Equipments.Count;
  524. switch (equipmentCount)
  525. {
  526. case 1:
  527. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/OneRopePage.xaml", uriKind: UriKind.Relative));
  528. break;
  529. case 2:
  530. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/TwoRopesPage.xaml", uriKind: UriKind.Relative));
  531. break;
  532. case 3:
  533. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/ThreeRopesPage.xaml", uriKind: UriKind.Relative));
  534. break;
  535. case 4:
  536. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/FourRopesPage.xaml", uriKind: UriKind.Relative));
  537. break;
  538. }
  539. break;
  540. case "Record":
  541. MainView.CurrentPage = "Record";
  542. main_frame.NavigationService.Navigate(new Uri($"Pages/RecordPage.xaml", uriKind: UriKind.Relative));
  543. break;
  544. }
  545. }
  546. private void Menu_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  547. {
  548. if (sender is TextBlock menuItem)
  549. {
  550. CleanNavigation(main_frame);
  551. NavigateToPage(menuItem?.Tag);
  552. }
  553. }
  554. private void CleanNavigation(Frame frame)
  555. {
  556. while (frame.CanGoBack)
  557. frame.RemoveBackEntry();
  558. }
  559. private void StackPanel_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  560. {
  561. if (e.ClickCount == 2)
  562. {
  563. Left = 0;
  564. Top = 0;
  565. }
  566. }
  567. private void Setting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  568. {
  569. SettingDialog settingDialog = new SettingDialog();
  570. if (settingDialog.ShowDialog(true) == true)
  571. {
  572. if (settingDialog.IsAutoStart)
  573. {
  574. App.RestartApplication();
  575. }
  576. }
  577. }
  578. private void Window_Closing(object sender, CancelEventArgs e)
  579. {
  580. App.TcpServer?.Dispose();
  581. speech?.Dispose();
  582. }
  583. private void Minimize_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  584. {
  585. WindowState = WindowState.Minimized;
  586. }
  587. private void Close_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  588. {
  589. var result = MessageBoxX.Show(this, "退出后将无法进行实时检测,是否确认退出程序?", "警告",
  590. MessageBoxButton.YesNo,
  591. MessageBoxIcon.Warning, DefaultButton.YesOK);
  592. if (result == MessageBoxResult.Yes)
  593. {
  594. Close();
  595. }
  596. }
  597. private void SwitchToInstance_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  598. {
  599. if (sender is Border instanceBorder && instanceBorder.Tag != null)
  600. {
  601. App.SwitchToExistingInstance(instanceBorder.Tag.ToString());
  602. }
  603. }
  604. }
  605. }