Asa_Common.cs
6.1 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
using System;
using System.Collections.Generic;
using System.Drawing;
namespace Asa
{
/// <summary>
/// 公共的
/// </summary>
public static class Common
{
/// <summary>
/// 设置文件的路径
/// </summary>
public static readonly string SET_FILE_PATH = System.IO.Directory.GetCurrentDirectory() + "\\Setting.xml";
/// <summary>
/// 模板文件的路径文件夹
/// </summary>
public static readonly string ITEM_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Item\\";
/// <summary>
/// 日志文件的路径文件夹
/// </summary>
public static readonly string LOG_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Log\\";
/// <summary>
/// 用于生成标签的路径文件夹
/// </summary>
public static readonly string LABEL_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Label\\";
/// <summary>
/// 用于语言的路径文件夹
/// </summary>
public static readonly string LANGUAGE_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Language\\";
public static Basler_Pylon Camera = new Basler_Pylon();
public static Template Template = new Template();
public static ConfigParam Config = new ConfigParam();
public static CodeLabel Label = new CodeLabel();
public static MultLang Language = new MultLang();
/// <summary>
/// 日志输出
/// </summary>
/// <param name="s"></param>
public static void LogOut(string s)
{
//if (!System.IO.Directory.Exists(LOG_DIR))
// System.IO.Directory.CreateDirectory(LOG_DIR);
//string path = LOG_DIR + string.Format("{0:yyyy_MM_dd}.txt", DateTime.Now);
//string contents = string.Format("{0:HH:mm:ss}->", DateTime.Now) + s + "\r\n";
//System.IO.File.AppendAllText(path, contents, System.Text.Encoding.UTF8);
}
/// <summary>
/// 日志输出
/// </summary>
/// <param name="rtx"></param>
/// <param name="s"></param>
public static void LogOut(System.Windows.Forms.RichTextBox rtx, string s)
{
rtx.AppendText(s + "\r\n");
LogOut(s);
}
}
/// <summary>
/// 配置
/// </summary>
public class ConfigParam
{
/// <summary>
/// 拼接需要用到的字段
/// </summary>
public List<string> Field = new List<string>();
/// <summary>
/// 拼接字符串的字符
/// </summary>
public string Chars = "";
/// <summary>
/// 起始,长度,当前
/// </summary>
public int[] RID;
/// <summary>
/// 默认打印机
/// </summary>
public string Printer;
/// <summary>
/// 本地打印机列表
/// </summary>
public List<string> PrinterList = new List<string>();
/// <summary>
/// 光源串口名
/// </summary>
public string LightPort;
/// <summary>
/// 所有本地串口
/// </summary>
public List<string> SerialPort = new List<string>();
public string LabelDefault;
public string TemplateDefault;
public string Language;
private XML xml;
/// <summary>
/// 初始化,读取设置
/// </summary>
public ConfigParam()
{
xml = new XML();
xml.Open(Common.SET_FILE_PATH);
Field.AddRange(xml.GetText("Field").Split(','));
Chars = xml.GetText("Chars");
Printer = xml.GetText("Printer");
LightPort = xml.GetText("Light");
LabelDefault = xml.GetText("Label");
TemplateDefault = xml.GetText("TempLate");
Language = xml.GetText("Language");
string[] s = xml.GetText("Rid").Split(',');
RID = new int[3];
RID[0] = Convert.ToInt32(s[0]);
RID[1] = Convert.ToInt32(s[1]);
RID[2] = Convert.ToInt32(s[2]);
foreach (string ss in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
PrinterList.Add(ss);
SerialPort.AddRange(System.IO.Ports.SerialPort.GetPortNames());
}
/// <summary>
/// 字段添加
/// </summary>
/// <param name="s"></param>
public void FieldAdd(string s)
{
Field.Add(s);
string f = string.Join(",", Field);
xml.SetText(f, "Field");
xml.Save();
}
/// <summary>
/// 字段删除
/// </summary>
/// <param name="idx"></param>
public void FieldDel(int idx)
{
Field.RemoveAt(idx);
string f = string.Join(",", Field);
xml.SetText(f, "Field");
xml.Save();
}
/// <summary>
/// rid字段更新
/// </summary>
public void UpdateRid()
{
xml.SetText(string.Join(",", RID), "Rid");
xml.Save();
}
public void UpdateLabel(string s)
{
xml.SetText(s, "Label");
xml.Save();
}
public void UpdateTemplate(string s)
{
xml.SetText(s, "Template");
xml.Save();
}
public void UpdateLanguage(string s)
{
xml.SetText(s, "Language");
Language = s;
xml.Save();
}
}
/// <summary>
/// 标签区域矩形
/// </summary>
public class AreaRect
{
/// <summary>
/// 中心点
/// </summary>
public PointF Center;
/// <summary>
/// 区域大小
/// </summary>
public SizeF Size;
/// <summary>
/// 旋转角度
/// </summary>
public float Angle;
/// <summary>
/// 区域点坐标
/// </summary>
public PointF[] Points;
/// <summary>
/// 文本
/// </summary>
public string Text;
}
}