using System; using System.Windows; using System.Windows.Controls; using OS.Spin.ViewModle.Models; using System.Text.RegularExpressions; using OS.Spin.Common; namespace OS.Spin.View.Views { /// /// VirtualKeyboard.xaml 的交互逻辑 /// public partial class VirtualKeyboard : Window { public VirtualKeyboard() { InitializeComponent(); //绑定数据 txtClothNo.DataContext = cloth; setClothNumber("927A-19-1234-3-12-AAA"); } /// /// 动态绑定布匹编号 /// /// public void setClothNumber(string number) { cloth.clothNum = number; } private ClothNumber _cloth = new ClothNumber(); //封装属性 public ClothNumber cloth { get { return _cloth; } set { _cloth = value; } } /// /// 按钮相关操作 /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { try { Button btnTemp = sender as Button; if (btnTemp.Content.ToString().Equals("清空")) this.txtClothNo.Clear(); else if (btnTemp.Content.ToString().Equals("退出")) this.Close(); else if (btnTemp.Content.ToString().Equals("退格")) BackUp(); else if (btnTemp.Content.ToString().Equals("确认")) Submit(); else NumIn(btnTemp.Content.ToString()); } catch (Exception ex) { LogisTrac.WriteLog(string.Format("Button_Click:{0}", ex.Message)); } } /// /// 数字和字母输入 /// private void NumIn(string content) { try { string strTemp = txtClothNo.Text; int idx = txtClothNo.SelectionStart; strTemp = strTemp.Insert(idx, content); txtClothNo.Text = strTemp; txtClothNo.SelectionStart = idx + 1; txtClothNo.Focus(); } catch (Exception ex) { LogisTrac.WriteLog(string.Format("NumIn:{0}", ex.Message)); } } /// /// 确认 /// private void Submit() { try { if (txtClothNo.Text.Length < 3 || txtClothNo.Text.Length > 21) { MessageBox.Show("布匹编号输入不合法必须为3-21位之间", "温馨提示", MessageBoxButton.OK); } else if (!Regex.IsMatch(txtClothNo.Text, "[0-9]{3}$")) { MessageBox.Show("布匹编号后三位必须为数字", "温馨提示", MessageBoxButton.OK); } else { OS.Spin.Commands.Controller.GetInstance().ChangeSnNo(txtClothNo.Text); this.Close(); } } catch (Exception ex) { LogisTrac.WriteLog(string.Format("Submit:{0}", ex.Message)); } } /// /// 退格 /// /// /// private void BackUp() { try { string strTemp = txtClothNo.Text; int idx = txtClothNo.SelectionStart; if (idx > 0) { txtClothNo.Text = strTemp.Substring(0, idx - 1) + strTemp.Substring(idx); txtClothNo.SelectionStart = idx - 1; } else { txtClothNo.SelectionStart = 0; } } catch (Exception ex) { LogisTrac.WriteLog(string.Format("BackUp:{0]", ex.Message)); } } } }