MainWindow.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. if (equipmentData.Messages.Any())
  221. {
  222. equipmentData.Messages.Clear();
  223. }
  224. foreach (var fault in equipmentData.Faults)
  225. {
  226. if (fault.Value != null)
  227. {
  228. equipmentData.Messages.Add(fault.Value.ToString());
  229. }
  230. }
  231. }
  232. }
  233. /// <summary>
  234. /// 接收实时数据
  235. /// </summary>
  236. private void TcpServer_RealTimeDataReceived(object sender, RealTimeDataReceivedEventArgs e)
  237. {
  238. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  239. if (equipmentData != null)
  240. {
  241. equipmentData.Speed = Math.Round(e.RealTimeData.Speed * 60, 2);
  242. equipmentData.Position = e.RealTimeData.Position;
  243. equipmentData.RunningStatus = e.RealTimeData.Status;
  244. equipmentData.AbsolutePosition = e.RealTimeData.AbsolutePosition;
  245. equipmentData.LiftHeight = (equipmentData.RopeLength - equipmentData.AbsolutePosition) / equipmentData.LiftHightRatio;
  246. equipmentData.Direction = equipmentData.Speed > 0 ? DirectionState.Forward :
  247. (equipmentData.Speed == 0f ? DirectionState.Stoped : DirectionState.Reverse);
  248. equipmentData.AddSpeedData(equipmentData.Speed);
  249. }
  250. }
  251. /// <summary>
  252. /// 客户端连接成功
  253. /// </summary>
  254. private void TcpServer_ClientConnected(object sender, ClientConnectedEventArgs e)
  255. {
  256. var equipment = App.Config.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  257. if (equipment == null)
  258. {
  259. LogHelper.Error($"未找到设备,IP地址:{e.IpAddress}");
  260. return;
  261. }
  262. var server = (TcpServerFrame)sender;
  263. server.SendTurnLiveStreamData(true, equipment.SerialNo, e.ClientSocket);
  264. Thread.Sleep(20);
  265. server.SendSetClockData(DateTime.Now.DateTimeToTimestamp(), equipment.SerialNo, e.ClientSocket);
  266. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  267. if (equipmentData != null)
  268. {
  269. equipmentData.IsConnect = true;
  270. equipmentData.ClientSocket = e.ClientSocket;
  271. if (equipmentData.RunningStatus != RunningStatus.SpatialNormal)
  272. {
  273. equipmentData.RunningStatus |= RunningStatus.SpatialNormal;
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// 客户端连接断开
  279. /// </summary>
  280. private void TcpServer_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
  281. {
  282. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  283. if (equipmentData != null)
  284. {
  285. equipmentData.IsConnect = false;
  286. equipmentData.ClientSocket = null;
  287. equipmentData.Speed = 0;
  288. equipmentData.AbsolutePosition = 0;
  289. equipmentData.Position = 0;
  290. equipmentData.Direction = DirectionState.Stoped;
  291. }
  292. }
  293. /// <summary>
  294. /// 接收检测结果
  295. /// </summary>
  296. private void TcpServer_DetectionDataReceived(object sender, DetectionDataReceivedEventArgs e)
  297. {
  298. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  299. if (equipmentData != null)
  300. {
  301. e.DetectionData.DetectionNo = equipmentData.DetectionNo;
  302. equipmentData.DetectionData = e.DetectionData;
  303. }
  304. }
  305. /// <summary>
  306. /// 接检测原始数据结果
  307. /// </summary>
  308. private void TcpServer_DetectionRawDataResultReceived(object sender, DetectionRawDataResultReceivedEventArgs e)
  309. {
  310. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  311. if (equipmentData != null)
  312. {
  313. // 处理检测原始结果数据
  314. if (e.DetectionRawResultData.Code == 0)
  315. {
  316. if (equipmentData.DetectionData != null)
  317. {
  318. equipmentData.DetectionData.RawResultData = e.DetectionRawResultData;
  319. }
  320. }
  321. else
  322. {
  323. LogHelper.Error($"获取检测原始数据失败,错误码:{e.DetectionRawResultData.Code}");
  324. }
  325. }
  326. }
  327. /// <summary>
  328. /// 接受检测结果原始数据
  329. /// </summary>
  330. private async void TcpServer_DetectionRawDataReceived(object sender, DetectionRawDataReceivedEventArgs e)
  331. {
  332. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  333. if (equipmentData != null)
  334. {
  335. if (equipmentData.DisableAlarm)
  336. {
  337. DebugMessageShow($"获取检测结果原始数据结束", equipmentData.IpAddress, equipmentData.SerialNo);
  338. return;
  339. }
  340. await Task.Run(() =>
  341. {
  342. if (equipmentData.DetectionData != null && equipmentData.DetectionData.RawResultData != null)
  343. {
  344. DebugMessageShow($"数据接收:{e.DetectionRawData.PacketNumber}/{e.DetectionRawData.TotalPackets}", equipmentData.IpAddress, equipmentData.SerialNo);
  345. if (e.DetectionRawData.PacketNumber == 1)
  346. {
  347. equipmentData.DetectionData.RawDataReceiving = true;
  348. equipmentData.DetectionData.RawData = new MemoryStream();
  349. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  350. }
  351. else if (e.DetectionRawData.PacketNumber <= e.DetectionRawData.TotalPackets)
  352. {
  353. // 添加原始数据到检测数据中
  354. equipmentData.DetectionData.RawData.Write(e.DetectionRawData.Data, 0, e.DetectionRawData.Data.Length);
  355. // 如果是最后一包数据,处理检测数据
  356. if (e.DetectionRawData.PacketNumber == e.DetectionRawData.TotalPackets)
  357. {
  358. // 生成数据文件路径
  359. (string absolutePath, string relativePath) = DatFileHandler.GetDatFilePath(equipmentData.SerialNo);
  360. // 处理检测数据逻辑
  361. var record = new RecordDto
  362. {
  363. RopeName = equipmentData.RopeName,
  364. RopeNumber = equipmentData.RopeNumber,
  365. StartPoint = equipmentData.DetectionData.StartPoint,
  366. EndPoint = equipmentData.DetectionData.EndPoint,
  367. DetectedSpeed = equipmentData.DetectionData.DetectedSpeed,
  368. DetectionLength = equipmentData.DetectionData.DetectionLength,
  369. StartTime = equipmentData.DetectionData.StartTime.TimestampToDateTime(),
  370. EndTime = equipmentData.DetectionData.EndTime.TimestampToDateTime(),
  371. SensorCount = equipmentData.DetectionData.RawResultData.SensorCount,
  372. SamplingStep = equipmentData.DetectionData.RawResultData.SamplingStep,
  373. DataFilePath = relativePath,
  374. InUseSensors = string.Join(",", equipmentData.InUseSensor)
  375. };
  376. foreach (var damage in equipmentData.DetectionData.Damages)
  377. {
  378. var alarmCount = _alarmRepository.AddAlarm(new AlarmDataModel
  379. {
  380. DamageLevel = damage.DamageLevel,
  381. DamagePosition = damage.DamagePoint,
  382. DamageValue = damage.DamageValue,
  383. RopeNumber = equipmentData.RopeNumber
  384. }, AlarmSourceType.Detection, App.Config.DamageExtent);
  385. if (alarmCount >= App.Config.AlarmValidCount)
  386. {
  387. record.Damages.Add(new DamageDto
  388. {
  389. DamageLevel = damage.DamageLevel,
  390. DamagePoint = damage.DamagePoint,
  391. DamageValue = damage.DamageValue,
  392. });
  393. record.DamageCount++;
  394. //纠正健康度 以客户端上传的损伤数据 重新计算
  395. if ((int)record.RiskLevel < (int)damage.DamageLevel)
  396. {
  397. record.RiskLevel = (RiskLevel)damage.DamageLevel;
  398. }
  399. }
  400. }
  401. equipmentData.RiskLevel = record.RiskLevel;
  402. if (record.DamageCount > 0)
  403. {
  404. int? recordId = _recordRepository.CreateRecord(record);
  405. if (recordId.HasValue)
  406. {
  407. record.Id = recordId.Value;
  408. AddRecordToPageRecords(record);
  409. if (!DatFileHandler.CreateDatFile(absolutePath, equipmentData.DetectionData.RawData))
  410. {
  411. LogHelper.Error($"创建检测数据文件失败,路径:{absolutePath}");
  412. }
  413. DebugMessageShow($"检测数据记录成功", equipmentData.IpAddress, equipmentData.SerialNo);
  414. if ((int)record.RiskLevel >= (int)App.Config.SoundRiskLevel)
  415. {
  416. Application.Current.Dispatcher.Invoke(() =>
  417. {
  418. speech.SpeakAsync($"{equipmentData.RopeName},检测到{record.DamageCount}处损伤");
  419. });
  420. }
  421. }
  422. else
  423. {
  424. LogHelper.Error("检测数据记录失败");
  425. }
  426. }
  427. else
  428. {
  429. DebugMessageShow($"检测完成,未发现损伤,本次检测不做记录。", equipmentData.IpAddress, equipmentData.SerialNo);
  430. }
  431. equipmentData.DetectionData.RawDataReceiving = false;
  432. }
  433. }
  434. }
  435. });
  436. }
  437. }
  438. /// <summary>
  439. /// 接收报警数据
  440. /// </summary>
  441. private void TcpServer_AlarmDataReceived(object sender, AlarmDataReceivedEventArgs e)
  442. {
  443. var equipmentData = App.DataCenter.Equipments.FirstOrDefault(c => c.IpAddress == e.IpAddress);
  444. if (equipmentData != null && equipmentData.IsSpeedStable && !equipmentData.DisableAlarm)
  445. {
  446. Dispatcher.InvokeAsync(() =>
  447. {
  448. e.AlarmData.RopeNumber = equipmentData.RopeNumber;
  449. var alarmCount = _alarmRepository.AddAlarm(e.AlarmData, AlarmSourceType.RealTime, App.Config.DamageExtent);
  450. if (alarmCount >= App.Config.AlarmValidCount)
  451. {
  452. equipmentData.AddAlarm(e.AlarmData);
  453. }
  454. });
  455. }
  456. }
  457. private void TcpServer_UpgradedRequestResultReceived(object sender, UpgradedResultReceivedEventArgs e)
  458. {
  459. Dispatcher.InvokeAsync(async () =>
  460. {
  461. if (e.Code == 0)
  462. {
  463. await Task.Delay(2000);
  464. string url = $"http://192.168.1.200"; // 替换为您的网页地址
  465. Extensions.Tools.OpenUrl(url);
  466. }
  467. });
  468. }
  469. public void AddRecordToPageRecords(RecordDto record)
  470. {
  471. Application.Current.Dispatcher.Invoke(() =>
  472. {
  473. if (main_frame.Content is Page currentPage && currentPage != null)
  474. {
  475. var simpleRecord = record.ToSimpleRecordDto();
  476. switch (currentPage.Title)
  477. {
  478. case "OneRopePage":
  479. if (currentPage.DataContext is OneRopeViewModel oneRopeView)
  480. {
  481. oneRopeView.AddRecord(simpleRecord);
  482. }
  483. break;
  484. case "TwoRopesPage":
  485. if (currentPage.DataContext is TwoRopesViewModel twoRopesView)
  486. {
  487. twoRopesView.AddRecord(simpleRecord);
  488. }
  489. break;
  490. case "ThreeRopesPage":
  491. if (currentPage.DataContext is ThreeRopesViewModel threeRopesView)
  492. {
  493. threeRopesView.AddRecord(simpleRecord);
  494. }
  495. break;
  496. case "FourRopesPage":
  497. if (currentPage.DataContext is FourRopesViewModel fourRopesView)
  498. {
  499. fourRopesView.AddRecord(simpleRecord);
  500. }
  501. break;
  502. }
  503. }
  504. });
  505. }
  506. private void WindowX_Loaded(object sender, RoutedEventArgs e)
  507. {
  508. NavigateToPage("Home");
  509. }
  510. public void NavigatePage(Uri uri)
  511. {
  512. main_frame.NavigationService.Navigate(uri);
  513. }
  514. private void NavigateToPage(object pageName)
  515. {
  516. switch (pageName)
  517. {
  518. case "Home":
  519. MainView.CurrentPage = "Home";
  520. int equipmentCount = App.Config.Equipments.Count;
  521. switch (equipmentCount)
  522. {
  523. case 1:
  524. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/OneRopePage.xaml", uriKind: UriKind.Relative));
  525. break;
  526. case 2:
  527. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/TwoRopesPage.xaml", uriKind: UriKind.Relative));
  528. break;
  529. case 3:
  530. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/ThreeRopesPage.xaml", uriKind: UriKind.Relative));
  531. break;
  532. case 4:
  533. main_frame.NavigationService.Navigate(new Uri($"Pages/RealTime/FourRopesPage.xaml", uriKind: UriKind.Relative));
  534. break;
  535. }
  536. break;
  537. case "Record":
  538. MainView.CurrentPage = "Record";
  539. main_frame.NavigationService.Navigate(new Uri($"Pages/RecordPage.xaml", uriKind: UriKind.Relative));
  540. break;
  541. }
  542. }
  543. private void Menu_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  544. {
  545. if (sender is TextBlock menuItem)
  546. {
  547. CleanNavigation(main_frame);
  548. NavigateToPage(menuItem?.Tag);
  549. }
  550. }
  551. private void CleanNavigation(Frame frame)
  552. {
  553. while (frame.CanGoBack)
  554. frame.RemoveBackEntry();
  555. }
  556. private void StackPanel_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  557. {
  558. if (e.ClickCount == 2)
  559. {
  560. Left = 0;
  561. Top = 0;
  562. }
  563. }
  564. private void Setting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  565. {
  566. SettingDialog settingDialog = new SettingDialog();
  567. if (settingDialog.ShowDialog(true) == true)
  568. {
  569. if (settingDialog.IsAutoStart)
  570. {
  571. App.RestartApplication();
  572. }
  573. }
  574. }
  575. private void Window_Closing(object sender, CancelEventArgs e)
  576. {
  577. App.TcpServer?.Dispose();
  578. speech?.Dispose();
  579. }
  580. private void Minimize_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  581. {
  582. WindowState = WindowState.Minimized;
  583. }
  584. private void Close_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  585. {
  586. var result = MessageBoxX.Show(this, "退出后将无法进行实时检测,是否确认退出程序?", "警告",
  587. MessageBoxButton.YesNo,
  588. MessageBoxIcon.Warning, DefaultButton.YesOK);
  589. if (result == MessageBoxResult.Yes)
  590. {
  591. Close();
  592. }
  593. }
  594. private void SwitchToInstance_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  595. {
  596. if (sender is Border instanceBorder && instanceBorder.Tag != null)
  597. {
  598. App.SwitchToExistingInstance(instanceBorder.Tag.ToString());
  599. }
  600. }
  601. }
  602. }