CrossDoseControl.xaml.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using MECF.Framework.Common.CommonData.Reservoir;
  2. using MECF.Framework.Common.OperationCenter;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using static System.Net.Mime.MediaTypeNames;
  19. namespace CyberX8_Themes.UserControls
  20. {
  21. /// <summary>
  22. /// CrossDoseControl.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class CrossDoseControl : UserControl
  25. {
  26. public CrossDoseControl()
  27. {
  28. InitializeComponent();
  29. }
  30. #region 属性
  31. public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
  32. "ModuleName", typeof(string), typeof(CrossDoseControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  33. /// <summary>
  34. /// ModuleName
  35. /// </summary>
  36. public string ModuleName
  37. {
  38. get
  39. {
  40. return (string)this.GetValue(ModuleNameProperty);
  41. }
  42. set
  43. {
  44. this.SetValue(ModuleNameProperty, value);
  45. }
  46. }
  47. public static readonly DependencyProperty ANTransferFlowProperty = DependencyProperty.Register(
  48. "ANTransferFlow", typeof(double), typeof(CrossDoseControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  49. /// <summary>
  50. /// ANTransferFlow
  51. /// </summary>
  52. public double ANTransferFlow
  53. {
  54. get
  55. {
  56. return (double)this.GetValue(ANTransferFlowProperty);
  57. }
  58. set
  59. {
  60. this.SetValue(ANTransferFlowProperty, value);
  61. }
  62. }
  63. public static readonly DependencyProperty RemainingFlowProperty = DependencyProperty.Register(
  64. "RemainingFlow", typeof(double), typeof(CrossDoseControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  65. /// <summary>
  66. /// RemainingFlow
  67. /// </summary>
  68. public double RemainingFlow
  69. {
  70. get
  71. {
  72. return (double)this.GetValue(RemainingFlowProperty);
  73. }
  74. set
  75. {
  76. this.SetValue(RemainingFlowProperty, value);
  77. }
  78. }
  79. public static readonly DependencyProperty ReservoirDataProperty = DependencyProperty.Register(
  80. "ReservoirData", typeof(CompactMembranReservoirData), typeof(CrossDoseControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  81. /// <summary>
  82. /// ReservoirData
  83. /// </summary>
  84. public CompactMembranReservoirData ReservoirData
  85. {
  86. get
  87. {
  88. return (CompactMembranReservoirData)this.GetValue(ReservoirDataProperty);
  89. }
  90. set
  91. {
  92. this.SetValue(ReservoirDataProperty, value);
  93. }
  94. }
  95. public static readonly DependencyProperty PumpFactorProperty = DependencyProperty.Register(
  96. "PumpFactor", typeof(double), typeof(CrossDoseControl), new FrameworkPropertyMetadata(0.000, FrameworkPropertyMetadataOptions.AffectsRender));
  97. /// <summary>
  98. /// PumpFactor
  99. /// </summary>
  100. public double PumpFactor
  101. {
  102. get
  103. {
  104. return (double)this.GetValue(PumpFactorProperty);
  105. }
  106. set
  107. {
  108. this.SetValue(PumpFactorProperty, value);
  109. }
  110. }
  111. public static readonly DependencyProperty IsCalibrateEnableProperty = DependencyProperty.Register(
  112. "IsCalibrateEnable", typeof(bool), typeof(CrossDoseControl), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  113. /// <summary>
  114. /// IsCalibrateEnable
  115. /// </summary>
  116. public bool IsCalibrateEnable
  117. {
  118. get
  119. {
  120. return (bool)this.GetValue(IsCalibrateEnableProperty);
  121. }
  122. set
  123. {
  124. this.SetValue(IsCalibrateEnableProperty, value);
  125. }
  126. }
  127. public static readonly DependencyProperty TargetDosingVolumeProperty = DependencyProperty.Register(
  128. "TargetDosingVolume", typeof(double), typeof(CrossDoseControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));
  129. /// <summary>
  130. /// TargetDosingVolume
  131. /// </summary>
  132. public double TargetDosingVolume
  133. {
  134. get
  135. {
  136. return (double)this.GetValue(TargetDosingVolumeProperty);
  137. }
  138. set
  139. {
  140. this.SetValue(TargetDosingVolumeProperty, value);
  141. }
  142. }
  143. public static readonly DependencyProperty IsAutoModeProperty = DependencyProperty.Register(
  144. "IsAutoMode", typeof(bool), typeof(CrossDoseControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  145. /// <summary>
  146. /// IsAutoMode
  147. /// </summary>
  148. public bool IsAutoMode
  149. {
  150. get
  151. {
  152. return (bool)this.GetValue(IsAutoModeProperty);
  153. }
  154. set
  155. {
  156. this.SetValue(IsAutoModeProperty, value);
  157. }
  158. }
  159. #endregion
  160. /// <summary>
  161. /// 手动Dosing开始
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void Start_Click(object sender, RoutedEventArgs e)
  166. {
  167. if (requestVolume.Text != "")
  168. {
  169. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.StartDosing", double.Parse(requestVolume.Text));
  170. }
  171. }
  172. /// <summary>
  173. /// 手动Dosing停止
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void Halt_Click(object sender, RoutedEventArgs e)
  178. {
  179. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.HaltDosing");
  180. }
  181. /// <summary>
  182. /// 计算Pump Factor
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void Calibrate_Click(object sender, RoutedEventArgs e)
  187. {
  188. if (!string.IsNullOrEmpty(counterVolume.Text) && !string.IsNullOrEmpty(requestVolume.Text))
  189. {
  190. double request = double.Parse(requestVolume.Text);
  191. if (request == 0) return;
  192. double pumpFactor = double.Parse(counterVolume.Text) / request;
  193. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SetPumpFactor", Math.Round(pumpFactor, 3));
  194. }
  195. }
  196. /// <summary>
  197. /// Reset电机
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void Reset_Click(object sender, RoutedEventArgs e)
  202. {
  203. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ResetCrossDose");
  204. }
  205. /// <summary>
  206. /// 输入限制
  207. /// </summary>
  208. /// <param name="key"></param>
  209. /// <param name="text"></param>
  210. /// <returns></returns>
  211. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  212. {
  213. e.Handled = !IsTextAllowed(e.Text, ((TextBox) sender).Text);
  214. }
  215. private bool IsTextAllowed(string key, string text)
  216. {
  217. Regex regex = new Regex(@"^[0-9\.]+$");
  218. return regex.IsMatch(key);
  219. }
  220. }
  221. }