ChillerControl.xaml.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Aitex.Core.Common.DeviceData;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using System.Windows.Media.Imaging;
  7. using MECF.Framework.Common.OperationCenter;
  8. namespace MECF.Framework.UI.Client.Ctrlib.UnitControls
  9. {
  10. /// <summary>
  11. /// ChillerControl.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class ChillerControl : UserControl
  14. {
  15. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  16. "DeviceData", typeof(AITChillerData), typeof(ChillerControl),
  17. new FrameworkPropertyMetadata(new AITChillerData(), FrameworkPropertyMetadataOptions.AffectsRender));
  18. public AITChillerData DeviceData
  19. {
  20. get
  21. {
  22. return (AITChillerData)this.GetValue(DeviceDataProperty);
  23. }
  24. set
  25. {
  26. this.SetValue(DeviceDataProperty, value);
  27. }
  28. }
  29. public static readonly DependencyProperty EnableControlProperty = DependencyProperty.Register(
  30. "EnableControl", typeof(bool), typeof(ChillerControl),
  31. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public bool EnableControl
  33. {
  34. get
  35. {
  36. return (bool)this.GetValue(EnableControlProperty);
  37. }
  38. set
  39. {
  40. this.SetValue(EnableControlProperty, value);
  41. }
  42. }
  43. public ChillerControl()
  44. {
  45. InitializeComponent();
  46. }
  47. protected override void OnRender(DrawingContext drawingContext)
  48. {
  49. base.OnRender(drawingContext);
  50. if (DeviceData == null)
  51. return;
  52. if (DeviceData.IsError)
  53. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.UI.Client;component/Resources/Images/units/chiller_right_error.png"));
  54. else if (DeviceData.IsRunning)
  55. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.UI.Client;component/Resources/Images/units/chiller_right_on.png"));
  56. else
  57. imagePicture.Source = new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.UI.Client;component/Resources/Images/units/chiller_right_off.png"));
  58. if (imagePicture.ContextMenu != null && imagePicture.ContextMenu.Items.Count == 2)
  59. {
  60. ((MenuItem)imagePicture.ContextMenu.Items[0]).IsEnabled = !DeviceData.IsRunning;
  61. ((MenuItem)imagePicture.ContextMenu.Items[1]).IsEnabled = DeviceData.IsRunning;
  62. }
  63. }
  64. private void ChillerOn(object sender, RoutedEventArgs e)
  65. {
  66. if (EnableControl)
  67. {
  68. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITChillerOperation.ChillerOn}");
  69. }
  70. }
  71. private void ChillerOff(object sender, RoutedEventArgs e)
  72. {
  73. if (EnableControl)
  74. {
  75. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITChillerOperation.ChillerOff}");
  76. }
  77. }
  78. }
  79. }