PosDebug.cs
6.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
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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class PosDebug
{
static string filePath = $"{Application.StartupPath}//StoreConfig//pos_debug.json";
static object locker = new object();
/// <summary>
/// 左侧库位结果表
/// </summary>
public List<PosPos> LPos { get; set; }
/// <summary>
/// 右侧库位结果表
/// </summary>
public List<PosPos> RPos { get; set; }
public int Total { get; set; }
public int Ok { get; set; }
public void Start()
{
Total++;
ClearPosState();
}
public int GetRows()
{
return LPos.Select(s=>s.Row).Max();
}
public int GetCols()
{
return LPos.Select(s => s.Col).Max();
}
public bool Exist(string posId,out PosPos posPos)
{
posPos = null;
int idx = LPos.FindIndex(s => s.PosId.Equals(posId));
if (idx == -1)
{
idx = RPos.FindIndex(s => s.PosId.Equals(posId));
if (idx == -1)
return false;
else
{
posPos = RPos[idx];
}
}
else
{
posPos = LPos[idx];
}
return true;
}
/// <summary>
///
/// </summary>
/// <param name="posId"></param>
/// <param name="posPos"></param>
/// <param name="dir">0:左侧</param>
/// <returns></returns>
public bool Exist(string posId, out PosPos posPos,out int dir)
{
posPos = null;
dir = 0;
int idx = LPos.FindIndex(s => s.PosId.Equals(posId));
if (idx == -1)
{
idx = RPos.FindIndex(s => s.PosId.Equals(posId));
if (idx == -1)
return false;
else
{
posPos = RPos[idx];
dir = 1;
}
}
else
{
posPos = LPos[idx];
}
return true;
}
void SetPosState(string posId,StoreMoveType moveType)
{
int idx = LPos.FindIndex(s=>s.PosId.Equals(posId));
if(idx == -1)
{
idx= RPos.FindIndex(s=>s.PosId.Equals(posId));
if(idx != -1)
{
if (moveType.Equals(StoreMoveType.InStore))
{
RPos[idx].PosState.InStoreCheck = 1;
}
else if (moveType.Equals(StoreMoveType.OutStore))
{
RPos[idx].PosState.OutStoreCheck = 1;
}
}
}
else
{
if (moveType.Equals(StoreMoveType.InStore))
{
LPos[idx].PosState.InStoreCheck = 1;
}
else if (moveType.Equals(StoreMoveType.OutStore))
{
LPos[idx].PosState.OutStoreCheck = 1;
}
}
}
public void AddResult(string posId, StoreMoveType movetype, bool isLast)
{
if (Monitor.TryEnter(locker, 500))
{
try
{
if (isLast)
Ok++;
SetPosState(posId, movetype);
File.WriteAllText(filePath, JsonHelper.SerializeObject(this));
}
finally
{
Monitor.Exit(locker);
}
}
}
private void ClearPosState()
{
foreach (var item in LPos)
{
item.PosState.InStoreCheck = 0;
item.PosState.OutStoreCheck = 0;
}
foreach (var item in RPos)
{
item.PosState.InStoreCheck = 0;
item.PosState.OutStoreCheck = 0;
}
}
public static PosDebug Init(List<string> posNumList)
{
PosDebug posDebug;
if (File.Exists(filePath))
{
string txt = File.ReadAllText(filePath);
posDebug = JsonHelper.DeserializeJsonToObject<PosDebug>(txt);
if (posDebug != null)
return posDebug;
}
posDebug = new PosDebug();
posDebug.LPos = new List<PosPos>();
posDebug.RPos = new List<PosPos>();
for (int i = 0; i < posNumList.Count; i++)
{
//AC1#R1_1_11
//AC1#L1_1_11
string pos = posNumList[i];
string[] dir = pos.Split('#');
if (dir[1].StartsWith("L"))
{
posDebug.LPos.Add(new PosPos { PosId = pos, Index = i });
}
else
{
posDebug.RPos.Add(new PosPos { PosId = pos, Index = i });
}
}
return posDebug;
}
}
//AC1#L1_1_11
public class PosPos
{
/// <summary>
/// 库位ID
/// </summary>
public string PosId { get; set; }
/// <summary>
/// 库位名
/// </summary>
public string PosName { get { return PosId.Split('#')[1]; } }
/// <summary>
/// 所在库位列表的索引
/// </summary>
public int Index { get; set; }
/// <summary>
/// 库位所在层
/// </summary>
public int Row { get { return int.Parse(PosId.Split('#')[1].Split('_')[2]); } }
/// <summary>
/// 库位所在列
/// </summary>
public int Col { get { return int.Parse(PosId.Split('#')[1].Split('_')[0].Substring(1)); } }
public PosState PosState { get; set; } = new PosState();
}
/// <summary>
/// 库位状态
/// </summary>
public class PosState
{
public int InStoreCheck = 0;
public int OutStoreCheck = 0;
}
}