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
{
///
/// NewRecipeView.xaml 的交互逻辑
///
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.Read();
if (res.Text != null && res.Text != String.Empty)
{
var datas = Json.Data.Names.Where(s => s.Contains(res.Text.Trim()));
// var datas = Json.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.Data = MaterialNames.GetInstance;
Json.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;
}
}
}
}
///
/// 偏差值验证
///
///
///
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);
// }
//}
}
///
/// 料桶重量验证
///
///
///
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;
}
}
}
}
}
}