PositionDebugManager.cs
4.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class PosDebugResultManager
{
public static List<DrawerResult> DrawerResults;
public static bool isInit = false;
static string filePath = 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.ReadAllText(filePath);
if (txt.Length == 0)
{
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 });
}
else
{
res.PosResultList.Add(new PosDebugResult() { Name = item });
}
}
}
else
DrawerResults = Common.JsonHelper.DeserializeJsonToList<DrawerResult>(txt);
}
isInit = true;
}
/// <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>
/// <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;
}
}
}