AITGasValve.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. namespace Aitex.Core.UI.DeviceControl
  17. {
  18. /// <summary>
  19. /// TexGasValve.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AITGasValve : UserControl
  22. {
  23. // define dependency properties
  24. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  25. "Command", typeof(ICommand), typeof(AITGasValve),
  26. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  27. public ICommand Command
  28. {
  29. get
  30. {
  31. return (ICommand)this.GetValue(CommandProperty);
  32. }
  33. set
  34. {
  35. this.SetValue(CommandProperty, value);
  36. }
  37. }
  38. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  39. "DeviceData", typeof(AITValveData), typeof(AITGasValve),
  40. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  41. public AITValveData DeviceData
  42. {
  43. get
  44. {
  45. return (AITValveData)this.GetValue(DeviceDataProperty);
  46. }
  47. set
  48. {
  49. this.SetValue(DeviceDataProperty, value);
  50. }
  51. }
  52. public static readonly DependencyProperty DeviceData2Property = DependencyProperty.Register(
  53. "DeviceData2", typeof(AITValveData), typeof(AITGasValve),
  54. new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
  55. public AITValveData DeviceData2
  56. {
  57. get
  58. {
  59. return (AITValveData)this.GetValue(DeviceData2Property);
  60. }
  61. set
  62. {
  63. this.SetValue(DeviceData2Property, value);
  64. }
  65. }
  66. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  67. "ValveOpenOrientation", typeof(LineOrientation), typeof(AITGasValve),
  68. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  69. public LineOrientation ValveOpenOrientation
  70. {
  71. get { return (LineOrientation)GetValue(ValveOpenOrientationProperty); }
  72. set { SetValue(ValveOpenOrientationProperty, value); }
  73. }
  74. public AITGasValve()
  75. {
  76. InitializeComponent();
  77. }
  78. private BitmapSource GetImage(string name)
  79. {
  80. return
  81. new BitmapImage(new Uri(string.Format("pack://application:,,,/Core;component/Resources/Valve/{0}", name)));
  82. }
  83. protected override void OnRender(DrawingContext drawingContext)
  84. {
  85. rotateTransform.Angle = ValveOpenOrientation == LineOrientation.Horizontal ? 0 : 90;
  86. bool IsOpen = DeviceData == null || DeviceData.IsOpen;
  87. IsOpen = IsOpen && (DeviceData2 == null || !DeviceData2.IsOpen);
  88. imagePicture.Source = GetImage(IsOpen ? "ValveOpenHorizontal.png" : "ValveCloseHorizontal.png");
  89. if (DeviceData != null)
  90. {
  91. this.ToolTip = string.Format(Application.Current.Resources["GlobalLableValveToolTip"].ToString(),
  92. DeviceData.DisplayName,
  93. DeviceData.DeviceSchematicId,
  94. DeviceData.DefaultValue,
  95. DeviceData.SetPoint,
  96. DeviceData.Feedback);
  97. }
  98. base.OnRender(drawingContext);
  99. }
  100. private void OpenValve(object sender, RoutedEventArgs e)
  101. {
  102. if (Command == null)
  103. return;
  104. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, true });
  105. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  106. {
  107. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, false });
  108. }
  109. }
  110. private void CloseValve(object sender, RoutedEventArgs e)
  111. {
  112. if (Command == null)
  113. return;
  114. Command.Execute(new object[] { DeviceData.DeviceName, AITValveOperation.GVTurnValve, false });
  115. if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
  116. {
  117. Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, true });
  118. }
  119. }
  120. }
  121. }