AITIsoGasValve.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.Common.DeviceData;
  15. using Aitex.Core.UI.Control;
  16. using MECF.Framework.Common.OperationCenter;
  17. namespace Aitex.Core.UI.DeviceControl
  18. {
  19. /// <summary>
  20. /// TexGasValve.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class AITIsoGasValve : UserControl
  23. {
  24. // define dependency properties
  25. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  26. "Command", typeof(ICommand), typeof(AITIsoGasValve),
  27. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  28. public ICommand Command
  29. {
  30. get
  31. {
  32. return (ICommand)this.GetValue(CommandProperty);
  33. }
  34. set
  35. {
  36. this.SetValue(CommandProperty, value);
  37. }
  38. }
  39. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  40. "DeviceData", typeof(AITCylinderData), typeof(AITIsoGasValve),
  41. new FrameworkPropertyMetadata(new AITCylinderData(), FrameworkPropertyMetadataOptions.AffectsRender));
  42. public AITCylinderData DeviceData
  43. {
  44. get
  45. {
  46. return (AITCylinderData)this.GetValue(DeviceDataProperty);
  47. }
  48. set
  49. {
  50. this.SetValue(DeviceDataProperty, value);
  51. }
  52. }
  53. public static readonly DependencyProperty EnableServiceControlProperty = DependencyProperty.Register(
  54. "EnableServiceControl", typeof(bool), typeof(AITIsoGasValve),
  55. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  56. public bool EnableServiceControl
  57. {
  58. get
  59. {
  60. return (bool)this.GetValue(EnableServiceControlProperty);
  61. }
  62. set
  63. {
  64. this.SetValue(EnableServiceControlProperty, value);
  65. }
  66. }
  67. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  68. "DeviceData2", typeof(AITCylinderData), typeof(AITIsoGasValve),
  69. new FrameworkPropertyMetadata(new AITCylinderData(), FrameworkPropertyMetadataOptions.AffectsRender));
  70. public AITCylinderData DeviceData2
  71. {
  72. get
  73. {
  74. return (AITCylinderData)this.GetValue(DeviceData2Property);
  75. }
  76. set
  77. {
  78. this.SetValue(DeviceData2Property, value);
  79. }
  80. }
  81. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  82. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITIsoGasValve),
  83. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  84. public LineOrientation ValveOpenOrientation
  85. {
  86. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  87. set { SetValue(ValveOpenOrientationProperty, value); }
  88. }
  89. public AITIsoGasValve()
  90. {
  91. InitializeComponent();
  92. }
  93. private BitmapSource GetImage(string name)
  94. {
  95. return
  96. new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  97. }
  98. protected override void OnRender(DrawingContext drawingContext)
  99. {
  100. rotateTransform.Angle = ValveOpenOrientation == LineOrientation.Horizontal ? 0 : 90;
  101. bool IsOpen = DeviceData == null || (DeviceData.OpenSetPoint && !DeviceData.CloseSetPoint);
  102. imagePicture.Source = GetImage(IsOpen ? "ValveOpenHorizontal.png" : "ValveCloseHorizontal.png");
  103. if (DeviceData != null)
  104. {
  105. this.ToolTip =
  106. $"Valve Name:{DeviceData.DisplayName} \r\n Device ID:{DeviceData.DeviceSchematicId} \r\n SetPoint:{DeviceData.StringStatus} \r\n Status:{DeviceData.StringStatus}";
  107. }
  108. base.OnRender(drawingContext);
  109. }
  110. private void OpenValve(object sender, RoutedEventArgs e)
  111. {
  112. if (EnableServiceControl)
  113. {
  114. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITCylinderOperation.Open}" );
  115. return;
  116. }
  117. if (Command == null)
  118. return;
  119. Command.Execute(new object[] { DeviceData.DeviceName, AITCylinderOperation.Open });
  120. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  121. {
  122. Command.Execute(new object[] { DeviceData2.DeviceName, AITCylinderOperation.Open });
  123. }
  124. }
  125. private void CloseValve(object sender, RoutedEventArgs e)
  126. {
  127. if (EnableServiceControl)
  128. {
  129. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.{AITCylinderOperation.Close}" );
  130. return;
  131. }
  132. if (Command == null)
  133. return;
  134. Command.Execute(new object[] { DeviceData.DeviceName, AITCylinderOperation.Close });
  135. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  136. {
  137. Command.Execute(new object[] { DeviceData2.DeviceName, AITCylinderOperation.Close });
  138. }
  139. }
  140. }
  141. }