UsrMacro.cs
5.3 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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Model;
namespace SmartScan
{
public partial class UsrMacro : UserControl, ISetMenu
{
private readonly List<string> keyCopy;
public UsrMacro()
{
InitializeComponent();
keyCopy = new(Common.macroKey);
LstKey.Items.AddRange(keyCopy.ToArray());
setRIkey();
TxtReelIDMatch.Text = Common.config.ReelIDMatch;
TxtPrefix.Text = Common.config.ReelIDPrefix;
TxtPostfix.Text = Common.config.ReelIDPostfix;
NumReelIDPlaces.Value = Common.config.ReelIDPlaces;
ChkReelIDFillZero.Checked = Common.config.ReelIDFillZero;
ChkResetidbydate.Checked = Common.config.ReelIDAutoResetByDate;
Asa.FaceControl.Language.SetLanguage(this);
}
public Asa.FaceControl.FacePanel GetPanel()
{
return facePanel1;
}
public void Save()
{
Common.macroKey.Clear();
Common.macroKey.AddRange(keyCopy);
System.IO.File.WriteAllLines(FilePath.CONFIG_MACRO_KEY, Common.macroKey.ToArray());
Common.config.ReelIDMatch = TxtReelIDMatch.Text;
Common.config.ReelIDPrefix = TxtPrefix.Text;
Common.config.ReelIDPostfix = TxtPostfix.Text;
Common.config.ReelIDPlaces = (int)NumReelIDPlaces.Value;
Common.config.ReelIDFillZero = ChkReelIDFillZero.Checked;
Common.config.ReelIDAutoResetByDate = ChkResetidbydate.Checked;
Common.config.Save();
}
void setRIkey() {
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
for (int i = 0; i < LstKey.Items.Count; i++)
{
if (LstKey.Items[i] == Common.config.ReelIDKeyWord)
LstKey.Items[i] = "[RI]" + LstKey.Items[i];
}
}
private void LstKey_SelectedIndexChanged(object sender, EventArgs e)
{
if(LstKey.SelectedIndex>=0)
TxtKey.Text = keyCopy[LstKey.SelectedIndex];
}
private void BtnAddKey_Click(object sender, EventArgs e)
{
string text = TxtKey.Text;
int index = keyCopy.FindIndex(match => match == text);
if (index == -1)
{
keyCopy.Add(text);
LstKey.Items.Add(text);
}
else
{
string hint = Asa.FaceControl.Language.Dialog("KeyExists");
hint = hint.Replace("[name]", text);
new Asa.FaceControl.FaceMessageBox("", hint, MessageBoxButtons.OK).ShowDialog();
}
}
private void BtnDelKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
keyCopy.RemoveAt(LstKey.SelectedIndex);
LstKey.Items.RemoveAt(LstKey.SelectedIndex);
}
private void BtnUpdateKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
string text = TxtKey.Text;
int index = keyCopy.FindIndex(match => match == text);
if (index == -1)
{
keyCopy[LstKey.SelectedIndex] = text;
LstKey.Items[LstKey.SelectedIndex] = text;
setRIkey();
}
else
{
string hint = Asa.FaceControl.Language.Dialog("KeyExists");
hint = hint.Replace("[name]", text);
new Asa.FaceControl.FaceMessageBox("", hint, MessageBoxButtons.OK).ShowDialog();
}
}
private void BtnAppendKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
string key = "[" + LstKey.Text + "]";
TxtReelIDMatch.AppendText(key);
}
private void btn_up_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1 || LstKey.SelectedIndex ==0) return;
keyCopy.Insert(LstKey.SelectedIndex - 1, keyCopy[LstKey.SelectedIndex]);
keyCopy.RemoveAt(LstKey.SelectedIndex+1);
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
LstKey.SelectedIndex = LstKey.SelectedIndex - 1;
}
private void btn_down_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1 || LstKey.SelectedIndex == keyCopy.Count-1) return;
keyCopy.Insert(LstKey.SelectedIndex+2, keyCopy[LstKey.SelectedIndex]);
keyCopy.RemoveAt(LstKey.SelectedIndex);
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
LstKey.SelectedIndex = LstKey.SelectedIndex + 1;
}
private void btn_setriid_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
if (keyCopy[LstKey.SelectedIndex] == Common.config.ReelIDKeyWord)
Common.config.ReelIDKeyWord = "";
else
Common.config.ReelIDKeyWord = keyCopy[LstKey.SelectedIndex];
setRIkey();
}
private void btn_adddatetime_Click(object sender, EventArgs e)
{
string key = "[datetime:yyyyMMdd]";
TxtReelIDMatch.AppendText(key);
}
}
}