AITChillerControl.xaml.cs 7.5 KB

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