AITPump.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. namespace Aitex.Core.UI.DeviceControl
  9. {
  10. /// <summary>
  11. /// AITPump.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class AITPump : UserControl
  14. {
  15. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  16. "DeviceData", typeof(AITPumpData), typeof(AITPump),
  17. new FrameworkPropertyMetadata(new AITPumpData(), FrameworkPropertyMetadataOptions.AffectsRender));
  18. public AITPumpData DeviceData
  19. {
  20. get
  21. {
  22. return (AITPumpData)this.GetValue(DeviceDataProperty);
  23. }
  24. set
  25. {
  26. this.SetValue(DeviceDataProperty, value);
  27. }
  28. }
  29. public static readonly DependencyProperty IsShowSensorProperty = DependencyProperty.Register(
  30. "IsShowSensor", typeof(bool), typeof(AITPump),
  31. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public bool IsShowSensor
  33. {
  34. get
  35. {
  36. return (bool)this.GetValue(IsShowSensorProperty);
  37. }
  38. set
  39. {
  40. this.SetValue(IsShowSensorProperty, value);
  41. }
  42. }
  43. public static readonly DependencyProperty WaterFlowStatusColorProperty = DependencyProperty.Register(
  44. "WaterFlowStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  45. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  46. public SolidColorBrush WaterFlowStatusColor
  47. {
  48. get
  49. {
  50. return (SolidColorBrush)this.GetValue(WaterFlowStatusColorProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(WaterFlowStatusColorProperty, value);
  55. }
  56. }
  57. public static readonly DependencyProperty N2PressureStatusColorProperty = DependencyProperty.Register(
  58. "N2PressureStatusColor", typeof(SolidColorBrush), typeof(AITPump),
  59. new FrameworkPropertyMetadata(Brushes.DarkGray, FrameworkPropertyMetadataOptions.AffectsRender));
  60. public SolidColorBrush N2PressureStatusColor
  61. {
  62. get
  63. {
  64. return (SolidColorBrush)this.GetValue(N2PressureStatusColorProperty);
  65. }
  66. set
  67. {
  68. this.SetValue(N2PressureStatusColorProperty, value);
  69. }
  70. }
  71. public AITPump()
  72. {
  73. InitializeComponent();
  74. }
  75. protected override void OnRender(DrawingContext drawingContext)
  76. {
  77. base.OnRender(drawingContext);
  78. if (DeviceData == null)
  79. return;
  80. if (DeviceData.IsError)
  81. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Pump/pump_error.png"));
  82. else if (DeviceData.IsWarning)
  83. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Pump/pump_warning.png"));
  84. else if (DeviceData.IsOn)
  85. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Pump/pump_on.png"));
  86. else
  87. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Pump/pump_off.png"));
  88. StackPanelN2Pressure.Visibility = (DeviceData.IsN2PressureEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  89. StackPanelWaterFlow.Visibility = (DeviceData.IsWaterFlowEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  90. StackPanelDryPump.Visibility = (DeviceData.IsDryPumpEnable && IsShowSensor) ? Visibility.Visible : Visibility.Hidden;
  91. WaterFlowStatusColor = DeviceData.WaterFlowAlarm
  92. ? Brushes.Red
  93. : (DeviceData.WaterFlowWarning ? Brushes.Yellow : Brushes.Lime);
  94. N2PressureStatusColor = DeviceData.N2PressureAlarm
  95. ? Brushes.Red
  96. : (DeviceData.N2PressureWarning ? Brushes.Yellow : Brushes.Lime);
  97. }
  98. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  99. {
  100. if (DeviceData != null)
  101. {
  102. string tooltipValue =
  103. string.Format(Application.Current.Resources["GlobalLableFlowMeterToolTip"].ToString(),
  104. "",
  105. DeviceData.DisplayName,
  106. DeviceData.DeviceSchematicId,
  107. DeviceData.WaterFlow.ToString("F1"),
  108. "");
  109. ToolTip = tooltipValue;
  110. }
  111. }
  112. }
  113. }