PosInfos.cs
6.0 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
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.LinkLabel;
using System.Windows.Forms;
using System.IO;
using OnlineStore.Common;
namespace CtuDeviceLib
{
public class PosInfos
{
static List<PosInfo> _PosInfos = new List<PosInfo>();
public static bool Load(string linefilePath)
{
if (!File.Exists(linefilePath))
{
LogUtil.error($"未找到料架配置路径:{linefilePath}");
return false;
}
LogUtil.info($"加载料架配置:{linefilePath}");
string[] lines = File.ReadAllLines(linefilePath);
List<PosInfo> _tempPosInfos = new List<PosInfo>();
for (int i = 1; i < lines.Length; i++)
{
string[] fields = lines[i].Split(',');
if (fields.Length < 8)
continue;
string posId = fields[0];
string pointCode = fields[1];
int.TryParse(fields[2], out int updown);
int.TryParse(fields[3], out int inout);
int.TryParse(fields[4], out int scancode);
int.TryParse(fields[5], out int containerWidth);
var shelve = new Shelves(posId, pointCode, updown, inout, scancode, containerWidth);
string side = fields[6].Trim();
if (!string.IsNullOrEmpty(side))
{
shelve.Side = side[0];
}
shelve.Desc = fields[7];
if (_tempPosInfos.Find(s => s.ShelveCode == posId) != null)
{
LogUtil.error($"{posId} 已存在,请确保货架码唯一");
MessageBox.Show($"{posId} 已存在,请确保货架码唯一");
return false;
}
var pos = new PosInfo()
{
Name = posId.Trim(),
Dir = (byte)(shelve.Side == 'L' ? 1 : 2),
InoutDepth = shelve.InoutDepth,
PointCode = shelve.PointCode,
ScanCodeShift = shelve.ScanCodeShift,
ShelveCode = posId.Trim(),
UpDownHeight = shelve.UpDownHeight,
Lanway = shelve.Lanway,
Row = shelve.Row,
};
if (!string.IsNullOrEmpty(shelve.Desc))
{
pos.Name = shelve.Desc.Trim();
}
_tempPosInfos.Add(pos);
}
_PosInfos = _tempPosInfos.ToList();
return true;
}
public static List<PosInfo> GetAllPosInfos()
{
return _PosInfos;
}
/// <summary>
/// 根据名称获取其位置信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static PosInfo GetPosInfoByName(string name)
{
return _PosInfos.Find(s => s.Name.Equals(name));
}
public static PosInfo GetPosInfoByPtCode(uint pt)
{
return _PosInfos.Find(s => s.PointCode.Equals(pt));
}
}
/// <summary>
/// 货架
/// </summary>
public class Shelves
{
/// <summary>
/// 货架号
/// </summary>
public string PosId { get; set; }
/// <summary>
/// 楼层
/// </summary>
public int Floor { get; set; }
/// <summary>
/// 巷道编码
/// </summary>
public string Lanway { get; set; }
/// <summary>
/// 库位在车头的左侧/右侧
/// </summary>
public char Side { get; set; }
/// <summary>
/// 地面点位编码
/// </summary>
public uint PointCode { get; set; }
/// <summary>
/// 所在层
/// </summary>
public int Row { get; set; }
/// <summary>
/// 升降高度
/// </summary>
public int UpDownHeight { get; set; }
/// <summary>
/// 进出深度
/// </summary>
public int InoutDepth { get; set; }
/// <summary>
/// 料箱码读码偏移距离
/// </summary>
public int ScanCodeShift { get; set; }
/// <summary>
/// 料箱宽度
/// </summary>
public int ContainerWidth { get; set; }
//描述
public string Desc { get; set; }
/// <summary>
/// 货架码
/// 16位
/// </summary>
/// <param name="posid"></param>
public Shelves(string posid, string pointcode, int updown, int inout, int scancode, int containerWidth)
{
if (string.IsNullOrEmpty(posid))
return;
if (posid.Length < 16)
{
posid = "";
Lanway = "";
if (!string.IsNullOrEmpty(pointcode))
{
PointCode = uint.Parse(pointcode);
}
InoutDepth = inout;
ScanCodeShift = scancode;
ContainerWidth = containerWidth;
return;
}
PosId = posid;
string floor = posid.Substring(0, 1);
string laneway = posid.Substring(1, 3);
string side = posid.Substring(4, 1);
string pointCode = posid.Substring(5, 8);
if (!string.IsNullOrEmpty(pointcode))
{
pointCode = pointcode;
}
string row = posid.Substring(14);
int.TryParse(floor, out int val);
Floor = val;
Lanway = laneway;
Side = side[0];
PointCode = uint.Parse(pointCode);
Row = int.Parse(row);
UpDownHeight = updown;
InoutDepth = inout;
ScanCodeShift = scancode;
ContainerWidth = containerWidth;
}
}
}