GasSplitterControl.xaml.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.ControlDataContext;
  16. using MECF.Framework.Common.OperationCenter;
  17. namespace Aitex.Core.UI.Control
  18. {
  19. /// <summary>
  20. /// GasSplitterControl.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class GasSplitterControl : UserControl
  23. {
  24. public GasSplitterControl()
  25. {
  26. InitializeComponent();
  27. }
  28. // define dependency properties
  29. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  30. "Command", typeof(ICommand), typeof(GasSplitterControl),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  33. "DeviceData", typeof(AITGasSplitterData), typeof(GasSplitterControl),
  34. new FrameworkPropertyMetadata(new AITGasSplitterData(), FrameworkPropertyMetadataOptions.AffectsRender));
  35. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  36. "BackColor", typeof(Brush), typeof(GasSplitterControl),
  37. new FrameworkPropertyMetadata(Brushes.Green, FrameworkPropertyMetadataOptions.AffectsRender));
  38. /// <summary>
  39. /// 输入值是否百分比,默认否
  40. /// </summary>
  41. public bool IsPercent { get; set; }
  42. public ICommand Command
  43. {
  44. get
  45. {
  46. return (ICommand)this.GetValue(CommandProperty);
  47. }
  48. set
  49. {
  50. this.SetValue(CommandProperty, value);
  51. }
  52. }
  53. /// <summary>
  54. /// set, get current progress value AnalogDeviceData
  55. /// </summary>
  56. public AITGasSplitterData DeviceData
  57. {
  58. get
  59. {
  60. return (AITGasSplitterData)this.GetValue(DeviceDataProperty);
  61. }
  62. set
  63. {
  64. this.SetValue(DeviceDataProperty, value);
  65. }
  66. }
  67. public Brush BackColor
  68. {
  69. get
  70. {
  71. return (Brush)this.GetValue(BackColorProperty);
  72. }
  73. set
  74. {
  75. this.SetValue(BackColorProperty, value);
  76. }
  77. }
  78. protected override void OnRender(DrawingContext drawingContext)
  79. {
  80. base.OnRender(drawingContext);
  81. //draw background color
  82. rectBkground.Fill = BackColor;
  83. if (DeviceData != null)
  84. {
  85. //draw red board if mfc meets a warning
  86. rectBkground.Stroke = DeviceData.IsWarning ? Brushes.Red : Brushes.Gray;
  87. labelValue.Foreground = DeviceData.IsWarning ? Brushes.Pink : Brushes.LightYellow;
  88. rectBkground.StrokeThickness = DeviceData.IsWarning ? 2 : 1;
  89. if (dialogBox != null)
  90. {
  91. if (IsPercent)
  92. dialogBox.RealValue = (DeviceData.FeedBack * 100).ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1") + "%";
  93. else
  94. dialogBox.RealValue = DeviceData.FeedBack.ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1");
  95. }
  96. }
  97. }
  98. private InputDialogBox dialogBox;
  99. public Window AnalogOwner { get; set; }
  100. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  101. {
  102. if (DeviceData == null)
  103. return;
  104. dialogBox = new InputDialogBox
  105. {
  106. CommandDelegate = Execute,
  107. DeviceName = string.Format("{0}: {1}", DeviceData.Type, DeviceData.DisplayName),
  108. DeviceId = DeviceData.DeviceSchematicId,
  109. DefaultValue = DeviceData.DefaultValue,
  110. RealValue = DeviceData.FeedBack.ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1"),
  111. SetPoint = Math.Round(DeviceData.SetPoint, 1),
  112. MaxValue = DeviceData.Scale,
  113. Unit = DeviceData.Unit,
  114. };
  115. dialogBox.IsPercent = IsPercent;
  116. if (IsPercent)
  117. dialogBox.SetPoint = Math.Round(DeviceData.SetPoint * 100.0, 1);
  118. if (AnalogOwner != null)
  119. dialogBox.Owner = AnalogOwner;
  120. dialogBox.Topmost = true;
  121. dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  122. dialogBox.FocasAll();
  123. dialogBox.ShowDialog();
  124. dialogBox = null;
  125. }
  126. private void Execute(double value)
  127. {
  128. if (Command == null)
  129. {
  130. InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITMfcOperation.Ramp}", value, 0);
  131. return;
  132. }
  133. Command.Execute(new object[] { DeviceData.DeviceName, AITMfcOperation.Ramp, value });
  134. }
  135. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  136. {
  137. if (DeviceData != null)
  138. {
  139. string tooltipValue =
  140. string.Format("{0}:{1}\r\n\r\nID:{2}\r\nScale:{3} {4}\r\nSetPoint:{5} {4}\r\nFeedback:{6} {4}\r\nTolerance:{7}\r\nStatus:{8}",
  141. DeviceData.Type,
  142. DeviceData.DisplayName,
  143. DeviceData.DeviceSchematicId,
  144. DeviceData.Scale,
  145. DeviceData.Unit,
  146. IsPercent ? (DeviceData.SetPoint * 100).ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1") + "%" : DeviceData.SetPoint.ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1"),
  147. IsPercent ? (DeviceData.FeedBack * 100).ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1") + "%" : DeviceData.FeedBack.ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1"),
  148. DeviceData.Scale > 0 ? ((DeviceData.FeedBack - DeviceData.SetPoint) / DeviceData.Scale * 100).ToString(!string.IsNullOrEmpty(DeviceData.FormatString) ? DeviceData.FormatString : "F1") : "0",
  149. DeviceData.IsWarning ? "Tolerance Warning" : "Normal");
  150. ToolTip = tooltipValue;
  151. }
  152. }
  153. }
  154. }