PositionDebugManager.cs
5.5 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class PosDebugResultManager
{
public static List<DrawerResult> DrawerResults;
public static bool isInit = false;
static string filePath = Application.StartupPath + Common.ConfigAppSettings.GetValue(Common.Setting_Init.ConfigPath_PosDebugInfo);
public static void Init(List<string> posNumList)
{
if (!System.IO.File.Exists(filePath))
{
DrawerResults = new List<DrawerResult>();
foreach (var item in posNumList)
{
DrawerResult res = DrawerResults.Find(s => s.DrawerName.Equals(item.Substring(0, 8)));
if (res == null)
{
res = new DrawerResult() { DrawerName = item.Substring(0, 8) };
res.PosResultList.Add(new PosDebugResult() { Name = item });
DrawerResults.Add(res);
}
else
{
res.PosResultList.Add(new PosDebugResult() { Name = item });
}
}
}
else
{
string[] txt = System.IO.File.ReadAllLines(filePath);
DrawerResults = new List<DrawerResult>();
if (txt == null || txt.Length==0)
{
foreach (var item in posNumList)
{
DrawerResult res = DrawerResults.Find(s => s.DrawerName.Equals(item.Substring(0, 8)));
if (res == null)
{
res = new DrawerResult() { DrawerName = item.Substring(0, 8) };
res.PosResultList.Add(new PosDebugResult() { Name = item });
}
else
{
res.PosResultList.Add(new PosDebugResult() { Name = item });
}
}
}
else
{
foreach (var item in txt)
{
DrawerResults.Add(Common.JsonHelper.DeserializeJsonToObject<DrawerResult>(item)) ;
}
}
}
isInit = true;
}
public static void SaveResult()
{
try
{
List<string> res = new List<string>();
foreach (var item in DrawerResults)
{
res.Add(Common.JsonHelper.SerializeObject(item));
}
System.IO.File.WriteAllLines(filePath, res);
}
catch (Exception e)
{
Common.LogUtil.error("SaveResult", e);
}
}
/// <summary>
/// 获取抽屉调试结果
/// </summary>
/// <param name="drawername"></param>
/// <returns></returns>
public static int GetDrawerResult(string drawername)
{
if (!isInit)
return -1;
DrawerResult drawerResult = DrawerResults.Find(s => s.DrawerName.Equals(drawername));
return drawerResult.ResultCode;
}
public static void SetDrawerResult(string drawername, int code)
{
if (!isInit)
return;
DrawerResult drawerResult = DrawerResults.Find(s => s.DrawerName.Equals(drawername));
drawerResult.ResultCode = code;
}
/// <summary>
/// 通过料格结果得出抽屉结果
/// </summary>
public static int SetDrawerResultWithGrid(string drawername)
{
if (!isInit)
return -1;
DrawerResult drawerResult = DrawerResults.Find(s => s.DrawerName.Equals(drawername));
PosDebugResult posDebugResult = drawerResult.PosResultList.Find(s => s.ResCode.Equals(0) || s.ResCode.Equals(-1));
if (posDebugResult == null)
{
drawerResult.ResultCode = 1;
return 1;
}
else
{
drawerResult.ResultCode = 0;
return 0;
}
}
/// <summary>
/// 设置料格的状态
/// </summary>
/// <param name="drawername">抽屉名</param>
/// <param name="code">结果代码</param>
public static void SetGridResult(string name, int code)
{
DrawerResult drawerResult = DrawerResults.Find(s => s.DrawerName.Equals(name.Substring(0, 8)));
if (drawerResult != null)
{
PosDebugResult res = drawerResult.PosResultList.Find(s => s.Name.Equals(name));
if (res != null)
res.ResCode = code;
}
}
/// <summary>
/// 获取料格状态
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int GetGridResult(string name)
{
DrawerResult drawerResult = DrawerResults.Find(s => s.DrawerName.Equals(name.Substring(0, 8)));
if (drawerResult != null)
{
PosDebugResult res = drawerResult.PosResultList.Find(s => s.Name.Equals(name));
if (res != null)
return res.ResCode;
}
return -1;
}
}
}