Traced.cs
3.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Xml;
namespace BLL
{
/// <summary>
/// 追溯类
/// </summary>
public class Traced
{
private XmlDocument _doc;
private List<CodeSplice.TraceTemp> _trac;
/// <summary>
/// 追溯类
/// </summary>
/// <param name="path"></param>
public Traced(string path)
{
try
{
string[] arr;
List<string> itemFile = new List<string>();
string[] file = System.IO.Directory.GetFiles(path);
foreach (string s in file)
if (s.ToUpper().EndsWith(".XML")) itemFile.Add(s);
_doc = new XmlDocument();
_trac = new List<CodeSplice.TraceTemp>();
for (int i = 0; i < itemFile.Count; i++) //文件循环
{
_doc.Load(itemFile[i]);
XmlElement root = (XmlElement)_doc.LastChild;
CodeSplice.TraceTemp temp = new CodeSplice.TraceTemp();
temp.Name = (i + 1).ToString();
temp.MateTemp = root.GetAttribute("MaterialTemp");
temp.MateImageName = root.GetAttribute("MaterialImage");
temp.MateImage = new Bitmap(path + temp.MateImageName);
temp.LabelTemp = root.GetAttribute("LabelTemp");
temp.LabelImageName = root.GetAttribute("LabelImage");
temp.LabelImage = new Bitmap(path + temp.LabelImageName);
int n = root.ChildNodes.Count;
for (int j = 0; j < n; j++) //标签区域循环
{
CodeSplice.BarCode code = new CodeSplice.BarCode();
XmlElement ele = (XmlElement)root.ChildNodes[j];
arr = ele.GetAttribute("Center").Split(',');
code.Center = new PointF(Convert.ToSingle(arr[0]), Convert.ToSingle(arr[1]));
code.Text = ele.GetAttribute("Text");
temp.Code.Add(code);
}
_trac.Add(temp);
}
}
catch (Exception ex)
{
CodeSplice.Common.Log.OutError(ex.ToString());
}
}
/// <summary>
/// 物料模板名称
/// </summary>
public string[] Name
{
get
{
string[] s = new string[_trac.Count];
for (int i = 0; i < s.Length; i++)
s[i] = _trac[i].Name;
return s;
}
}
/// <summary>
/// 物料模板总数
/// </summary>
public int Count
{
get
{
if (_trac == null)
return -1;
else
return _trac.Count;
}
}
public int Index { set; get; } = -1;
public CodeSplice.TraceTemp GetTrace(int index)
{
return _trac[index];
}
public void Add(CodeSplice.TraceTemp temp)
{
_trac.Add(temp);
}
}
}