SteelManage.cs
23.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
using System;
using Model;
using System.Collections.Generic;
namespace BLL
{
public static class SteelManage
{
private static List<SteelWork> oldSteelWork = new List<SteelWork>();
private static List<SteelWork> newSteelWork = new List<SteelWork>();
private static List<SteelWork> storageWork = new List<SteelWork>();
#region OldSteelWork
public static void OldSteelWorkAdd(string place)
{
place = place.ToUpper();
int index = oldSteelWork.FindIndex(sw => sw.Place == place);
if (index == -1)
{
SteelWork sw = new SteelWork() { Place = place };
oldSteelWork.Add(sw);
SaveOldSteelWork();
Common.log.Info("添加(" + place + ")回收钢板任务");
}
else
{
Common.log.Info("重复(" + place + ")回收钢板任务,已忽略");
}
}
public static void OldSteelWorkDel(string place)
{
int index = oldSteelWork.FindIndex(sw => sw.Place == place);
if (index > -1)
{
oldSteelWork.RemoveAt(index);
SaveOldSteelWork();
Common.log.Info("删除(" + place + ")回收钢板任务");
}
else
{
Common.log.Info("没有找到(" + place + ")回收钢板任务");
}
}
public static void OldSteelWorkDelTimeout()
{
if (!Common.WorkTimeoutDel) return;
int index = 0;
bool remove = false;
while (index < oldSteelWork.Count)
{
TimeSpan span = DateTime.Now - oldSteelWork[index].DateTime;
if (span.TotalMinutes >= Common.WorkTimeout)
{
oldSteelWork.RemoveAt(index);
remove = true;
}
else
{
index++;
}
}
if (remove)
{
SaveOldSteelWork();
Common.log.Info("删除超时" + Common.WorkTimeout + "分钟之前的所有回收钢板任务");
}
}
public static void OldSteelWorkDelAll(string workshop)
{
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == workshop);
if (lineIdx == -1) return;
int index = 0;
while (index < oldSteelWork.Count)
{
int idx = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == oldSteelWork[index].Place);
if (idx > -1)
oldSteelWork.RemoveAt(index);
else
index++;
}
SaveOldSteelWork();
Common.log.Info("删除" + workshop + "所有回收钢板任务");
}
public static void OldSteelWorkDelAll()
{
oldSteelWork.Clear();
SaveOldSteelWork();
Common.log.Info("删除所有回收钢板任务");
}
public static 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.lstOldSteel != null)
{
Common.lstOldSteel.Items.Clear();
Common.lstOldSteel.Items.AddRange(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.Info("加载回收钢板任务");
}
public static bool FindOldSteelWork(AgvInfo info, out string place)
{
place = "";
bool find = false;
string name = "";
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
//回收时不去前面的产线
int placeIdx = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == info.Place);
if (placeIdx == -1) placeIdx = 0;
for (int i = placeIdx; i < Common.agvLines[lineIdx].Lines.Length; i++)
{
name = Common.agvLines[lineIdx].Lines[i];
int idx = oldSteelWork.FindIndex(s => s.Place == name);
if (idx > -1)
{
find = true;
break;
}
}
place = name;
return find;
}
#endregion
#region NewSteelWork
public static void NewSteelWorkAdd(string from, string place)
{
from = from.ToUpper();
place = place.ToUpper();
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);
SaveNewSteelWork();
Common.log.Info("添加(" + from + "," + place + ")送新钢板任务");
}
else
{
Common.log.Info("重复(" + place + ")送新钢板任务,已忽略");
}
}
public static void NewSteelWorkAdd(string from, string[] place)
{
from = from.ToUpper();
for (int i = 0; i < place.Length; i++)
{
place[i] = place[i].ToUpper();
int index = newSteelWork.FindIndex(sw => sw.From == from && sw.Place == place[i]);
if (index == -1)
{
SteelWork sw = new SteelWork() { From = from, Place = place[i] };
newSteelWork.Add(sw);
Common.log.Info("添加(" + from + "," + place[i] + ")送新钢板任务");
}
else
{
Common.log.Info("重复(" + place[i] + ")送新钢板任务,已忽略");
}
SaveNewSteelWork();
}
}
public static void NewSteelWorkDel(string from, string place)
{
int index = newSteelWork.FindIndex(sw => sw.From == from && sw.Place == place);
if (index > -1)
{
newSteelWork.RemoveAt(index);
SaveNewSteelWork();
Common.log.Info("删除(" + from + "," + place + ")送新钢板任务");
}
else
{
List<string> str = new List<string>();
for (int i = 0; i < newSteelWork.Count; i++)
str.Add(string.Format("Idx={0},From={1},Place={2}", i, newSteelWork[i].From, newSteelWork[i].Place));
Common.log.Debug("NewSteelWorkDel " + string.Join("; ", str));
Common.log.Info("没有找到(" + from + "," + place + ")送新钢板任务");
}
}
public static void NewSteelWorkDelAll(string workshop)
{
int index = 0;
while (index < newSteelWork.Count)
{
int idx = newSteelWork.FindIndex(sw => sw.From == workshop + "WASH");
if (idx > -1)
newSteelWork.RemoveAt(index);
else
index++;
}
SaveNewSteelWork();
Common.log.Info("删除" + workshop + "wash所有送新钢板任务");
}
public static void NewSteelWorkDelAll()
{
newSteelWork.Clear();
SaveNewSteelWork();
Common.log.Info("删除所有送新钢板任务");
}
public static 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.lstNewSteel != null)
{
Common.lstNewSteel.Items.Clear();
Common.lstNewSteel.Items.AddRange(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.Info("加载送新钢板任务");
}
public static bool FindNewSteelWork(AgvInfo info, out string place)
{
place = "";
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
if (newSteelWork.Count == 0) return false;
bool find = false;
for (int i = 0; i < Common.agvLines[lineIdx].Lines.Length; i++)
{
int index = newSteelWork.FindIndex(s => s.From == info.From && s.Place == Common.agvLines[lineIdx].Lines[i]);
if (index > -1)
{
place = newSteelWork[index].Place;
find = true;
break;
}
}
//for (int i = 0; i < newSteelWork.Count; i++)
//{
// if (newSteelWork[i].From == info.Workshop + "WASH")
// {
// if (newSteelWork[i].Place == "STORAGE")
// {
// place = newSteelWork[i].Place;
// info.From = newSteelWork[i].From;
// find = true;
// break;
// }
// else
// {
// int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == newSteelWork[i].Place);
// if (index > -1)
// {
// place = newSteelWork[i].Place;
// info.From = newSteelWork[i].From;
// find = true;
// break;
// }
// }
// }
//}
return find;
}
#endregion
#region StorageWork
public static void StorageWorkAdd(string place)
{
place = place.ToUpper();
int index = storageWork.FindIndex(sw => sw.Place == place);
if (index == -1)
{
SteelWork sw = new SteelWork() { Place = place };
storageWork.Add(sw);
SaveStorageWork();
Common.log.Info("添加(" + place + ")仓库钢板任务");
}
else
{
Common.log.Info("重复(" + place + ")仓库钢板任务,已忽略");
}
}
public static void StorageWorkDel(string place)
{
int index = storageWork.FindIndex(sw => sw.Place == place);
if (index > -1)
{
storageWork.RemoveAt(index);
SaveStorageWork();
Common.log.Info("删除(" + place + ")仓库钢板任务");
}
else
{
Common.log.Info("没有找到(" + place + ")仓库钢板任务");
}
}
public static void StorageWorkDelAll(string workshop)
{
//int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == workshop);
//if (lineIdx == -1) return;
//int index = 0;
//while (index < storageWork.Count)
//{
// int idx = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == storageWork[index].Place);
// if (idx > -1)
// storageWork.RemoveAt(index);
// else
// index++;
//}
int index = storageWork.FindIndex(sw => sw.Place == workshop + "_ENTER");
if (index > -1) storageWork.RemoveAt(index);
SaveStorageWork();
Common.log.Info("删除" + workshop + "仓库钢板任务");
}
public static void StorageWorkDelAll()
{
storageWork.Clear();
SaveStorageWork();
Common.log.Info("删除所有仓库钢板任务");
}
public static void StorageWorkLoad()
{
storageWork = new List<SteelWork>();
if (!System.IO.File.Exists(Common.PATH_STORAGE_WORK)) return;
string[] lines = System.IO.File.ReadAllLines(Common.PATH_STORAGE_WORK, System.Text.Encoding.UTF8);
if (Common.lstStorage != null)
{
Common.lstStorage.Items.Clear();
Common.lstStorage.Items.AddRange(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]) };
storageWork.Add(sw);
}
Common.log.Info("加载仓库钢板任务");
}
public static bool FindStorageWork(AgvInfo info, out string place)
{
place = "";
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
if (newSteelWork.Count == 0) return false;
bool find = false;
for (int i = 0; i < Common.agvLines[lineIdx].Lines.Length; i++)
{
int index = newSteelWork.FindIndex(s => s.From == info.From && s.Place == Common.agvLines[lineIdx].Lines[i]);
if (index > -1)
{
place = newSteelWork[index].Place;
find = true;
break;
}
}
//for (int i = 0; i < newSteelWork.Count; i++)
//{
// if (newSteelWork[i].From == "STORAGE")
// {
// int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == newSteelWork[i].Place);
// if (index > -1)
// {
// place = newSteelWork[i].Place;
// find = true;
// break;
// }
// }
//}
return find;
}
public static bool FindStorageWork(AgvInfo info)
{
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
bool find = false;
for (int i = 0; i < newSteelWork.Count; i++)
{
if (newSteelWork[i].From == "STORAGE")
{
int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == newSteelWork[i].Place);
if (index > -1)
{
find = true;
break;
}
}
}
return find;
}
public static bool FindStorageWorkLeave()
{
int index = storageWork.FindIndex(s => s.Place == Common.STORAGE_LEAVE);
if (index > -1)
return true;
else
return false;
}
public static void StorageWorkDelLeave()
{
int index = storageWork.FindIndex(s => s.Place == Common.STORAGE_LEAVE);
if (index > -1)
{
storageWork.RemoveAt(index);
SaveStorageWork();
Common.log.Debug("删除仓库离开架子任务");
}
}
#endregion
public static IJob GetSteelJob(AgvInfo info)
{
if (info.Battery < info.BatteryMin)
return null;
bool rtn;
#region 清洗点呼叫
rtn = GetWashCall(info);
if (rtn)
{
Common.log.Info(string.Format("{0} 清洗点呼叫{1}小车", info.Name, info.Workshop));
return new WashPointJob();
}
else
{
Common.log.Debug(info.Name + " 没有找到" + info.Workshop + "清洗点呼叫");
}
#endregion
#region 仓库入架子出钢板
rtn = GetStorageCall(info);
if (rtn)
{
Common.log.Info(string.Format("{0} 仓库呼叫{1}小车", info.Name, info.Workshop));
return new StorageJob();
}
else
{
Common.log.Debug(info.Name + " 没有找到仓库呼叫");
}
#endregion
#region 回收钢板
rtn = GetOldSteelCall(info);
if (rtn)
{
Common.log.Info(info.Name + " " + info.Workshop + "回收钢板");
return new TakeOldJob();
}
else
{
Common.log.Debug(info.Name + " 没有找到" + info.Workshop + "回收钢板任务");
}
#endregion
return null;
}
public static IJob GetNewSteelJob(AgvInfo info)
{
bool rtn = GetNewSteel(info);
if (rtn)
{
Common.log.Info(info.Name + " " + info.Workshop + "送新钢板呼叫");
return new SendNewJob();
}
else
{
Common.log.Debug(info.Name + " 没有找到" + info.Workshop + "送新钢板呼叫");
return null;
}
}
private static bool GetWashCall(AgvInfo info)
{
bool find = false;
string name = info.Workshop + "WASH";
for (int i = 0; i < newSteelWork.Count; i++)
{
if (newSteelWork[i].From == newSteelWork[i].Place && newSteelWork[i].From == name)
{
find = true;
break;
}
}
//int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
//if (lineIdx == -1) return false;
//bool find = false;
//for (int i = 0; i < newSteelWork.Count; i++)
//{
// if (newSteelWork[i].From == newSteelWork[i].Place)
// {
// int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == newSteelWork[i].Place);
// if (index > -1)
// {
// find = true;
// break;
// }
// }
//}
return find;
}
private static bool GetOldSteelCall(AgvInfo info)
{
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
bool find = false;
for (int i = 0; i < oldSteelWork.Count; i++)
{
int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == oldSteelWork[i].Place);
if (index > -1)
{
find = true;
break;
}
}
return find;
}
private static bool GetNewSteel(AgvInfo info)
{
int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
if (lineIdx == -1) return false;
bool find = false;
for (int i = 0; i < Common.agvLines[lineIdx].Lines.Length; i++)
{
int index = newSteelWork.FindIndex(s => s.From == info.From && s.Place == Common.agvLines[lineIdx].Lines[i]);
if (index > -1)
{
find = true;
break;
}
}
//for (int i = 0; i < newSteelWork.Count; i++)
//{
// if (newSteelWork[i].From == info.From)
// {
// if (newSteelWork[i].Place.ToUpper() == "STORAGE")
// {
// find = true;
// break;
// }
// else
// {
// int index = Array.FindIndex(Common.agvLines[lineIdx].Lines, s => s == newSteelWork[i].Place);
// if (index > -1)
// {
// find = true;
// break;
// }
// }
// }
//}
return find;
}
private static bool GetStorageCall(AgvInfo info)
{
//int lineIdx = Common.agvLines.FindIndex(s => s.Workshop == info.Workshop);
//if (lineIdx == -1) return false;
bool find = false;
for (int i = 0; i < storageWork.Count; i++)
{
if (storageWork[i].Place == info.Workshop + "_ENTER")
{
find = true;
break;
}
}
return find;
}
private static void SaveOldSteelWork()
{
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.lstOldSteel != null)
{
Common.lstOldSteel.Invoke(new Action(() =>
{
Common.lstOldSteel.Items.Clear();
Common.lstOldSteel.Items.AddRange(content);
}));
}
System.IO.File.WriteAllLines(Common.PATH_OLD_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
private static void SaveNewSteelWork()
{
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.lstNewSteel != null)
{
Common.lstNewSteel.Invoke(new Action(() =>
{
Common.lstNewSteel.Items.Clear();
Common.lstNewSteel.Items.AddRange(content);
}));
}
System.IO.File.WriteAllLines(Common.PATH_NEW_STEEL_WORK, content, System.Text.Encoding.UTF8);
}
private static void SaveStorageWork()
{
string[] content = new string[storageWork.Count];
for (int i = 0; i < content.Length; i++)
content[i] = storageWork[i].Place + "," + storageWork[i].DateTime.ToString();
if (Common.lstStorage != null)
{
Common.lstStorage.Invoke(new Action(() =>
{
Common.lstStorage.Items.Clear();
Common.lstStorage.Items.AddRange(content);
}));
}
System.IO.File.WriteAllLines(Common.PATH_STORAGE_WORK, content, System.Text.Encoding.UTF8);
}
}
}