终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

206 lines
6.8 KiB

  1. using BPASmartClient.Helper;
  2. using FryPot_DosingSystem.Model;
  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.Shapes;
  17. namespace FryPot_DosingSystem.View
  18. {
  19. /// <summary>
  20. /// NewRecipeView.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class NewRecipeView : Window
  23. {
  24. int maxMaterialWeight = 250;
  25. public NewRecipeView()
  26. {
  27. InitializeComponent();
  28. this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
  29. ActionManage.GetInstance.CancelRegister("CloseNewRecipeView");
  30. ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseNewRecipeView");
  31. }
  32. private void Button_Click(object sender, RoutedEventArgs e)
  33. {
  34. this.Close();
  35. }
  36. private void ComboBox_KeyUp(object sender, KeyEventArgs e)
  37. {
  38. var res = sender as ComboBox;
  39. Json<MaterialNames>.Read();
  40. if (res.Text != null && res.Text != String.Empty)
  41. {
  42. var datas = Json<MaterialNames>.Data.Names.Where(s => s.Contains(res.Text.Trim()));
  43. // var datas = Json<MaterialNames>.Data.Names.ToList().FindAll(s => s.Contains(res.Text.Trim()));
  44. if (datas.Count() > 0)
  45. {
  46. res.ItemsSource = datas;
  47. res.IsDropDownOpen = true;
  48. }
  49. else
  50. {
  51. res.IsDropDownOpen = false;
  52. }
  53. }
  54. }
  55. private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
  56. {
  57. var res = sender as ComboBox;
  58. if (res.Text != null && res.Text != String.Empty)
  59. {
  60. if (!MaterialNames.GetInstance.Names.Contains(res.Text.Trim()))//判断是否存在原料
  61. {
  62. MaterialNames.GetInstance.Names.Add(res.Text.Trim());
  63. Json<MaterialNames>.Data = MaterialNames.GetInstance;
  64. Json<MaterialNames>.Save();
  65. }
  66. }
  67. }
  68. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  69. {
  70. if (sender is TextBox txt)
  71. {
  72. if (txt.Text != null)
  73. {
  74. if (new Regex("^[1-8]$").IsMatch(txt.Text))//全匹配
  75. {
  76. }
  77. else
  78. {
  79. txt.Text = string.Empty;
  80. }
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 偏差值验证
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. private void TextBox_LostFocus(object sender, RoutedEventArgs e)
  90. {
  91. //if (sender is TextBox)
  92. //{
  93. // try
  94. // {
  95. // TextBox text = sender as TextBox;
  96. // if (text.Text != null)
  97. // {
  98. // double offset = float.Parse((text.Text));
  99. // if (offset < 0)
  100. // {
  101. // MessageBox.Show("偏差值无效输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  102. // }
  103. // }
  104. // }
  105. // catch (Exception)
  106. // {
  107. // MessageBox.Show("偏差值非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  108. // }
  109. //}
  110. }
  111. /// <summary>
  112. /// 料桶重量验证
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void TextBox_LostFocus_1(object sender, RoutedEventArgs e)
  117. {
  118. //if (sender is TextBox)
  119. //{
  120. // try
  121. // {
  122. // TextBox text = sender as TextBox;
  123. // if (text != null)
  124. // {
  125. // double weight = Convert.ToDouble(text.Text);
  126. // if (weight < 0)
  127. // {
  128. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  129. // }
  130. // else if (weight > maxMaterialWeight)
  131. // {
  132. // MessageBox.Show("原料重量超出上限", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  133. // }
  134. // else
  135. // {
  136. // text.Text = Math.Ceiling(weight).ToString();
  137. // }
  138. // }
  139. // }
  140. // catch (Exception)
  141. // {
  142. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  143. // }
  144. //}
  145. }
  146. private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
  147. {
  148. if (sender is TextBox txtbox)
  149. {
  150. if (txtbox != null)
  151. {
  152. if (Regex.IsMatch(txtbox.Text, @"^\+?[0-9][0-9]*$"))//非零正整数
  153. {
  154. txtbox.Text = txtbox.Text.Trim();
  155. }
  156. else
  157. {
  158. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  159. txtbox.Text = string.Empty;
  160. }
  161. }
  162. }
  163. }
  164. private void TextBox_TextChanged_2(object sender, TextChangedEventArgs e)
  165. {
  166. if (sender is TextBox txtbox)
  167. {
  168. if (txtbox.Text != null)
  169. {
  170. if (Regex.IsMatch(txtbox.Text, @"^[0-9]+(.[1-9]{0,1})?$"))//验证整数或1位小数
  171. {
  172. txtbox.Text = txtbox.Text.Trim();
  173. }
  174. else
  175. {
  176. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  177. txtbox.Text = string.Empty;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }