AITPump.xaml.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. using System.Windows.Media.Imaging;
  7. using Aitex.Core.Common.DeviceData;
  8. using MECF.Framework.Common.OperationCenter;
  9. namespace Aitex.Core.UI.DeviceControl
  10. {
  11. /// <summary>
  12. /// AITPump.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class AITPump : UserControl
  15. {
  16. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  17. "DeviceData", typeof(AITPumpData), typeof(AITPump),
  18. new FrameworkPropertyMetadata(new AITPumpData(), FrameworkPropertyMetadataOptions.AffectsRender));
  19. public AITPumpData DeviceData
  20. {
  21. get
  22. {
  23. return (AITPumpData)this.GetValue(DeviceDataProperty);
  24. }
  25. set
  26. {
  27. this.SetValue(DeviceDataProperty, value);
  28. }
  29. }
  30. public static readonly DependencyProperty EnableControlProperty = DependencyProperty.Register(
  31. "EnableControl", typeof(bool), typeof(AITPump),
  32. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public bool EnableControl
  34. {
  35. get
  36. {
  37. return (bool)this.GetValue(EnableControlProperty);
  38. }
  39. set
  40. {
  41. this.SetValue(EnableControlProperty, value);
  42. }
  43. }
  44. public static readonly DependencyProperty IsShowSpeedProperty = DependencyProperty.Register(
  45. "IsShowSpeed", typeof(bool), typeof(AITPump),
  46. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  47. public bool IsShowSpeed
  48. {
  49. get
  50. {
  51. return (bool)this.GetValue(IsShowSpeedProperty);
  52. }
  53. set
  54. {
  55. this.SetValue(IsShowSpeedProperty, value);
  56. }
  57. }
  58. public static readonly DependencyProperty IsShowSensorProperty = DependencyProperty.Register(
  59. "IsShowSensor", typeof(bool), typeof(AITPump),
  60. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  61. public bool IsShowSensor
  62. {
  63. get
  64. {
  65. return (bool)this.GetValue(IsShowSensorProperty);
  66. }
  67. set
  68. {
  69. this.SetValue(IsShowSensorProperty, value);
  70. }
  71. }
  72. public static readonly DependencyProperty WaterFlowStatusColorProperty = DependencyProperty.Register(
  73. "WaterFlowStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  74. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  75. public SolidColorBrush WaterFlowStatusColor
  76. {
  77. get
  78. {
  79. return (SolidColorBrush)this.GetValue(WaterFlowStatusColorProperty);
  80. }
  81. set
  82. {
  83. this.SetValue(WaterFlowStatusColorProperty, value);
  84. }
  85. }
  86. public static readonly DependencyProperty N2PressureStatusColorProperty = DependencyProperty.Register(
  87. "N2PressureStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  88. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  89. public SolidColorBrush N2PressureStatusColor
  90. {
  91. get
  92. {
  93. return (SolidColorBrush)this.GetValue(N2PressureStatusColorProperty);
  94. }
  95. set
  96. {
  97. this.SetValue(N2PressureStatusColorProperty, value);
  98. }
  99. }
  100. public AITPump()
  101. {
  102. InitializeComponent();
  103. }
  104. protected override void OnRender(DrawingContext drawingContext)
  105. {
  106. base.OnRender(drawingContext);
  107. if (DeviceData == null)
  108. return;
  109. if (DeviceData.IsError || DeviceData.IsOverLoad)
  110. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_error.png"));
  111. else if (DeviceData.IsWarning)
  112. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_warning.png"));
  113. else if (DeviceData.IsOn)
  114. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_on.png"));
  115. else
  116. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_off.png"));
  117. StackPanelN2Pressure.Visibility = (DeviceData.IsN2PressureEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  118. StackPanelWaterFlow.Visibility = (DeviceData.IsWaterFlowEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  119. StackPanelDryPump.Visibility = (DeviceData.IsDryPumpEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  120. WaterFlowStatusColor = DeviceData.WaterFlowAlarm
  121. ? Brushes.Red
  122. : (DeviceData.WaterFlowWarning ? Brushes.Yellow : Brushes.Lime);
  123. N2PressureStatusColor = DeviceData.N2PressureAlarm
  124. ? Brushes.Red
  125. : (DeviceData.N2PressureWarning ? Brushes.Yellow : Brushes.Lime);
  126. txtSpeed.Background = DeviceData.AtSpeed ? Brushes.Transparent : Brushes.LimeGreen;
  127. txtTemp.Background = DeviceData.OverTemp ? Brushes.OrangeRed : Brushes.Transparent;
  128. if (imagePicture.ContextMenu!=null && imagePicture.ContextMenu.Items.Count == 2)
  129. {
  130. ((MenuItem)imagePicture.ContextMenu.Items[0]).IsEnabled = !DeviceData.IsOn;
  131. ((MenuItem)imagePicture.ContextMenu.Items[1]).IsEnabled = DeviceData.IsOn;
  132. }
  133. }
  134. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  135. {
  136. if (DeviceData != null)
  137. {
  138. string tooltipValue =
  139. string.Format("{0}:{1}\r\n\r\nID:{2} ",
  140. "",
  141. DeviceData.DisplayName,
  142. DeviceData.DeviceSchematicId );
  143. ToolTip = tooltipValue;
  144. }
  145. }
  146. private void PumpOn(object sender, RoutedEventArgs e)
  147. {
  148. if (EnableControl)
  149. {
  150. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOn}");
  151. }
  152. }
  153. private void PumpOff(object sender, RoutedEventArgs e)
  154. {
  155. if (EnableControl)
  156. {
  157. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOff}");
  158. }
  159. }
  160. }
  161. }