SteelManage.cs
8.6 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using Model;
using AGVControl_Steel;
using System.Collections.Generic;
namespace BLL
{
public class SteelManage
{
private List<SteelWork> oldSteelWork;
private List<SteelWork> newSteelWork;
public SteelManage()
{
oldSteelWork = new List<SteelWork>();
newSteelWork = new List<SteelWork>();
}
//public int OldSteelWorkCount
//{
// get
// {
// return oldSteelWork.Count;
// }
//}
//public int NewSteelWorkCount
//{
// get
// {
// return newSteelWork.Count;
// }
//}
public void OldSteelWorkAdd(string place)
{
int index = oldSteelWork.FindIndex(sw => sw.Place == place);
if (index == -1)
{
SteelWork sw = new SteelWork() { Place = place };
oldSteelWork.Add(sw);
string[] content = new string[oldSteelWork.Count];
for (int i = 0; i < content.Length; i++)
content[i] = oldSteelWork[i].Place + "," + oldSteelWork[i].DateTime.ToString();
if (Common.txtOldSteel != null) Common.txtOldSteel.Text = string.Join("\r\n", content);
System.IO.File.WriteAllLines(Common.PATH_OLD_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
Common.log.Debug("添加(" + place + ")旧钢板任务,保存到" + Common.PATH_OLD_STEEL_WORK);
}
public void OldSteelWorkDel(string place)
{
int index = oldSteelWork.FindIndex(sw => sw.Place == place);
if (index > -1)
{
oldSteelWork.RemoveAt(index);
string[] content = new string[oldSteelWork.Count];
for (int i = 0; i < content.Length; i++)
content[i] = oldSteelWork[i].Place + "," + oldSteelWork[i].DateTime.ToString();
if (Common.txtOldSteel != null) Common.txtOldSteel.Text = string.Join("\r\n", content);
System.IO.File.WriteAllLines(Common.PATH_OLD_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
Common.log.Debug("删除(" + place + ")旧钢板任务,保存到" + Common.PATH_OLD_STEEL_WORK);
}
public void OldSteelWorkLoad()
{
oldSteelWork = new List<SteelWork>();
if (!System.IO.File.Exists(Common.PATH_OLD_STEEL_WORK)) return;
string[] lines = System.IO.File.ReadAllLines(Common.PATH_OLD_STEEL_WORK, System.Text.Encoding.UTF8);
if (Common.txtOldSteel != null) Common.txtOldSteel.Text = string.Join("\r\n", lines);
for (int i = 0; i < lines.Length; i++)
{
string[] arr = lines[i].Split(',');
SteelWork sw = new SteelWork() { Place = arr[0], DateTime = Convert.ToDateTime(arr[1]) };
oldSteelWork.Add(sw);
}
Common.log.Debug("加载旧钢板任务,来自" + Common.PATH_OLD_STEEL_WORK);
}
public bool FindOldSteelWork(AgvInfo info, out string place)
{
int index = -1;
string name = "";
bool find = false;
string s = info.Workshop.Substring(1, 1);
for (int i = 0; i < Common.PLACE_NAME.Length; i++)
{
name = Common.PLACE_NAME[i];
if (name.StartsWith(s))
{
index = oldSteelWork.FindIndex(s => s.Place == name);
if (index > -1)
{
find = true;
break;
}
}
}
place = name;
return find;
}
public void NewSteelWorkAdd(string from, string place)
{
int index = newSteelWork.FindIndex(sw => sw.From == from && sw.Place == place);
if (index == -1)
{
SteelWork sw = new SteelWork() { From = from, Place = place };
newSteelWork.Add(sw);
string[] content = new string[newSteelWork.Count];
for (int i = 0; i < content.Length; i++)
content[i] = newSteelWork[i].From + "," + newSteelWork[i].Place + "," + newSteelWork[i].DateTime.ToString();
if (Common.txtNewSteel != null) Common.txtNewSteel.Text = string.Join("\r\n", content);
System.IO.File.WriteAllLines(Common.PATH_NEW_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
Common.log.Debug("添加(" + from + "," + place + ")新钢板任务,保存到" + Common.PATH_NEW_STEEL_WORK);
}
public void NewSteelWorkDel(string from, string place)
{
int index = newSteelWork.FindIndex(sw => sw.From == from && sw.Place == place);
if (index > -1)
{
newSteelWork.RemoveAt(index);
string[] content = new string[newSteelWork.Count];
for (int i = 0; i < content.Length; i++)
content[i] = newSteelWork[i].From + "," + newSteelWork[i].Place + "," + newSteelWork[i].DateTime.ToString();
if (Common.txtNewSteel != null) Common.txtNewSteel.Text = string.Join("\r\n", content);
System.IO.File.WriteAllLines(Common.PATH_NEW_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
Common.log.Debug("删除(" + from + "," + place + ")新钢板任务,保存到" + Common.PATH_NEW_STEEL_WORK);
}
public void NewSteelWorkLoad()
{
newSteelWork = new List<SteelWork>();
if (!System.IO.File.Exists(Common.PATH_NEW_STEEL_WORK)) return;
string[] lines = System.IO.File.ReadAllLines(Common.PATH_NEW_STEEL_WORK, System.Text.Encoding.UTF8);
if (Common.txtNewSteel != null) Common.txtNewSteel.Text = string.Join("\r\n", lines);
for (int i = 0; i < lines.Length; i++)
{
string[] arr = lines[i].Split(',');
SteelWork sw = new SteelWork() { From = arr[0], Place = arr[1], DateTime = Convert.ToDateTime(arr[2]) };
newSteelWork.Add(sw);
}
Common.log.Debug("加载新钢板任务,来自" + Common.PATH_NEW_STEEL_WORK);
}
public bool FindNewSteelWork(AgvInfo info, out string place)
{
int index = -1;
string name = "";
bool find = false;
for (int i = 0; i < Common.PLACE_NAME.Length; i++)
{
name = Common.PLACE_NAME[i];
index = newSteelWork.FindIndex(s => s.From == info.SteelFrom && s.Place == name);
if (index > -1)
{
find = true;
break;
}
}
place = name;
return find;
}
public bool FindNewSteelWork(AgvInfo info)
{
int index = newSteelWork.FindIndex(s => s.From == info.SteelFrom);
if (index > -1)
return true;
else
return false;
}
public Job GetSteelJob(AgvInfo info)
{
//TEST
string s = "";
for (int i = 0; i < oldSteelWork.Count; i++)
s += oldSteelWork[i].Place + ";";
Common.log.Debug("TEST oldSteelWork=" + s);
s = "";
for (int i = 0; i < newSteelWork.Count; i++)
s += newSteelWork[i].From + "," + newSteelWork[i].Place + "; ";
Common.log.Debug("TEST newSteelWork=" + s);
//回收旧钢板
string name = info.Workshop.Substring(1, 1);
int index = oldSteelWork.FindIndex(s => s.Place.StartsWith(name));
if (index > -1)
{
Common.log.Info(info.Workshop + "旧钢板回收");
return new TakeOldJob();
}
//清洗点呼叫
index = newSteelWork.FindIndex(s => s.From.StartsWith(info.Workshop.ToLower()) && s.From == s.Place);
if (index > -1)
{
info.SteelFrom = newSteelWork[index].From;
Common.log.Info(info.Workshop + "清洗点呼叫");
return new WashPointJob();
}
//仓库呼叫
index = newSteelWork.FindIndex(s => s.From == "storage" && s.From == s.Place);
if (index > -1)
{
info.SteelFrom = newSteelWork[index].From;
Common.log.Info("4D仓库呼叫");
return new StorageJob();
}
return null;
}
}
}