OneRopePage.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /// OneRopePage.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class OneRopePage : Page
  14. {
  15. private readonly IRecordRepository _recordRepository;
  16. public OneRopeViewModel OneRopeView { get; set; }
  17. public OneRopePage()
  18. {
  19. InitializeComponent();
  20. Loaded += OneRopePage_Loaded;
  21. Unloaded += OneRopePage_Unloaded;
  22. _recordRepository = new RecordRepository();
  23. OneRopeView = new OneRopeViewModel
  24. {
  25. EquipmentData = App.DataCenter.Equipments[0],
  26. Records = _recordRepository.GetLastRecords().ToSimpleRecordDtos()
  27. };
  28. OneRopeView.Equipment = App.Config.Equipments.First(c => c.IpAddress == OneRopeView.EquipmentData.IpAddress);
  29. DataContext = OneRopeView;
  30. App.TcpServer.LiveStreamReceived += TcpServer_LiveStreamReceived;
  31. }
  32. private void OneRopePage_Loaded(object sender, System.Windows.RoutedEventArgs e)
  33. {
  34. if (OneRopeView.EquipmentData.ChartSource != null)
  35. {
  36. chartLine.AddDataPoints(OneRopeView.EquipmentData.ChartSource);
  37. }
  38. }
  39. private void OneRopePage_Unloaded(object sender, System.Windows.RoutedEventArgs e)
  40. {
  41. OneRopeView.EquipmentData.ChartSource = chartLine.GetChartSource();
  42. }
  43. private async void TcpServer_LiveStreamReceived(object sender, LiveStreamReceivedEventArgs e)
  44. {
  45. if (e.IpAddress == OneRopeView.EquipmentData.IpAddress)
  46. {
  47. if (OneRopeView.EquipmentData.DetectionData?.DetectionNo == OneRopeView.EquipmentData.DetectionNo)
  48. {
  49. OneRopeView.EquipmentData.ClearData();
  50. }
  51. await Task.Run(() =>
  52. {
  53. chartLine.AddDataPoints((OneRopeView.EquipmentData.AbsolutePosition, e.LiveStream),OneRopeView.EquipmentData.InUseSensor);
  54. });
  55. }
  56. }
  57. private void AlarmDetail_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  58. {
  59. DamagesDialog damagesDialog = new DamagesDialog(OneRopeView.EquipmentData.Alarms);
  60. damagesDialog.ShowDialog(true);
  61. }
  62. private void ParameterSetting_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  63. {
  64. ParameterDialog parameterDialog = new ParameterDialog(OneRopeView.Equipment, OneRopeView.EquipmentData.ClientSocket, OneRopeView.EquipmentData.RunningStatus);
  65. parameterDialog.ShowDialog(true);
  66. }
  67. }
  68. }