KaiFa.cs
4.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
/*
* kaifa
*/
using System;
using System.Collections.Generic;
using System.Linq;
using Model;
using Asa.FaceControl;
using System.Web.Script.Serialization;
namespace ExtensionGroup
{
public class KaiFa : IExtension
{
private int reelID = 0;
private List<ExtensionControl> extensions;
public event IExtension.PrintDelegate Printing;
public event IExtension.PrintDelegate SaveRetrospect;
public KaiFa() { }
public void Clear()
{
Log.Info("Clear()");
for (int i = 0; i < extensions.Count; i++)
{
if (!extensions[i].CanClear) continue;
if (extensions[i].Control is FaceComboBox box)
box.Items.Clear();
extensions[i].Control.Text = "";
}
}
public void Dispose()
{
}
public void Load(List<ExtensionControl> extensions)
{
this.extensions = extensions;
ReadReelID();
}
public void SetKey(string[] originalCode, Dictionary<string, string> key)
{
for (int i = 0; i < extensions.Count; i++)
{
if (key.ContainsKey(extensions[i].Key))
extensions[i].Control.Text = key[extensions[i].Key];
}
if (CanPrint())
PrintLabel(null, EventArgs.Empty);
}
public void Update()
{
}
private bool CanPrint()
{
int index = extensions.FindIndex(match => match.Control.Name == "TxtPart");
if (index == -1) return false;
if (extensions[index].Control.Text == "") return false;
index = extensions.FindIndex(match => match.Control.Name == "TxtQty");
if (index == -1) return false;
if (extensions[index].Control.Text == "") return false;
return true;
}
private void ReadReelID()
{
try
{
if (System.IO.File.Exists(FilePath.CONFIG_REELID))
{
string text = System.IO.File.ReadAllText(FilePath.CONFIG_REELID);
bool bln = int.TryParse(text, out reelID);
Log.Info($"ReadReelID {bln} text={text}");
}
else
{
System.IO.FileStream fs = System.IO.File.Create(FilePath.CONFIG_REELID);
fs.Close();
reelID = 0;
Log.Info("ReadReelID Create");
}
}
catch (Exception ex)
{
Log.Error("ReadReelID", ex);
System.Windows.Forms.MessageBox.Show(ex.Message, "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}
}
private void SaveAddReelID()
{
try
{
Log.Debug("打印标签前的ID:" + reelID);
reelID++;
System.IO.File.WriteAllText(FilePath.CONFIG_REELID, reelID.ToString());
Log.Info($"Save ReelID:{reelID}");
}
catch (Exception ex)
{
Log.Error("SaveAddReelID error", ex);
}
}
private void PrintLabel(object sender, EventArgs e)
{
Log.Debug("Enter PrintLabel Method");
Dictionary<string, string> key = new();
for (int i = 0; i < extensions.Count; i++)
{
if (extensions[i].Key == "") continue;
if (key.ContainsKey(extensions[i].Key))
key[extensions[i].Key] = extensions[i].Control.Text;
else
key.Add(extensions[i].Key, extensions[i].Control.Text);
}
SaveAddReelID();
Printing?.Invoke(key);
}
public bool SetKey(string[] originalCode, Dictionary<string, string> key, bool hasMatch, out string errmsg)
{
throw new NotImplementedException();
}
public void Print(bool match, Dictionary<string, string> key)
{
throw new NotImplementedException();
}
public void DrawTextBackground(Dictionary<string, string> key)
{
throw new NotImplementedException();
}
}
}