AITBoostPumpInputDialogBox.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using Aitex.Core.RT.Log;
  6. namespace Aitex.Core.UI.DeviceControl
  7. {
  8. public partial class AITBoostPumpInputDialogBox : Window
  9. {
  10. public AITBoostPumpInputDialogBox()
  11. {
  12. InitializeComponent();
  13. DataContext = this;
  14. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  15. }
  16. public void FocasAll()
  17. {
  18. inputBox.Text = Math.Round(SetPoint, 2).ToString();
  19. inputBox.Focus();
  20. inputBox.SelectAll();
  21. }
  22. /// <summary>
  23. /// Vilidate input range
  24. /// </summary>
  25. /// <param name="sender"></param>
  26. /// <param name="e"></param>
  27. private void InputTextBox_TextChanged(object sender, TextChangedEventArgs e)
  28. {
  29. double input;
  30. if (!double.TryParse(inputBox.Text, out input))
  31. btnSet.IsEnabled = false;
  32. else if (input < 0 || input > MaxValue)
  33. btnSet.IsEnabled = false;
  34. else
  35. btnSet.IsEnabled = true;
  36. inputBox.Foreground = btnSet.IsEnabled ?
  37. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  38. }
  39. public static readonly DependencyProperty DeviceNameProperty = DependencyProperty.Register(
  40. "DeviceName", typeof(string), typeof(AITBoostPumpInputDialogBox),
  41. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  42. public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(
  43. "DeviceId", typeof(string), typeof(AITBoostPumpInputDialogBox),
  44. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  45. public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register(
  46. "MaxValue", typeof(double), typeof(AITBoostPumpInputDialogBox),
  47. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  48. public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register(
  49. "Frequency", typeof(double), typeof(AITBoostPumpInputDialogBox),
  50. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  51. public static readonly DependencyProperty RealValueProperty = DependencyProperty.Register(
  52. "RealValue", typeof(string), typeof(AITBoostPumpInputDialogBox),
  53. new FrameworkPropertyMetadata("0.0", FrameworkPropertyMetadataOptions.AffectsRender));
  54. public static readonly DependencyProperty UnitProperty = DependencyProperty.Register(
  55. "Unit", typeof(string), typeof(AITBoostPumpInputDialogBox),
  56. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  57. public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
  58. "SetPoint", typeof(double), typeof(AITBoostPumpInputDialogBox),
  59. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  60. /// <summary>
  61. /// 是否百分比显示
  62. /// </summary>
  63. public bool IsPercent
  64. {
  65. get;
  66. set;
  67. }
  68. public string DeviceName
  69. {
  70. get
  71. {
  72. return (string)this.GetValue(DeviceNameProperty);
  73. }
  74. set
  75. {
  76. if (!string.IsNullOrEmpty(value) && !value.StartsWith("_"))
  77. value = "_" + value;
  78. this.SetValue(DeviceNameProperty, value);
  79. }
  80. }
  81. public string DeviceId
  82. {
  83. get
  84. {
  85. return (string)this.GetValue(DeviceIdProperty);
  86. }
  87. set
  88. {
  89. this.SetValue(DeviceIdProperty, value);
  90. }
  91. }
  92. public double MaxValue
  93. {
  94. get
  95. {
  96. return (double)this.GetValue(MaxValueProperty);
  97. }
  98. set
  99. {
  100. this.SetValue(MaxValueProperty, value);
  101. // validationRule.MaxInput = value;
  102. }
  103. }
  104. public double Frequency
  105. {
  106. get
  107. {
  108. return (double)this.GetValue(FrequencyProperty);
  109. }
  110. set
  111. {
  112. this.SetValue(FrequencyProperty, value);
  113. }
  114. }
  115. public string RealValue
  116. {
  117. get
  118. {
  119. return (string)this.GetValue(RealValueProperty);
  120. }
  121. set
  122. {
  123. this.SetValue(RealValueProperty, value);
  124. }
  125. }
  126. public string Unit
  127. {
  128. get
  129. {
  130. return (string)this.GetValue(UnitProperty);
  131. }
  132. set
  133. {
  134. this.SetValue(UnitProperty, value);
  135. }
  136. }
  137. public double SetPoint
  138. {
  139. get
  140. {
  141. return (double)this.GetValue(SetPointProperty);
  142. }
  143. set
  144. {
  145. this.SetValue(SetPointProperty, value);
  146. }
  147. }
  148. public Action<double> SetPressureCommandDelegate;
  149. private void ButtonSet_Click(object sender, RoutedEventArgs e)
  150. {
  151. try
  152. {
  153. SetPressureCommandDelegate(Convert.ToDouble(inputBox.Text));
  154. Close();
  155. }
  156. catch (Exception ex)
  157. {
  158. LOG.Error(ex.Message);
  159. }
  160. }
  161. private void OnEnterKeyIsHit(object sender, KeyEventArgs e)
  162. {
  163. try
  164. {
  165. if (!btnSet.IsEnabled)
  166. return;
  167. if (e.Key == Key.Return)
  168. {
  169. ButtonSet_Click(null, null);
  170. }
  171. }
  172. catch (Exception ex)
  173. {
  174. LOG.Error(ex.Message);
  175. }
  176. }
  177. private void ButtonCancel_Click(object sender, RoutedEventArgs e)
  178. {
  179. Close();
  180. }
  181. }
  182. }