AITPump25.xaml.cs 7.5 KB

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