MainWindow.xaml.cs 27 KB

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