TwoRopesPage.xaml.cs 5.0 KB

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