VirtualKeyboard.xaml.cs
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
{
/// <summary>
/// VirtualKeyboard.xaml 的交互逻辑
/// </summary>
public partial class VirtualKeyboard : Window
{
public VirtualKeyboard()
{
InitializeComponent();
//绑定数据
txtClothNo.DataContext = cloth;
setClothNumber("927A-19-1234-3-12-AAA");
}
/// <summary>
/// 动态绑定布匹编号
/// </summary>
/// <param name="number"></param>
public void setClothNumber(string number)
{
cloth.clothNum = number;
}
private ClothNumber _cloth = new ClothNumber();
//封装属性
public ClothNumber cloth
{
get { return _cloth; }
set
{
_cloth = value;
}
}
/// <summary>
/// 按钮相关操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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));
}
}
/// <summary>
/// 数字和字母输入
/// </summary>
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));
}
}
/// <summary>
/// 确认
/// </summary>
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));
}
}
/// <summary>
/// 退格
/// </summary>
/// <param name="strTemp"></param>
/// <param name="idx"></param>
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));
}
}
}
}