ThreeRopesPage.xaml.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using SWRIS.Core;
  2. using SWRIS.Dtos;
  3. using SWRIS.Events;
  4. using SWRIS.Extensions;
  5. using SWRIS.Models.ViewModel;
  6. using SWRIS.Repository;
  7. using System;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using System.Windows.Controls;
  12. namespace SWRIS.Pages.RealTime
  13. {
  14. /// <summary>
  15. /// ThreeRopesPage.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class ThreeRopesPage : Page
  18. {
  19. private readonly IRecordRepository _recordRepository;
  20. public ThreeRopesViewModel ThreeRopesView { get; set; }
  21. public ThreeRopesPage()
  22. {
  23. InitializeComponent();
  24. _recordRepository = new RecordRepository();
  25. Loaded += OneRopePage_Loaded;
  26. Unloaded += OneRopePage_Unloaded;
  27. ThreeRopesView = new ThreeRopesViewModel
  28. {
  29. FirstEquipmentData = App.DataCenter.Equipments[0],
  30. SecondEquipmentData = App.DataCenter.Equipments[1],
  31. ThirdEquipmentData = App.DataCenter.Equipments[2],
  32. Records = _recordRepository.GetLastRecords().ToSimpleRecordDtos()
  33. };
  34. ThreeRopesView.FirstEquipment = App.Config.Equipments.First(c => c.IpAddress == ThreeRopesView.FirstEquipmentData.IpAddress);
  35. ThreeRopesView.SecondEquipment = App.Config.Equipments.First(c => c.IpAddress == ThreeRopesView.SecondEquipmentData.IpAddress);
  36. ThreeRopesView.ThirdEquipment = App.Config.Equipments.First(c => c.IpAddress == ThreeRopesView.ThirdEquipmentData.IpAddress);
  37. DataContext = ThreeRopesView;
  38. App.TcpServer.LiveStreamReceived += TcpServer_LiveStreamReceived;
  39. }
  40. private void OneRopePage_Loaded(object sender, System.Windows.RoutedEventArgs e)
  41. {
  42. if (ThreeRopesView.FirstEquipmentData.ChartSource != null)
  43. {
  44. firstChartLine.AddDataPoints(ThreeRopesView.FirstEquipmentData.ChartSource);
  45. }
  46. if (ThreeRopesView.SecondEquipmentData.ChartSource != null)
  47. {
  48. secondChartLine.AddDataPoints(ThreeRopesView.SecondEquipmentData.ChartSource);
  49. }
  50. if (ThreeRopesView.ThirdEquipmentData.ChartSource != null)
  51. {
  52. thirdChartLine.AddDataPoints(ThreeRopesView.ThirdEquipmentData.ChartSource);
  53. }
  54. }
  55. private void OneRopePage_Unloaded(object sender, System.Windows.RoutedEventArgs e)
  56. {
  57. ThreeRopesView.FirstEquipmentData.ChartSource = firstChartLine.GetChartSource();
  58. ThreeRopesView.SecondEquipmentData.ChartSource = secondChartLine.GetChartSource();
  59. ThreeRopesView.ThirdEquipmentData.ChartSource = thirdChartLine.GetChartSource();
  60. }
  61. private async void TcpServer_LiveStreamReceived(object sender, LiveStreamReceivedEventArgs e)
  62. {
  63. if (e.IpAddress == ThreeRopesView.FirstEquipment.IpAddress)
  64. {
  65. if (ThreeRopesView.FirstEquipmentData.DetectionData?.DetectionNo == ThreeRopesView.FirstEquipmentData.DetectionNo)
  66. {
  67. ThreeRopesView.FirstEquipmentData.ClearData();
  68. }
  69. await Task.Run(() =>
  70. {
  71. firstChartLine.AddDataPoints((ThreeRopesView.FirstEquipmentData.AbsolutePosition, e.LiveStream), ThreeRopesView.FirstEquipmentData.InUseSensor);
  72. });
  73. }
  74. else if (e.IpAddress == ThreeRopesView.SecondEquipmentData.IpAddress)
  75. {
  76. if (ThreeRopesView.SecondEquipmentData.DetectionData?.DetectionNo == ThreeRopesView.SecondEquipmentData.DetectionNo)
  77. {
  78. ThreeRopesView.SecondEquipmentData.ClearData();
  79. }
  80. await Task.Run(() =>
  81. {
  82. secondChartLine.AddDataPoints((ThreeRopesView.SecondEquipmentData.AbsolutePosition, e.LiveStream), ThreeRopesView.SecondEquipmentData.InUseSensor);
  83. });
  84. }
  85. else if (e.IpAddress == ThreeRopesView.ThirdEquipmentData.IpAddress)
  86. {
  87. if (ThreeRopesView.ThirdEquipmentData.DetectionData?.DetectionNo == ThreeRopesView.ThirdEquipmentData.DetectionNo)
  88. {
  89. ThreeRopesView.ThirdEquipmentData.ClearData();
  90. }
  91. await Task.Run(() =>
  92. {
  93. thirdChartLine.AddDataPoints((ThreeRopesView.ThirdEquipmentData.AbsolutePosition, e.LiveStream), ThreeRopesView.ThirdEquipmentData.InUseSensor);
  94. });
  95. }
  96. }
  97. private void FirstEquipmentAlarm_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  98. {
  99. DamagesDialog damagesDialog = new DamagesDialog(ThreeRopesView.FirstEquipmentData.Alarms);
  100. damagesDialog.ShowDialog(true);
  101. }
  102. private void SecondEquipmentAlarm_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  103. {
  104. DamagesDialog damagesDialog = new DamagesDialog(ThreeRopesView.SecondEquipmentData.Alarms);
  105. damagesDialog.ShowDialog(true);
  106. }
  107. private void ThreeEquipmentAlarm_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  108. {
  109. DamagesDialog damagesDialog = new DamagesDialog(ThreeRopesView.ThirdEquipmentData.Alarms);
  110. damagesDialog.ShowDialog(true);
  111. }
  112. private void FirstParameterSetting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  113. {
  114. ParameterDialog parameterDialog = new ParameterDialog(ThreeRopesView.FirstEquipment,
  115. ThreeRopesView.FirstEquipmentData.ClientSocket,
  116. ThreeRopesView.FirstEquipmentData.RunningStatus);
  117. parameterDialog.ShowDialog(true);
  118. }
  119. private void SecondParameterSetting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  120. {
  121. ParameterDialog parameterDialog = new ParameterDialog(ThreeRopesView.SecondEquipment,
  122. ThreeRopesView.SecondEquipmentData.ClientSocket,
  123. ThreeRopesView.SecondEquipmentData.RunningStatus);
  124. parameterDialog.ShowDialog(true);
  125. }
  126. private void ThreeParameterSetting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  127. {
  128. ParameterDialog parameterDialog = new ParameterDialog(ThreeRopesView.ThirdEquipment,
  129. ThreeRopesView.ThirdEquipmentData.ClientSocket,
  130. ThreeRopesView.ThirdEquipmentData.RunningStatus);
  131. parameterDialog.ShowDialog(true);
  132. }
  133. }
  134. }