AITPump.xaml.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 IsAutoModeProperty = DependencyProperty.Register(
  45. "IsAutoMode", typeof(bool), typeof(AITPump),
  46. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  47. public bool IsAutoMode
  48. {
  49. get
  50. {
  51. return (bool)this.GetValue(IsAutoModeProperty);
  52. }
  53. set
  54. {
  55. this.SetValue(IsAutoModeProperty, value);
  56. }
  57. }
  58. public static readonly DependencyProperty IsShowSpeedProperty = DependencyProperty.Register(
  59. "IsShowSpeed", typeof(bool), typeof(AITPump),
  60. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  61. public bool IsShowSpeed
  62. {
  63. get
  64. {
  65. return (bool)this.GetValue(IsShowSpeedProperty);
  66. }
  67. set
  68. {
  69. this.SetValue(IsShowSpeedProperty, value);
  70. }
  71. }
  72. public static readonly DependencyProperty IsShowSensorProperty = DependencyProperty.Register(
  73. "IsShowSensor", typeof(bool), typeof(AITPump),
  74. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  75. public bool IsShowSensor
  76. {
  77. get
  78. {
  79. return (bool)this.GetValue(IsShowSensorProperty);
  80. }
  81. set
  82. {
  83. this.SetValue(IsShowSensorProperty, value);
  84. }
  85. }
  86. public static readonly DependencyProperty WaterFlowStatusColorProperty = DependencyProperty.Register(
  87. "WaterFlowStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  88. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  89. public SolidColorBrush WaterFlowStatusColor
  90. {
  91. get
  92. {
  93. return (SolidColorBrush)this.GetValue(WaterFlowStatusColorProperty);
  94. }
  95. set
  96. {
  97. this.SetValue(WaterFlowStatusColorProperty, value);
  98. }
  99. }
  100. public static readonly DependencyProperty N2PressureStatusColorProperty = DependencyProperty.Register(
  101. "N2PressureStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  102. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  103. public SolidColorBrush N2PressureStatusColor
  104. {
  105. get
  106. {
  107. return (SolidColorBrush)this.GetValue(N2PressureStatusColorProperty);
  108. }
  109. set
  110. {
  111. this.SetValue(N2PressureStatusColorProperty, value);
  112. }
  113. }
  114. public AITPump()
  115. {
  116. InitializeComponent();
  117. }
  118. protected override void OnRender(DrawingContext drawingContext)
  119. {
  120. base.OnRender(drawingContext);
  121. if (DeviceData == null)
  122. return;
  123. if (DeviceData.IsError)
  124. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_error.png"));
  125. else if (DeviceData.IsWarning)
  126. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_warning.png"));
  127. else if (DeviceData.IsOn)
  128. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_on.png"));
  129. else
  130. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/pump_off.png"));
  131. StackPanelN2Pressure.Visibility = (DeviceData.IsN2PressureEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  132. StackPanelWaterFlow.Visibility = (DeviceData.IsWaterFlowEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  133. StackPanelDryPump.Visibility = (DeviceData.IsDryPumpEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  134. WaterFlowStatusColor = DeviceData.WaterFlowAlarm
  135. ? Brushes.Red
  136. : (DeviceData.WaterFlowWarning ? Brushes.Yellow : Brushes.Lime);
  137. N2PressureStatusColor = DeviceData.N2PressureAlarm
  138. ? Brushes.Red
  139. : (DeviceData.N2PressureWarning ? Brushes.Yellow : Brushes.Lime);
  140. txtSpeed.Background = DeviceData.AtSpeed ? Brushes.Transparent : Brushes.LimeGreen;
  141. txtTemp.Background = DeviceData.OverTemp ? Brushes.OrangeRed : Brushes.Transparent;
  142. }
  143. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  144. {
  145. if (DeviceData != null)
  146. {
  147. string tooltipValue =
  148. string.Format("{0}:{1}\r\n\r\nID:{2} ",
  149. "",
  150. DeviceData.DisplayName,
  151. DeviceData.DeviceSchematicId );
  152. ToolTip = tooltipValue;
  153. }
  154. }
  155. private void PumpOn(object sender, RoutedEventArgs e)
  156. {
  157. if (IsAutoMode) return;
  158. if (EnableControl)
  159. {
  160. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOn}");
  161. }
  162. }
  163. private void PumpOff(object sender, RoutedEventArgs e)
  164. {
  165. if (IsAutoMode) return;
  166. if (EnableControl)
  167. {
  168. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOff}");
  169. }
  170. }
  171. }
  172. }