TwoRopesPage.xaml.cs 4.9 KB

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