using 智能仓储WCS管理系统.ViewModel;
using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Runtime.CompilerServices;
using System.Text;
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;
using Window = System.Windows.Window;
namespace 智能仓储WCS管理系统
{
///
/// 提示框
///
public partial class TipInputView : HandyControl.Controls.Window
{
public TipInputView()
{
InitializeComponent();
}
private void closeClick(object sender, RoutedEventArgs e)
{
this.Close();
}
///
/// 显示输入提示框并尝试转为指定类型
///
/// 目标类型
/// 内容
/// 验证委托
/// 是否显示关闭按钮
/// 窗体所有者
/// 输入的内容(关闭为null)
public static T? Show(string content, Func verify = null, bool isVisCloseBut = true, Window owner = null) where T : struct
{
return Show(content, string.Empty, "请输入值", verify, isVisCloseBut, owner);
}
///
/// 显示输入提示框并尝试转为指定类型
///
/// 目标类型
/// 内容
/// 标题
/// 内部内容
/// 验证委托
/// 是否显示关闭按钮
/// 窗体所有者
/// 输入的内容(关闭为null)
public static T? Show(string content, string title, string contentHint = "请输入值", Func verify = null, bool isVisCloseBut = true, Window owner = null) where T : struct
{
TipInputView? tipView;
T? rval = null;
Application.Current.Dispatcher.Invoke(new Action(() =>
{
tipView = new TipInputView();
tipView.tb1.KeyDown += (s, e) =>
{
if (e.Key == Key.Enter)
{
e.Handled = true;
tipView.qr.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
};
tipView.qr.Click += (sender, e) =>
{
if (string.IsNullOrWhiteSpace(tipView.tb1.Text))
{
tipView.TsTxtx("请填写文本。");
return;
}
T val;
try
{
val = (T)Convert.ChangeType(tipView.tb1.Text, typeof(T));
}
catch (Exception)
{
tipView.TsTxtx($"无法将值{tipView.tb1.Text}换为{typeof(T).Name}。");
return;
}
var ts = verify?.Invoke(val);
if (!string.IsNullOrEmpty(ts))
{
tipView.TsTxtx(ts);
return;
}
rval = val;
tipView.Close();
};
tipView.DataContext = new { Title = title, Content = content, ContentHint = contentHint, IsClose = isVisCloseBut };
tipView.Owner = owner == null ? System.Windows.Application.Current.MainWindow : owner;
tipView.tb1.Focus();
tipView.ShowDialog();
tipView = null;
}));
return rval;
}
///
/// 显示输入提示框
///
/// 内容
/// 验证委托
/// 是否显示关闭按钮
/// 窗体所有者
/// 输入的文本(关闭为null)
public static string Show(string content, Func verify = null, bool isVisCloseBut = true, Window owner = null)
{
return Show(content, string.Empty, "请输入值", verify, isVisCloseBut, owner);
}
///
/// 显示输入提示框
///
/// 内容
/// 标题
/// 内部内容
/// 验证委托
/// 是否显示关闭按钮
/// 窗体所有者
/// 输入的文本(关闭为null)
public static string Show(string content, string title, string contentHint = "请输入值", Func verify = null, bool isVisCloseBut = true, Window owner = null)
{
TipInputView? tipView;
string? rval = null;
Application.Current.Dispatcher.Invoke(new Action(() =>
{
tipView = new TipInputView();
tipView.tb1.KeyDown += (s, e) =>
{
if (e.Key == Key.Enter)
{
e.Handled = true;
tipView.qr.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
};
tipView.qr.Click += (sender, e) =>
{
if (string.IsNullOrWhiteSpace(tipView.tb1.Text))
{
tipView.TsTxtx("请填写文本。");
return;
}
var ts = verify?.Invoke(tipView.tb1.Text);
if (!string.IsNullOrEmpty(ts))
{
tipView.TsTxtx(ts);
return;
}
rval = tipView.tb1.Text;
tipView.Close();
};
tipView.DataContext = new { Title = title, Content = content, ContentHint = contentHint, IsClose = isVisCloseBut };
tipView.Owner = owner == null ? System.Windows.Application.Current.MainWindow : owner;
tipView.tb1.Focus();
tipView.ShowDialog();
tipView = null;
}));
return rval!;
}
private void TsTxtx(string text)
{
transit.Visibility = Visibility.Hidden;
textBlock.Text = text;
transit.Visibility = Visibility.Visible;
}
private void previewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
}
}