终端一体化运控平台
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.
 
 
 

196 lines
6.4 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 (new Regex("^[1-8]$").IsMatch(txt.Text))//全匹配
  73. {
  74. }
  75. else
  76. {
  77. txt.Text = string.Empty;
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// 偏差值验证
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void TextBox_LostFocus(object sender, RoutedEventArgs e)
  87. {
  88. //if (sender is TextBox)
  89. //{
  90. // try
  91. // {
  92. // TextBox text = sender as TextBox;
  93. // if (text.Text != null)
  94. // {
  95. // double offset = float.Parse((text.Text));
  96. // if (offset < 0)
  97. // {
  98. // MessageBox.Show("偏差值无效输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  99. // }
  100. // }
  101. // }
  102. // catch (Exception)
  103. // {
  104. // MessageBox.Show("偏差值非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  105. // }
  106. //}
  107. }
  108. /// <summary>
  109. /// 料桶重量验证
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. private void TextBox_LostFocus_1(object sender, RoutedEventArgs e)
  114. {
  115. //if (sender is TextBox)
  116. //{
  117. // try
  118. // {
  119. // TextBox text = sender as TextBox;
  120. // if (text != null)
  121. // {
  122. // double weight = Convert.ToDouble(text.Text);
  123. // if (weight < 0)
  124. // {
  125. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  126. // }
  127. // else if (weight > maxMaterialWeight)
  128. // {
  129. // MessageBox.Show("原料重量超出上限", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  130. // }
  131. // else
  132. // {
  133. // text.Text = Math.Ceiling(weight).ToString();
  134. // }
  135. // }
  136. // }
  137. // catch (Exception)
  138. // {
  139. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  140. // }
  141. //}
  142. }
  143. private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
  144. {
  145. if (sender is TextBox txtbox)
  146. {
  147. if (Regex.IsMatch(txtbox.Text, @"^\+?[1-9][0-9]*$"))//非零正整数
  148. {
  149. txtbox.Text = txtbox.Text.Trim();
  150. }
  151. else
  152. {
  153. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  154. txtbox.Text = string.Empty;
  155. }
  156. }
  157. }
  158. private void TextBox_TextChanged_2(object sender, TextChangedEventArgs e)
  159. {
  160. if (sender is TextBox txtbox)
  161. {
  162. if (Regex.IsMatch(txtbox.Text, @"^[0-9]+(.[1-9]{0,1})?$"))//验证整数或1位小数
  163. {
  164. txtbox.Text = txtbox.Text.Trim();
  165. }
  166. else
  167. {
  168. // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  169. txtbox.Text = string.Empty;
  170. }
  171. }
  172. }
  173. }
  174. }