MainWindow.xaml.cs 26 KB

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