AITGasValve.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 AITGasValve : UserControl
  23. {
  24. // define dependency properties
  25. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  26. "Command", typeof(ICommand), typeof(AITGasValve),
  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(AITValveData), typeof(AITGasValve),
  41. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  42. public AITValveData DeviceData
  43. {
  44. get
  45. {
  46. return (AITValveData)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(AITGasValve),
  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 IsAutoModeProperty = DependencyProperty.Register(
  68. "IsAutoMode", typeof(bool), typeof(AITGasValve),
  69. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  70. public bool IsAutoMode
  71. {
  72. get
  73. {
  74. return (bool)this.GetValue(IsAutoModeProperty);
  75. }
  76. set
  77. {
  78. this.SetValue(IsAutoModeProperty, value);
  79. }
  80. }
  81. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  82. "DeviceData2", typeof(AITValveData), typeof(AITGasValve),
  83. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  84. public AITValveData DeviceData2
  85. {
  86. get
  87. {
  88. return (AITValveData)this.GetValue(DeviceData2Property);
  89. }
  90. set
  91. {
  92. this.SetValue(DeviceData2Property, value);
  93. }
  94. }
  95. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  96. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasValve),
  97. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  98. public LineOrientation ValveOpenOrientation
  99. {
  100. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  101. set { SetValue(ValveOpenOrientationProperty, value); }
  102. }
  103. public AITGasValve()
  104. {
  105. InitializeComponent();
  106. }
  107. private BitmapSource GetImage(string name)
  108. {
  109. return
  110. new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  111. }
  112. protected override void OnRender(DrawingContext drawingContext)
  113. {
  114. rotateTransform.Angle = ValveOpenOrientation == LineOrientation.Horizontal ? 0 : 90;
  115. bool IsOpen = DeviceData == null || DeviceData.IsOpen;
  116. IsOpen = IsOpen && (DeviceData2 == null || !DeviceData2.IsOpen);
  117. imagePicture.Source = GetImage(IsOpen ? "ValveOpenHorizontal.png" : "ValveCloseHorizontal.png");
  118. if (DeviceData != null)
  119. {
  120. this.ToolTip =
  121. $"Valve Name:{DeviceData.DisplayName} \r\n Device ID:{DeviceData.DeviceSchematicId} \r\n SetPoint:{DeviceData.SetPoint} \r\n Status:{DeviceData.Feedback}";
  122. }
  123. base.OnRender(drawingContext);
  124. }
  125. private void OpenValve(object sender, RoutedEventArgs e)
  126. {
  127. if (IsAutoMode) return;
  128. if (EnableServiceControl)
  129. {
  130. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
  131. return;
  132. }
  133. if (Command == null)
  134. return;
  135. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, true });
  136. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  137. {
  138. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, false });
  139. }
  140. }
  141. private void CloseValve(object sender, RoutedEventArgs e)
  142. {
  143. if (IsAutoMode) return;
  144. if (EnableServiceControl)
  145. {
  146. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
  147. return;
  148. }
  149. if (Command == null)
  150. return;
  151. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, false });
  152. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  153. {
  154. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, true });
  155. }
  156. }
  157. }
  158. }