ManageWork.cs
7.7 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Text;
using Model;
namespace BLL
{
public static class ManageWork
{
public static LineWork line;
public static ElevatorWork elevator;
public static bool PauseFull;
public static string frontLine;
public static void Init()
{
frontLine = "";
PauseFull = false;
line = new LineWork();
elevator = new ElevatorWork();
}
public static void Start()
{
line.Open();
elevator.Open();
}
public static void Stop()
{
line.Close();
elevator.Close();
}
/// <summary>
/// 获取产线或电梯任务
/// </summary>
/// <returns></returns>
public static IJob GetJob()
{
IJob job = elevator.GetJob();
if (job == null)
job = line.GetJob();
return job;
}
/// <summary>
/// 查找产线呼叫
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
/// <returns></returns>
public static bool FindLineWork(out string key, out string name)
{
//按时间的先后顺序
int index = -1;
DateTime dt = DateTime.Now;
for (int i = 0; i < Common.lineInfos.Count; i++)
{
if (Common.lineInfos[i].LineCall && Common.lineInfos[i].ShelfExist)
{
if (dt > Common.lineInfos[i].FinalDate)
{
dt = Common.lineInfos[i].FinalDate;
index = i;
}
}
}
//int index = Common.lineInfos.FindIndex(s => s.Call && s.Exist);
if (index == -1)
{
key = "";
name = "";
return false;
}
else
{
key = Common.lineInfos[index].Key;
name = Common.lineInfos[index].Name;
return true;
}
}
/// <summary>
/// 查找电梯回收呼叫
/// </summary>
/// <returns></returns>
public static bool FindElevatorWork()
{
return elevator.GetRecycle();
}
/// <summary>
/// 查找不带货架的产线
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
/// <returns></returns>
public static bool FindLineWithoutShelf(out string key, out string name)
{
int index;
int startIndex = Common.lineInfos.FindIndex(s => s.Key == frontLine);
if (startIndex == -1) //没有关键字
{
index = Common.lineInfos.FindIndex(s => s.ShelfExist == false);
}
else if (startIndex == Common.lineInfos.Count - 1) //最后一行
{
index = Common.lineInfos.FindIndex(s => s.ShelfExist == false);
}
else
{
index = Common.lineInfos.FindIndex(++startIndex, s => s.ShelfExist == false);
if (index == -1) //从头开始
index = Common.lineInfos.FindIndex(s => s.ShelfExist == false);
}
if (index == -1)
{
key = "";
name = "";
frontLine = "";
return false;
}
else
{
key = Common.lineInfos[index].Key;
name = Common.lineInfos[index].Name;
frontLine = key;
return true;
}
//int index = Common.lineInfos.FindIndex(s => s.Exist == false);
//if (index == -1)
//{
// key = "";
// name = "";
// return false;
//}
//else
//{
// key = Common.lineInfos[index].Key;
// name = Common.lineInfos[index].Name;
// return true;
//}
}
/// <summary>
/// 小车从产线取走货架
/// </summary>
/// <param name="key"></param>
public static void LineTakeAway(string key)
{
line.TakeAway(key);
}
/// <summary>
/// 小车拉取货架送到产线
/// </summary>
/// <param name="key"></param>
public static void LineSendTo(string key)
{
line.SendTo(key);
}
/// <summary>
/// 发送电梯使用请求
/// </summary>
public static void SendElevatorUseAsk()
{
elevator.UseAsk();
}
/// <summary>
/// 电梯使用应答
/// </summary>
/// <returns></returns>
public static bool ElevatorUseAnswer()
{
return elevator.UseAnswer();
}
/// <summary>
/// 电梯呼叫
/// </summary>
/// <param name="sta"></param>
public static void ElevatorCall(bool sta)
{
elevator.CallElevator(sta);
}
/// <summary>
/// 电梯已准备好(到达4楼并开门)
/// </summary>
/// <returns></returns>
public static bool ElevatorReady()
{
bool rtn1 = elevator.ArriveFloor();
bool rtn2 = elevator.OpenDoor();
return rtn1 && rtn2;
}
/// <summary>
/// 电梯送满架子
/// </summary>
public static void ElevatorFullShelf()
{
elevator.FullShelfLeave();
}
/// <summary>
/// 电梯回收空架子
/// </summary>
public static void ElevatorEmptyShelf()
{
elevator.EmptyShelfLeave();
}
/// <summary>
/// 电梯任务结束,可以离开
/// </summary>
public static void ElevatorEnd()
{
elevator.EndTask();
}
public static void FirstFloorAdd()
{
Common.FirstFloorCurr++;
if (Common.FirstFloorCurr > Common.FirstFloorCount)
Common.FirstFloorCurr = Common.FirstFloorCount;
System.IO.File.WriteAllText(Common.PATH_FIRST_FLOOR_CURR, Common.FirstFloorCurr.ToString(), Encoding.UTF8);
}
public static void FirstFloorMinus()
{
Common.FirstFloorCurr--;
if (Common.FirstFloorCurr < 0)
Common.FirstFloorCurr = 0;
System.IO.File.WriteAllText(Common.PATH_FIRST_FLOOR_CURR, Common.FirstFloorCurr.ToString(), Encoding.UTF8);
}
public static void FirstFloorSave()
{
if (Common.FirstFloorCurr < 0)
Common.FirstFloorCurr = 0;
else if (Common.FirstFloorCurr > Common.FirstFloorCount)
Common.FirstFloorCurr = Common.FirstFloorCount;
System.IO.File.WriteAllText(Common.PATH_FIRST_FLOOR_CURR, Common.FirstFloorCurr.ToString(), Encoding.UTF8);
}
/// <summary>
/// 回收空货架错误处理
/// </summary>
public static void EmptyErrorDispose()
{
elevator.EmptyShelfLeave();
System.Threading.Thread.Sleep(3000);
elevator.EndTask();
FirstFloorMinus();
}
/// <summary>
/// 送满货架错误处理
/// </summary>
public static void FullErrorDispose()
{
elevator.FullShelfLeave();
System.Threading.Thread.Sleep(3000);
elevator.EndTask();
FirstFloorAdd();
}
}
}