FrmCodeExtract.cs
6.2 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Asa.FaceControl;
using Model;
namespace SmartScan
{
public partial class FrmCodeExtract : FaceFormNormal
{
private readonly int codeID;
private readonly string codeText;
private readonly string codeType;
private readonly Dictionary<FaceButton, UsrCodeExtractList> matchButton = new();
int windowHeight = 0;
public FrmCodeExtract(string codeText, int codeID,string codeType, List<MaterialCodeMatch> match)
{
InitializeComponent();
windowHeight = this.Height;
codeText = codeText.Replace("\r", "");
this.codeText = codeText.Replace("\n", "");
this.codeID = codeID;
this.codeType = codeType;
for (int i = 0; i < match.Count; i++)
AddMatch(match[i]);
if (matchButton.Count > 0)
Btn_Click(matchButton.ElementAt(0).Key, EventArgs.Empty);
else
BtnAddMatch_Click(null, EventArgs.Empty);
}
public List<MaterialCodeMatch> CodeMatch { get; private set; }
private void AddMatch(MaterialCodeMatch match)
{
FaceButton btn = new() { Text = string.Format("[{0}]", match.Keyword), Margin = new Padding(0, 0, 6, 6), Width = 100, Height = 50 };
btn.Click += Btn_Click;
flowLayoutPanel1.Controls.Add(btn);
UsrCodeExtractList list = new(codeText,codeType, codeText.Length, match);
list.DelClick += List_DelClick;
list.KeyChanged += List_KeyChanged;
matchButton.Add(btn, list);
FacePanel pnl = list.GetPanel();
pnl.Left = PnlTemp.Left;
pnl.Top = PnlTemp.Top;
pnl.Width = PnlTemp.Width;
pnl.Height = PnlTemp.Height;
pnl.Anchor = PnlTemp.Anchor;
pnl.Visible = false;
Controls.Add(pnl);
clacWindowHeight();
}
void clacWindowHeight() {
if (flowLayoutPanel1.Controls.Count > 14)
{
matchButton.Values.ToList().ForEach((x)=> {x.GetPanel().Top = 184 + 56 * 2; });
flowLayoutPanel1.Height = 56 * 3;
this.Height = windowHeight + 56 * 2 - 4;
}
else if (flowLayoutPanel1.Controls.Count > 7)
{
matchButton.Values.ToList().ForEach((x) => { x.GetPanel().Top = 184 + 56 * 1; });
flowLayoutPanel1.Height = 56 * 2 - 4;
this.Height = windowHeight + 56;
}
else
{
matchButton.Values.ToList().ForEach((x) => { x.GetPanel().Top = 184; });
flowLayoutPanel1.Height = 56 - 4;
this.Height = windowHeight;
}
}
private void List_KeyChanged(object sender, string key)
{
UsrCodeExtractList ctl = sender as UsrCodeExtractList;
foreach (FaceButton btn in matchButton.Keys)
{
if (matchButton[btn] != ctl) continue;
btn.Text = string.Format("[{0}]", key);
break;
}
}
private void List_DelClick(object sender, EventArgs e)
{
UsrCodeExtractList ctl = sender as UsrCodeExtractList;
foreach (FaceButton btn in matchButton.Keys)
{
if (matchButton[btn] != ctl) continue;
flowLayoutPanel1.Controls.Remove(btn);
Controls.Remove(matchButton[btn].GetPanel());
matchButton.Remove(btn);
break;
}
if (matchButton.Count > 0)
{
matchButton.Last().Key.HoldPress = true;
matchButton.Last().Value.GetPanel().Visible = true;
}
clacWindowHeight();
}
private void BtnAddMatch_Click(object sender, EventArgs e)
{
MaterialCodeMatch temp = new() { SubstringLength = -1 };
AddMatch(temp);
Btn_Click(matchButton.ElementAt(matchButton.Count - 1).Key, EventArgs.Empty);
//foreach (FaceButton button in matchButton.Keys)
//{
// bool rtn = button == matchButton.ElementAt(matchButton.Count - 1).Key;
// matchButton[button].GetPanel().Visible = rtn;
//}
}
private void Btn_Click(object sender, EventArgs e)
{
foreach (FaceButton button in matchButton.Keys)
{
bool rtn = button == sender;
button.HoldPress = rtn;
matchButton[button].GetPanel().Visible = rtn;
}
}
private void BtnOK_Click(object sender, EventArgs e)
{
Dictionary<string, int> keyTemp = new();
foreach (FaceButton btn in matchButton.Keys)
{
string key = matchButton[btn].GetMatchKey();
if (keyTemp.ContainsKey(key))
keyTemp[key]++;
else
keyTemp.Add(key, 1);
}
foreach (string key in keyTemp.Keys)
{
if (keyTemp[key] > 1)
{
string text = Language.Dialog("KeyRepeat") + "\r\n";
text += string.Format("{0} * {1}", key, keyTemp[key]);
new FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
return;
}
}
CodeMatch = new();
foreach (FaceButton btn in matchButton.Keys)
{
MaterialCodeMatch match = matchButton[btn].GetMatch();
match.CodeID = codeID;
CodeMatch.Add(match);
}
DialogResult = DialogResult.OK;
}
private void BtnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void FrmCodeExtract_Load(object sender, EventArgs e)
{
LblCode.Text = codeText;
}
}
}