AITTurboPump.xaml.cs 7.1 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. /// AITTurboPump.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class AITTurboPump : UserControl
  15. {
  16. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  17. "DeviceData", typeof(AITPumpData), typeof(AITTurboPump),
  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(AITTurboPump),
  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(AITTurboPump),
  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(AITTurboPump),
  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(AITTurboPump),
  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(AITTurboPump),
  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 AITTurboPump()
  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. {
  111. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/TurboPump/pump_error.png"));
  112. txtState.Text = "Error";
  113. }
  114. else if (DeviceData.IsWarning)
  115. {
  116. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/TurboPump/pump_warning.png"));
  117. txtState.Text = "Warning";
  118. }
  119. else if (DeviceData.IsOk)
  120. {
  121. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/TurboPump/pump_on.png"));
  122. txtState.Text = "OK";
  123. }
  124. else if (DeviceData.IsOn)
  125. {
  126. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/TurboPump/pump_on.png"));
  127. txtState.Text = "ON";
  128. }
  129. else
  130. {
  131. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Pump/TurboPump/pump_off.png"));
  132. txtState.Text = "OFF";
  133. }
  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 && DeviceData.IsOn ? Brushes.LimeGreen : Brushes.Transparent;
  141. if (imagePicture.ContextMenu!=null && imagePicture.ContextMenu.Items.Count == 2)
  142. {
  143. ((MenuItem)imagePicture.ContextMenu.Items[0]).IsEnabled = !DeviceData.IsOn;
  144. ((MenuItem)imagePicture.ContextMenu.Items[1]).IsEnabled = DeviceData.IsOn;
  145. }
  146. }
  147. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  148. {
  149. if (DeviceData != null)
  150. {
  151. string tooltipValue =
  152. string.Format("{0}:{1}\r\n\r\nID:{2} ",
  153. "",
  154. DeviceData.DisplayName,
  155. DeviceData.DeviceSchematicId );
  156. ToolTip = tooltipValue;
  157. }
  158. }
  159. private void PumpOn(object sender, RoutedEventArgs e)
  160. {
  161. if (EnableControl)
  162. {
  163. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOn}");
  164. }
  165. }
  166. private void PumpOff(object sender, RoutedEventArgs e)
  167. {
  168. if (EnableControl)
  169. {
  170. InvokeClient.Instance.Service.DoOperation($"{DeviceData.DeviceModule}.{DeviceData.DeviceName}.{AITPumpOperation.PumpOff}");
  171. }
  172. }
  173. }
  174. }