UsrCodeExtractList.cs
8.1 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using Asa.FaceControl;
using BLL;
using DocumentFormat.OpenXml.EMMA;
using Model;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace SmartScan
{
public partial class UsrCodeExtractList : UserControl
{
private readonly bool changed;
private readonly string codeText;
private readonly string codeType;
public event EventHandler DelClick;
public event EventHandler AddClick;
public event KeyChangedHandler KeyChanged;
public delegate void KeyChangedHandler(object sender, string key);
public UsrCodeExtractList(string codeText, string codeType, int codeLength, Model.MaterialCodeMatch match)
{
InitializeComponent();
faceTextBox1.Tag = "not";
changed = true;
Language.SetLanguage(this);
this.codeText = codeText;
this.codeType = codeType;
CboKeyword.Items.AddRange(BLLCommon.macroKey.ToArray());
CboMatchingSplit.Items.AddRange(BLLCommon.CODE_SPLIT);
NudStart.Maximum = codeLength;
NudLength.Maximum = codeLength;
ChkMatchingSplit.Checked = match.MatchSplit;
CboMatchingSplit.Text = match.SplitText;
NudSplitPart.Value = match.SplitPart;
ChkMinLength.Checked = match.MatchMinLength;
NudMinLength.Value = match.MinLength;
ChkMaxLength.Checked = match.MatchMaxLength;
NudMaxLength.Value = match.MaxLength;
CboKeyword.Tag = "not";
CboKeyword.SelectedText = match.Keyword;
NudStart.Value = match.SubstringStart;
match.CodeType = codeType;
ChkMatchisnumber.Checked = match.MatchISNumber;
if (match.SubstringLength == -1)
{
ChkLengthEnd.Checked = true;
NudLength.Enabled = false;
}
else
NudLength.Value = match.SubstringLength;
changed = false;
ShowPreview();
}
public FacePanel GetPanel()
{
return facePanel1;
}
public Model.MaterialCodeMatch GetMatch()
{
Model.MaterialCodeMatch match = new()
{
MatchSplit = ChkMatchingSplit.Checked,
SplitText = CboMatchingSplit.Text,
SplitPart = Convert.ToInt32(NudSplitPart.Value),
MatchMinLength = ChkMinLength.Checked,
MinLength = Convert.ToInt32(NudMinLength.Value),
MatchMaxLength = ChkMaxLength.Checked,
MaxLength = Convert.ToInt32(NudMaxLength.Value),
Keyword = CboKeyword.SelectedText,
SubstringStart = Convert.ToInt32(NudStart.Value),
SubstringLength = ChkLengthEnd.Checked ? -1 : Convert.ToInt32(NudLength.Value),
MatchISNumber = ChkMatchisnumber.Checked
};
return match;
}
public string GetMatchKey()
{
return CboKeyword.SelectedText;
}
public void ShowPreview(string txt = "")
{
if (changed) return;
AsciiToCharReplacer asciiToChar = new AsciiToCharReplacer();
string text = asciiToChar.AsciiToString(codeText);
//if (ChkMatchingMiddle.Checked) {
// int textcount=1;
// int.TryParse(NudMiddleTextCount.Text, out textcount);
// var t = ChoMatchMiddleType.SelectedIndex - 1;
// int index = 0;
// int count = 0;
// while ((index = text.IndexOf(TxtMatchingMiddleText.Text, index)) != -1 && !string.IsNullOrEmpty(TxtMatchingMiddleText.Text))
// {
// count++;
// index += TxtMatchingMiddleText.Text.Length;
// }
// if (t == -1 && count > textcount)
// text = "";
// if (t == 0 && count != textcount)
// text = "";
// if (t == 1 && count < textcount)
// text = "";
// faceTextBox1.Text = text;
// if (string.IsNullOrEmpty(text))
// return;
//}
try
{
if (ChkMatchingSplit.Checked)
{
string str = Model.MaterialAsciiCode.GetAsciiCode(CboMatchingSplit.Text);
//string outup = codeText;
//AsciiToCharReplacer asciiToChar = new AsciiToCharReplacer();
//outup= asciiToChar.AsciiToString(outup);
string[] arr = text.Split(str.ToCharArray());
//string[] arr = codeText.Split(new string[] { str }, StringSplitOptions.RemoveEmptyEntries);
int index = Convert.ToInt32(NudSplitPart.Value) - 1;
if (index < arr.Length)
text = arr[index];
else
text = "";
}
if (ChkMinLength.Checked)
{
if (text.Length < NudMinLength.Value)
text = "";
}
if (ChkMaxLength.Checked)
{
if (text.Length > NudMaxLength.Value)
text = "";
}
if (text.Length > 0)
{
int startIndex = Convert.ToInt32(NudStart.Value);
int length = Convert.ToInt32(NudLength.Value);
if (ChkLengthEnd.Checked)
{
text = text.Substring(startIndex);
}
else
{
if (startIndex + length <= text.Length)
text = text.Substring(startIndex, length);
else
text = "";
}
}
faceTextBox1.Text = text;
}catch(Exception ex)
{
faceTextBox1.Text = "";
LogNet.log.Error("ShowPreview", ex);
}
}
private void ChkLengthEnd_CheckedChanged(object sender, EventArgs e)
{
if (changed) return;
NudLength.Enabled = !ChkLengthEnd.Checked;
ShowPreview();
}
private void BtnDel_Click(object sender, EventArgs e)
{
DelClick?.Invoke(this, new EventArgs());
}
private void CboKeyword_SelectedIndexChanged(object sender, EventArgs e)
{
KeyChanged?.Invoke(this, CboKeyword.Text);
}
private void ChkMatchingSplit_CheckedChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void NudSplitPart_ValueChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void NudStart_ValueChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void NudLength_ValueChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void ChkMinLength_CheckedChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void ChkMaxLength_CheckedChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void NudMinLength_ValueChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void NudMaxLength_ValueChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void CboMatchingSplit_SelectedIndexChanged(object sender, EventArgs e)
{
ShowPreview();
}
private void CboMatchingSplit_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
e.Handled = false;
}
private void BtnAdd_Click(object sender, EventArgs e)
{
AddClick?.Invoke(this, new EventArgs());
}
}
}