AITChillerControl.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.DataCenter;
  17. using MECF.Framework.Common.OperationCenter;
  18. namespace Aitex.Core.UI.DeviceControl
  19. {
  20. /// <summary>
  21. /// AITChillerControl.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class AITChillerControl : UserControl
  24. {
  25. public AITChillerControl()
  26. {
  27. InitializeComponent();
  28. }
  29. // define dependency properties
  30. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  31. "Command", typeof(ICommand), typeof(AITChillerControl),
  32. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  34. "DeviceData", typeof(AITChillerData), typeof(AITChillerControl),
  35. new FrameworkPropertyMetadata(new AITChillerData(), FrameworkPropertyMetadataOptions.AffectsRender));
  36. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  37. "BackColor", typeof(Brush), typeof(AITChillerControl),
  38. new FrameworkPropertyMetadata(Brushes.DarkMagenta, FrameworkPropertyMetadataOptions.AffectsRender));
  39. public static readonly DependencyProperty IsAutoModeProperty = DependencyProperty.Register(
  40. "IsAutoMode", typeof(bool), typeof(AITChillerControl),
  41. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  42. /// <summary>
  43. /// 输入值是否百分比,默认否
  44. /// </summary>
  45. public bool IsPercent { get; set; }
  46. public ICommand Command
  47. {
  48. get
  49. {
  50. return (ICommand)this.GetValue(CommandProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(CommandProperty, value);
  55. }
  56. }
  57. /// <summary>
  58. /// set, get current progress value AnalogDeviceData
  59. /// </summary>
  60. public AITChillerData DeviceData
  61. {
  62. get
  63. {
  64. return (AITChillerData)this.GetValue(DeviceDataProperty);
  65. }
  66. set
  67. {
  68. this.SetValue(DeviceDataProperty, value);
  69. }
  70. }
  71. public Brush BackColor
  72. {
  73. get
  74. {
  75. return (Brush)this.GetValue(BackColorProperty);
  76. }
  77. set
  78. {
  79. this.SetValue(BackColorProperty, value);
  80. }
  81. }
  82. public bool IsAutoMode
  83. {
  84. get
  85. {
  86. return (bool)this.GetValue(IsAutoModeProperty);
  87. }
  88. set
  89. {
  90. this.SetValue(IsAutoModeProperty, value);
  91. }
  92. }
  93. protected override void OnRender(DrawingContext drawingContext)
  94. {
  95. base.OnRender(drawingContext);
  96. //draw background color
  97. if (DeviceData != null)
  98. {
  99. rectBkground.Fill = DeviceData.IsPowerOn ? Brushes.DarkMagenta : Brushes.Gray;
  100. //draw red board if mfc meets a warning
  101. rectBkground.Stroke = DeviceData.IsWarning ? Brushes.Red : new SolidColorBrush(System.Windows.Media.Color.FromRgb(0X37, 0X37, 0X37));
  102. labelValue.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  103. rectBkground.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  104. if (dialogBox != null)
  105. {
  106. dialogBox.RealValue = DeviceData.FeedBack.ToString("F1");
  107. dialogBox.IsHeaterOn = DeviceData.IsPowerOn;
  108. dialogBox.SetPoint = DeviceData.SetPoint;
  109. }
  110. }
  111. }
  112. private void ExecutePowerOnOff(bool value)
  113. {
  114. if (Command == null)
  115. {
  116. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.SetPowerOnOff", value.ToString());
  117. }
  118. else
  119. {
  120. Command.Execute(new object[] { DeviceData.DeviceName, AITHeaterOperation.SetPowerOnOff.ToString(), value.ToString() });
  121. }
  122. }
  123. private void ExecuteSetHeaterValue(double power)
  124. {
  125. if (Command == null)
  126. {
  127. InvokeClient.Instance.Service.DoOperation($"{DeviceData.Module}.{DeviceData.DeviceName}.Ramp",
  128. power.ToString(), ((double)QueryDataClient.Instance.Service.GetConfig($"{DeviceData.Module}.{DeviceData.DeviceName}.ChillerTemperatureOffset")).ToString());
  129. }
  130. else
  131. {
  132. Command.Execute(new object[]
  133. {DeviceData.DeviceName, AITHeaterOperation.Ramp.ToString(), power.ToString()});
  134. }
  135. }
  136. private AITHeaterInputDialogBox dialogBox;
  137. public Window AnalogOwner { get; set; }
  138. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  139. {
  140. if (IsAutoMode) return;
  141. if (DeviceData == null)
  142. return;
  143. dialogBox = new AITHeaterInputDialogBox
  144. {
  145. SetHeaterValueCommandDelegate = ExecuteSetHeaterValue,
  146. SetHeaterPowerOnOffCommandDelegate = ExecutePowerOnOff,
  147. DeviceName = DeviceData.DisplayName,
  148. DeviceId = DeviceData.DeviceSchematicId,
  149. DefaultValue = DeviceData.DefaultValue,
  150. RealValue = DeviceData.FeedBack.ToString("F1"),
  151. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  152. MaxValue = DeviceData.ScaleMax,
  153. MinValue = DeviceData.ScaleMin,
  154. Unit = DeviceData.Unit,
  155. IsHeaterOn = DeviceData.IsPowerOn,
  156. HeaterOffName = "Device Off",
  157. HeaterOnName = "Device On",
  158. };
  159. if (AnalogOwner != null)
  160. dialogBox.Owner = AnalogOwner;
  161. dialogBox.Topmost = true;
  162. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  163. dialogBox.FocasAll();
  164. dialogBox.ShowDialog();
  165. dialogBox = null;
  166. }
  167. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  168. {
  169. if (DeviceData != null)
  170. {
  171. string tooltipValue =
  172. string.Format("{0}:{1}\r\n\r\nID:{2}\r\nScaleMax:{3} {5}\r\nScaleMin:{4} {5}\r\nSetPoint:{6} {5} \r\nFeedback:{7} {5}\r\nHeaterPower:{8}",
  173. DeviceData.Type,
  174. DeviceData.DisplayName,
  175. DeviceData.DeviceSchematicId,
  176. DeviceData.ScaleMax,
  177. DeviceData.ScaleMin,
  178. DeviceData.Unit,
  179. DeviceData.SetPoint.ToString("F1"),
  180. DeviceData.FeedBack.ToString("F1"),
  181. DeviceData.IsPowerOn ? "On" : "Off");
  182. ToolTip = tooltipValue;
  183. }
  184. }
  185. }
  186. }