Config.cs
9.7 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
using System;
using System.Collections.Generic;
using System.Xml;
namespace BLL
{
public class Config
{
private XmlDocument _doc;
private XmlNode _root;
private XmlNode _node;
private string path;
private string lang;
private string _print; //打印机名称
private bool _landscape; //打印纵向横向
private string _label; //默认标签
private string _port; //灯光串口名称
private string _openCmd; //灯光打开命令
private string _camName; //相机名称
private bool _camSingle; //相机是否单个
private string _camSN; //相机序列号
private SmartCode.ScanType _scanType; //识别的类型
private SmartCode.TraceType _traceType; //追溯保存图片质量
private bool[] _limit; //权限
private bool _check; //标签校验
/// <summary>
/// 错误信息
/// </summary>
public string ErrInfo { get; private set; }
/// <summary>
/// 本地打印机列表
/// </summary>
public string[] PrinterList { get; private set; }
/// <summary>
/// 打印机名称
/// </summary>
public string PrinterName
{
get
{
return _print;
}
set
{
_print = value;
_root.SelectSingleNode("Printer").Attributes["Name"].Value = _print;
_doc.Save(path);
}
}
/// <summary>
/// 打印机横向纵向
/// </summary>
public bool PrinterLandscape
{
get
{
return _landscape;
}
set
{
_landscape = value;
_root.SelectSingleNode("Printer").Attributes["Landscape"].Value = _landscape.ToString();
_doc.Save(path);
}
}
/// <summary>
/// 默认标签名称
/// </summary>
public string LabelName
{
get
{
return _label;
}
set
{
_label = value;
_root.SelectSingleNode("Label").Attributes["Name"].Value = _label;
_doc.Save(path);
}
}
/// <summary>
/// 光源串口名
/// </summary>
public string LightPort
{
get
{
return _port;
}
set
{
_port = value;
_root.SelectSingleNode("Light").Attributes["Name"].Value = _port;
_doc.Save(path);
}
}
/// <summary>
/// 光源命令
/// </summary>
public string LightOpen
{
get
{
return _openCmd;
}
set
{
_openCmd = value;
_root.SelectSingleNode("Light").Attributes["Open"].Value = _openCmd;
_doc.Save(path);
}
}
/// <summary>
/// 光源关闭命令
/// </summary>
public string LightClose { get; private set; }
/// <summary>
/// 指定的相机
/// </summary>
public string CameraName
{
get
{
return _camName;
}
set
{
_camName = value;
_root.SelectSingleNode("Camera").Attributes["Name"].Value = _camName;
_doc.Save(path);
}
}
/// <summary>
/// 指定的相机是否单个
/// </summary>
public bool CameraSingle
{
get
{
return _camSingle;
}
set
{
_camSingle = value;
_root.SelectSingleNode("Camera").Attributes["Single"].Value = _camSingle.ToString();
_doc.Save(path);
}
}
/// <summary>
/// 指定相机序列号,单个时使用
/// </summary>
public string CameraSN
{
get
{
return _camSN;
}
set
{
_camSN = value;
_root.SelectSingleNode("Camera").Attributes["SN"].Value = _camSN;
_doc.Save(path);
}
}
/// <summary>
/// 识别类型
/// </summary>
public SmartCode.ScanType ScanType
{
get
{
return _scanType;
}
set
{
_scanType = value;
_root.SelectSingleNode("Scan").Attributes["Type"].Value = ((int)_scanType).ToString();
_doc.Save(path);
}
}
/// <summary>
/// 追溯保存图片质量
/// </summary>
public SmartCode.TraceType TraceType
{
get
{
return _traceType;
}
set
{
_traceType = value;
_root.SelectSingleNode("Trace").Attributes["Type"].Value = ((int)_traceType).ToString();
_doc.Save(path);
}
}
/// <summary>
/// 默认语言
/// </summary>
public string Language
{
get
{
return lang;
}
set
{
lang = value;
_root.SelectSingleNode("Language").InnerText = lang;
_doc.Save(path);
}
}
/// <summary>
/// IO的IP地址
/// </summary>
public string IOAddress { get; private set; }
/// <summary>
/// 用户权限
/// </summary>
public bool[] UserLimit
{
get
{
return _limit;
}
set
{
_limit = value;
int n = 0;
for (int i = 0; i < _limit.Length; i++)
{
if (_limit[i])
n += (int)Math.Pow(2, i);
}
_root.SelectSingleNode("Limit").Attributes["Value"].Value = n.ToString();
_doc.Save(path);
}
}
/// <summary>
/// 管理员模式
/// </summary>
public bool Admin { set; get; }
/// <summary>
/// 密码
/// </summary>
public string Password { private set; get; }
/// <summary>
/// 标签校验
/// </summary>
public bool Check
{
get
{
return _check;
}
set
{
_check = value;
_root.SelectSingleNode("Check").Attributes["Value"].Value = _check.ToString();
_doc.Save(path);
}
}
public Config(string path)
{
this.path = path;
try
{
_doc = new XmlDocument();
_doc.Load(path);
_root = _doc.LastChild;
//打印机
_node = _root.SelectSingleNode("Printer");
PrinterName = _node.Attributes["Name"].Value;
PrinterLandscape = Convert.ToBoolean(_node.Attributes["Landscape"].Value);
List<string> list = new List<string>();
foreach (string ss in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
list.Add(ss);
PrinterList = list.ToArray();
//默认标签
_node = _root.SelectSingleNode("Label");
LabelName = _node.Attributes["Name"].Value;
//灯光
_node = _root.SelectSingleNode("Light");
LightPort = _node.Attributes["Name"].Value;
LightOpen = _node.Attributes["Open"].Value;
LightClose = _node.Attributes["Close"].Value;
//相机
_node = _root.SelectSingleNode("Camera");
CameraName = _node.Attributes["Name"].Value;
CameraSingle = Convert.ToBoolean(_node.Attributes["Single"].Value);
CameraSN = _node.Attributes["SN"].Value;
//识别
_node = _root.SelectSingleNode("Scan");
ScanType = (SmartCode.ScanType)Convert.ToInt32(_node.Attributes["Type"].Value);
//追溯
_node = _root.SelectSingleNode("Trace");
TraceType = (SmartCode.TraceType)Convert.ToInt32(_node.Attributes["Type"].Value);
//权限
_node = _root.SelectSingleNode("Limit");
ushort n = Convert.ToUInt16(_node.Attributes["Value"].Value);
_limit = new bool[16];
for (int i = 0; i < _limit.Length; i++)
_limit[i] = (n & (int)Math.Pow(2, i)) > 0;
//密码
_node = _root.SelectSingleNode("Pwd");
Password = _node.Attributes["Value"].Value;
//标签校验
_node = _root.SelectSingleNode("Check");
_check = Convert.ToBoolean(_node.Attributes["Value"].Value);
_node = _root.SelectSingleNode("Language");
Language = _node.InnerText;
_node = _root.SelectSingleNode("IOIP");
IOAddress = _node.InnerText;
}
catch (Exception ex)
{
ErrInfo = ex.ToString();
return;
}
}
}
}