|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using BPA.Helper;
- using FryPot_DosingSystem.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
-
- namespace FryPot_DosingSystem.View
- {
- /// <summary>
- /// NewRecipeView.xaml 的交互逻辑
- /// </summary>
- public partial class NewRecipeView : Window
- {
- int maxMaterialWeight = 250;
- public NewRecipeView()
- {
- InitializeComponent();
- this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
- ActionManage.GetInstance.CancelRegister("CloseNewRecipeView");
- ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseNewRecipeView");
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
-
- private void ComboBox_KeyUp(object sender, KeyEventArgs e)
- {
- var res = sender as ComboBox;
- Json<MaterialNames>.Read();
-
- if (res.Text != null && res.Text != String.Empty)
- {
- var datas = Json<MaterialNames>.Data.Names.Where(s => s.Contains(res.Text.Trim()));
- // var datas = Json<MaterialNames>.Data.Names.ToList().FindAll(s => s.Contains(res.Text.Trim()));
- if (datas.Count() > 0)
- {
- res.ItemsSource = datas;
- res.IsDropDownOpen = true;
- }
- else
- {
- res.IsDropDownOpen = false;
- }
- }
- }
-
- private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
- {
- var res = sender as ComboBox;
- if (res.Text != null && res.Text != String.Empty)
- {
- if (!MaterialNames.GetInstance.Names.Contains(res.Text.Trim()))//判断是否存在原料
- {
- MaterialNames.GetInstance.Names.Add(res.Text.Trim());
- Json<MaterialNames>.Data = MaterialNames.GetInstance;
- Json<MaterialNames>.Save();
- }
-
- }
- }
-
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (sender is TextBox txt)
- {
- if (txt.Text != null)
- {
- if (new Regex("^[1-8]$").IsMatch(txt.Text))//全匹配
- {
-
- }
- else
- {
- txt.Text = string.Empty;
- }
- }
-
- }
- }
-
- /// <summary>
- /// 偏差值验证
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox_LostFocus(object sender, RoutedEventArgs e)
- {
- //if (sender is TextBox)
- //{
- // try
- // {
- // TextBox text = sender as TextBox;
- // if (text.Text != null)
- // {
- // double offset = float.Parse((text.Text));
- // if (offset < 0)
- // {
- // MessageBox.Show("偏差值无效输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // }
- // }
- // }
- // catch (Exception)
- // {
-
- // MessageBox.Show("偏差值非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // }
- //}
-
-
- }
- /// <summary>
- /// 料桶重量验证
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox_LostFocus_1(object sender, RoutedEventArgs e)
- {
- //if (sender is TextBox)
- //{
- // try
- // {
- // TextBox text = sender as TextBox;
- // if (text != null)
- // {
- // double weight = Convert.ToDouble(text.Text);
- // if (weight < 0)
- // {
- // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // }
- // else if (weight > maxMaterialWeight)
- // {
- // MessageBox.Show("原料重量超出上限", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // }
- // else
- // {
- // text.Text = Math.Ceiling(weight).ToString();
- // }
-
- // }
- // }
- // catch (Exception)
- // {
-
- // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // }
- //}
-
- }
-
- private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
- {
- //if (sender is TextBox txtbox)
- //{
- // if (txtbox != null)
- // {
- // if (Regex.IsMatch(txtbox.Text, @"^\+?[0-9][0-9]*$"))//非零正整数
- // {
- // txtbox.Text = txtbox.Text.Trim();
-
- // }
- // else
- // {
- // // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- // txtbox.Text = string.Empty;
- // }
- // }
-
- //}
- if (sender is TextBox txtbox)
- {
- if (Regex.IsMatch(txtbox.Text, @"^[0-9]+(.[0-9]{0,1})?$"))//验证整数或1位小数
- {
- txtbox.Text = txtbox.Text.Trim();
-
- }
- else
- {
- // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- txtbox.Text = string.Empty;
- }
-
- }
- }
-
- private void TextBox_TextChanged_2(object sender, TextChangedEventArgs e)
- {
- if (sender is TextBox txtbox)
- {
- if (txtbox.Text != null)
- {
- if (Regex.IsMatch(txtbox.Text, @"^[0-9]+(.[1-9]{0,1})?$"))//验证整数或1位小数
- {
- txtbox.Text = txtbox.Text.Trim();
-
- }
- else
- {
- // MessageBox.Show("原料重量非法输入", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- txtbox.Text = string.Empty;
- }
- }
-
- }
- }
- }
- }
|