UpdateManage.cs
37.2 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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
using XingYe_ACS.BaseStruct;
using XingYe_ACS.Common;
using XingYe_ACS.WebApi;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XingYe_ACS.Business
{
public class UpdateManage
{
/// <summary>
/// 更新AGV信息
/// </summary>
/// <param name="clientMsg">小车客户端信息</param>
/// <returns></returns>
public static bool UpdateClientMsg(ClientMsg clientMsg)
{
try
{
string sqlUpdate = "";
Agv agv = clientMsg.msgAgv;
agv.strBarcode = clientMsg.strBarcode;
agv.agvMap = App.PointList.Find(a => a.strBarcode == agv.strBarcode).AreaType.ToString();
agv.agvState = (EnumMsg.State)clientMsg.intState;
agv.heightState = (EnumMsg.HeightState)clientMsg.intHeightState;
agv.currentCharge = clientMsg.intVoltage;
agv.agvHeart = DateTime.Now;
agv.strAgvError = ComnMethod.GetAgvError(clientMsg.ErrorList);
if (agv.heightState == EnumMsg.HeightState.中位 && agv.agvTask != null
&& agv.agvTask.sonTaskList[0].sonTaskType == EnumMsg.AgvTaskType.行走) agv.strAgvError += "agv处于中位异常";
if (agv.agvState == EnumMsg.State.自动无码) agv.strAgvError += "agv未读到二维码";
if (agv.agvTask != null && agv.strStopReason.Contains("行走任务需载货")) { agv.strAgvError += "agv行走任务需载货架,小车状态必须是高位;"; }
agv.agvErrorCode = clientMsg.ErrorList[0];
agv.agvOri = clientMsg.agvDirection;
agv.dialOri = clientMsg.dialDirection;
agv.intRunDistance = clientMsg.intRunDistance;
agv.isCarry = clientMsg.isCarry == 0 ? false : true;
#region 注释
agv.nextPoint = "";
agv.beforePoint = "";
if (agv.agvTask != null && agv.agvTask.sonTaskList.Count != 0 && agv.agvTask.sonTaskList[0].pathPointList.Count != 0)
{
Point oldPoint = App.PointList.FirstOrDefault(a => a.strBarcode == agv.strBarcode);
string xuniBarcode = "";
//当前点所在路径点
PathPoint pathPoints = agv.agvTask.sonTaskList[0].pathPointList.FirstOrDefault(a => a.point.strBarcode == agv.strBarcode);
PathPoint nextPoint = null;
if (pathPoints != null)
{
PathPoint beforePathPoint = agv.agvTask.sonTaskList[0].pathPointList.FirstOrDefault(a => a.intSerialNo == pathPoints.intSerialNo - 1);
//下个路径点
nextPoint = ComnMethod.GetNextPathPoint(agv, pathPoints);
if (nextPoint != null)
{
if (nextPoint.point.pointType == EnumMsg.PointType.虚拟点 && !nextPoint.isCorner)
{
//虚拟点下个路径点
xuniBarcode = nextPoint.point.strBarcode;
nextPoint = ComnMethod.GetNextPathPoint(agv, nextPoint);
}
agv.nextPoint = nextPoint.point.strBarcode;
agv.pointLength = ComnMethod.GetDistance(agv.strBarcode, nextPoint.point.strBarcode, xuniBarcode);
}
if (beforePathPoint != null)
{
agv.beforePoint = beforePathPoint.point.strBarcode;
}
}
}
#endregion
//20181030将有异常小车插入异常小车表中
if (agv.strAgvError != "")
{
if (!App.errAgv.Contains(agv.strAgvNo) && !agv.strAgvError.Contains("agv"))
{
if (agv.strAgvError.Contains("充电") && agv.currentCharge > 30)
{
App.ExFile.MessageLog("CheckAgvState" + agv.strAgvNo, "获取电梯内AGV出错误!");
}
else
{
SqlErrAgv(agv, "insert");
}
App.errAgv.Add(agv.strAgvNo);
}
}
else
{
DataSet ds = DbHelperSQL.Query("SELECT strAgvNo FROM T_Base_Agv WHERE ErrorTime IS NOT NULL AND strAgvError='' AND strAgvNo='" + agv.strAgvNo + "'");
if (ds.Tables[0].Rows.Count > 0) SqlErrAgv(agv, "update");
if (App.errAgv.Contains(agv.strAgvNo))
{
App.errAgv.Remove(agv.strAgvNo);
}
}
AcsPushBuild.PushAgv(agv);
sqlUpdate = string.Format(@"UPDATE T_Base_AGV SET strBarcode = '{1}',agvState = '{2}',heightState = '{3}',currentCharge = '{4}',agvHeart = '{5}' ,strAgvError = '{6}',agvmap = '{7}',offAct = '{8}'
WHERE strAgvNo = '{0}';", clientMsg.strAddress, clientMsg.strBarcode, clientMsg.intState, clientMsg.intHeightState, clientMsg.intVoltage, DateTime.Now.ToString()
, ComnMethod.GetAgvError(clientMsg.ErrorList), agv.agvMap, clientMsg.isCarry);
DbHelperSQL.ExecuteSql(sqlUpdate);
return true;
}
catch (Exception Ex)
{
throw new Exception("UpdateClientMsg:" + Ex.Message.Replace(Environment.NewLine, ""+clientMsg.msgAgv.strAgvNo));
}
}
/// <summary>
/// 更新点信息
/// </summary>
/// <param name="clientMsg">小车客户端信息</param>
/// <returns></returns>
public static bool SqlPointMsg(Point point,string type)
{
try
{
string sql = "";
if (type == "insert")
{
sql = string.Format(@"INSERT INTO T_Base_Point(pointAreaType,strBarcode,intX,intY,isXpos,isXNeg,isYPos,isYNeg,isEnable,pointType,XPosLength,XNegLength,YPosLength,YNegLength,isOccupy,strOccupyAgvNo,oriAgv,oriDial,strRegionName,isRegionApply,strRegionApplyAgvNo,stopTime,isStop,intStopLevel)VALUES
('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','0','',0,0,'{14}','0','','{15}','{16}','{17}');"
, point.AreaType, point.strBarcode, point.intX / 30 + 1, point.intY / 30 + 1, point.isXPos == false ? "0" : "1", point.isXNeg == false ? "0" : "1", point.isYPos == false ? "0" : "1", point.isYNeg == false ? "0" : "1", "1", (int)point.pointType, point.XPosLength, point.XNegLength, point.YPosLength, point.YNegLength, point.strRegionName, point.stopTime,point.isStop == false ? "0" : "1", point.intStopLevel);
}
else
{
string querySql = string.Format("SELECT * FROM T_Base_Point WHERE pointAreaType = '{0}';", point.AreaType);
DataSet ds = DbHelperSQL.Query(querySql);
if (ds.Tables[0].Rows.Count < 1) return true;
// AND pointType = 1
sql = string.Format(@"DELETE FROM T_Base_Point WHERE pointAreaType = '{0}';", point.AreaType);
sql += string.Format(@"DELETE FROM T_Base_Station WHERE stationArea = '{0}' AND stationType <> 8;", point.AreaType);
//sql += string.Format(@"DELETE FROM T_Config_Point WHERE AreaType = '{0}';", point.AreaType);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("SqlPointMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 更新Demo点信息
/// </summary>
/// <param name="point"></param>
/// <param name="type"></param>
/// <returns></returns>
public static bool SqlDemoPointMsg(Point point, string type)
{
try
{
string sql = "";
if (type == "simInsert")
{
sql = string.Format(@"INSERT INTO T_Base_DemoPoint(pointAreaType,strBarcode,intX,intY,isXpos,isXNeg,isYPos,isYNeg,isEnable,pointType,XPosLength,XNegLength,YPosLength,YNegLength,isOccupy,strOccupyAgvNo,oriAgv,oriDial,strRegionName,isRegionApply,strRegionApplyAgvNo)VALUES
('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','0','',0,0,'{14}','0','');"
, point.AreaType, point.strBarcode, point.intX / 30 + 1, point.intY / 30 + 1, point.isXPos == false ? "0" : "1", point.isXNeg == false ? "0" : "1", point.isYPos == false ? "0" : "1", point.isYNeg == false ? "0" : "1", "1", (int)point.pointType, point.XPosLength, point.XNegLength, point.YPosLength, point.YNegLength, point.strRegionName);
}
else
{
string querySql = string.Format("SELECT * FROM T_Base_DemoPoint WHERE pointAreaType = '{0}';", point.AreaType);
DataSet ds = DbHelperSQL.Query(querySql);
if (ds.Tables[0].Rows.Count < 1) return true;
sql = string.Format(@"DELETE FROM T_Base_DemoPoint WHERE pointAreaType = '{0}';", point.AreaType);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("SqlDemoPointMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 更新小车信息
/// </summary>
/// <param name="clientMsg">小车客户端信息</param>
/// <returns></returns>
public static bool UpdateAgvMsg(Agv agv)
{
try
{
string sqlUpdate = string.Format(@"UPDATE T_Base_Agv SET strBarcode = '{1}',isEnable = '{2}',strChooseStation = '{3}',agvMilage='{4}'
,agvAreaType='{5}',agvGroup='{6}',startCharges='{7}',agvState='{8}',agvmap='{9}'
WHERE strAgvNo = '{0}';"
, agv.strAgvNo, agv.strBarcode, agv.isEnable == false ? "0" : "1", agv.strChooseStation, agv.agvMilage, agv.agvAreaType, agv.agvGroup, agv.startCharges, (int)agv.agvState, agv.agvMap);
int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
if (intSqlResult < 1) return false;
return true;
}
catch (Exception Ex)
{
throw new Exception("UpdateAgvMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 更新主任务信息
/// </summary>
/// <param name="task">主任务信息</param>
/// <returns></returns>
public static bool UpdateFTask(FTask task)
{
try
{
string sqlUpdate = string.Format(@"UPDATE T_Task SET strTaskNo = '{1}' ,strTaskID = '{2}' ,strTaskGroup = '{3}' ,intTaskLevel = '{4}'
,strInitial = '{5}' ,strTarget = '{6}' ,startPoint = '{7}' ,endPoint = '{8}' ,strAcceptTime = '{9}' ,isTaskSubmit = '{10}' ,strTaskAgv = '{11}'
,strBeginTime = '{12}' ,strEndTime = '{13}', direction = '{14}',strTaskState = '{15}' WHERE strTaskNo = '{0}';"
, task.strTaskNo, task.strTaskNo, task.strTaskID, task.strTaskGroup, task.intTaskLevel
, task.strInitial, task.strTarget, task.startPoint.strBarcode, task.endPoint.strBarcode, task.strAcceptTime, task.isTaskSubmit == false ? "0" : "1", task.strTaskAgv
, task.strBeginTime == "" ? "null" : task.strBeginTime, task.strEndTime == "" ? "null" : task.strEndTime, (int)task.direction, task.taskState);
if (task.strEndTime != "")
{
sqlUpdate += string.Format("DELETE FROM T_Task WHERE strTaskNo = '{0}';", task.strTaskNo);
}
bool isSqleResult = false;
while (true)
{
isSqleResult = DbHelperSQL.SqlTransOperator(sqlUpdate);
if (isSqleResult) break;
}
return true;
}
catch (Exception Ex)
{
throw new Exception("UpdateFTask:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 更新子任务信息
/// </summary>
/// <param name="clientMsg">小车客户端信息</param>
/// <returns></returns>
public static bool UpdateSonTask(SonTask sonTask)
{
try
{
string sqlUpdate = "";
int flag = 0;
if (sonTask.sonTaskState == EnumMsg.SonTaskState.已完成)
{
sqlUpdate += string.Format("DELETE FROM T_Base_PathPoint WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo);
sqlUpdate += string.Format("DELETE FROM T_SonTask WHERE intSonTaskNo = '{0}'AND strTaskNo='{1}';", sonTask.intSonTaskNo, sonTask.strTaskNo);
flag = 99;
}
else
{
sqlUpdate += string.Format(@"UPDATE T_SonTask SET intSonTaskNo = '{1}' ,strTaskNo = '{2}' ,sonTaskType = '{3}' ,startPoint = '{4}' ,endPoint = '{5}'
,isCarry = '{6}' ,taskRequestType = '{7}' ,dialDirection = '{8}' ,agvDirection = '{9}' ,sonTaskState = '{10}'
,strBeginTime = '{11}' ,strEndTime = '{12}' WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo
, sonTask.intSonTaskNo, sonTask.strTaskNo, (int)sonTask.sonTaskType, sonTask.startPoint.strBarcode, sonTask.endPoint.strBarcode
, sonTask.isCarry == false ? "0" : "1", (int)sonTask.taskRequestType, (int)sonTask.dialDirection, (int)sonTask.agvDirection, (int)sonTask.sonTaskState
, sonTask.strBeginTime == "" ? "null" : sonTask.strBeginTime, sonTask.strEndTime == "" ? "null" : sonTask.strEndTime);
}
if (flag == 99)
{
bool isSqleResult = false;
while (true)
{
isSqleResult = DbHelperSQL.SqlTransOperator(sqlUpdate);
if (isSqleResult) break;
}
}
else
{
DbHelperSQL.ExecuteSql(sqlUpdate);
}
return true;
}
catch (Exception Ex)
{
throw new Exception("UpdateSonTask:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 更新站台信息
/// </summary>
/// <param name="station"></param>
/// <returns></returns>
public static bool UpdateStation(Station station)
{
try
{
string sqlUpdate = string.Format("UPDATE T_Base_Station SET isEnable = '{1}', isLocked = '{2}',stationState = '{3}' WHERE strStationNo = '{0}';", station.strStationNo, station.isEnable == false ? "0" : "1", station.isLocked == false ? "0" : "1", (int)station.stationState);
int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
if (intSqlResult < 1) return false;
return true;
}
catch (Exception Ex)
{
throw new Exception("UpdateStation:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 解除小车不应该lock的点
/// </summary>
/// <param name="lockedPoint">待lock的点</param>
/// <param name="agv"></param>
public static void relieveLocked(List<Point> lockedPoint, Agv agv)
{
try
{
List<Point> lockedList = App.PointList.Where(a => a.lockedAgv == agv).ToList();
foreach (Point point in lockedList)
{
if (lockedPoint.Contains(point)) continue;
point.lockedAgv = null;
}
}
catch (Exception Ex)
{
throw new Exception("relieveLocked:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 重建路径
/// 删除路径,更新子任务状态
/// </summary>
/// <param name="sonTask"></param>
public static void ResetPath(SonTask sonTask)
{
try
{
if (sonTask.sonTaskType != EnumMsg.AgvTaskType.行走) return;
string sqlDelete = string.Format(@"DELETE FROM T_Base_PathPoint WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo);
string sqlUpdate = string.Format(@"UPDATE T_SonTask SET sonTaskState = 5 WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo);
bool isSqlResult = DbHelperSQL.SqlTransOperator(sqlDelete + sqlUpdate);
if (isSqlResult)
{
sonTask.pathPointList.Clear();
sonTask.sonTaskState = EnumMsg.SonTaskState.重建路径中;
}
}
catch (Exception Ex)
{
throw new Exception("ResetPath:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 将异常小车插入异常信息表和任务表中
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool SqlErrAgv(Agv agv, string type)
{
try
{
string sql = "";
if (type == "insert")
{
string taskNo = "";
if (agv.agvTask != null) taskNo = agv.agvTask.strTaskNo;
sql = string.Format(@"INSERT INTO T_Config_agvErrTable (strAgvNo , strBarcode , agvErrMessage , startErrTime , strTaskNo)
VALUES ('{0}','{1}','{2}','{3}','{4}');"
, agv.strAgvNo, agv.strBarcode, agv.strAgvError, agv.agvHeart.ToString(), taskNo);
sql += string.Format(@"UPDATE T_Base_Agv SET ErrorTime='{1}' WHERE strAgvNo='{0}';", agv.strAgvNo, agv.agvHeart.ToString());
if (agv.agvTask != null)
{
sql += string.Format(@"UPDATE T_Task SET agvErrorCode = '{1}',taskErrMsg = '{2}' WHERE strTaskNo = '{0}';", agv.agvTask.strTaskNo, agv.agvErrorCode, agv.strAgvError);
}
}
else
{
sql = string.Format(@"UPDATE T_Config_agvErrTable SET endErrTime='{1}' WHERE strAgvNo='{0}' AND endErrTime IS NULL;",
agv.strAgvNo, agv.agvHeart.ToString());
sql += string.Format(@"UPDATE T_Base_Agv SET ErrorTime = null WHERE strAgvNo='{0}';", agv.strAgvNo);
if (agv.agvTask != null)
{
sql += string.Format(@"UPDATE T_Task SET agvErrorCode = 0,taskErrMsg = null WHERE strTaskNo = '{0}';", agv.agvTask.strTaskNo);
}
}
bool isSqlResult = DbHelperSQL.SqlTransOperator(sql);
return isSqlResult;
}
catch (Exception Ex)
{
throw new Exception("SqlErrAgv:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 插入AGV状态变化
/// </summary>
/// <param name="agv"></param>
/// <param name="state"></param>
/// <returns></returns>
public static bool InsertAgvState(Agv agv,int state)
{
try
{
//获取最后一条的状态 SELECT
//更新上一条状态结束 UPDATE ACS_Wistron_MOVE. T_AgvState SET endTime='{1}' WHERE agvNo='{}' AND endTime IS NULL
//插入新一条状态开始 INSERT
string sqlInsert = string.Format(@"INSERT INTO T_AgvState (agvNo,agvState,startTime,endTime)VALUES('{0}','{1}','{2}','{3}');"
, agv.strAgvNo, state, DateTime.Now, "null");
int intSqlResult = DbHelperSQL.ExecuteSql(sqlInsert);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("InsertAgvState:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 插入AGV里程
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public static bool InsertAgvMilage(FTask task)
{
try
{
Agv agv = App.AgvList.FirstOrDefault(a => a.strAgvNo == task.strTaskAgv);
if (agv == null) return true;
string sqlInsert = string.Format(@"INSERT INTO T_Milage (strAgvNo, startpoint, endpoint, mileage, starttime, endtime, taskno, groupname)
VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"
, agv.strAgvNo, task.startPoint.strBarcode, task.endPoint.strBarcode, agv.agvMilage, task.strBeginTime==""?"null":task.strBeginTime, task.strEndTime, agv.agvTask.strTaskID, agv.agvTask.strTaskGroup);
string sqlUpdate = string.Format(@"UPDATE T_Base_Agv SET agvMilage='0'WHERE strAgvNo = '{0}';", agv.strAgvNo);
bool intSqlResult = DbHelperSQL.SqlTransOperator(sqlInsert + sqlUpdate);
if (!intSqlResult) return false;
}
catch (Exception Ex)
{
throw new Exception("InsertAgvMilage:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 插入充电记录
/// </summary>
/// <param name="task"></param>
public static void InsertAgvCharge(FTask task)
{
try
{
string sqlInsert = "";
Agv agv = App.AgvList.First(a => a.strAgvNo == task.strTaskAgv);
if (task.strTaskID == "充电")
{
sqlInsert = string.Format(@"INSERT INTO T_Base_AgvCharge(strAgvNo, startCharge, startTime, endCharge, endTime)
VALUES('{0}','{1}','{2}','0','null');"
, agv.strAgvNo, (int)agv.currentCharge, task.strEndTime);
}
else
{
sqlInsert = string.Format(@"UPDATE T_Base_AgvCharge SET endCharge = '{1}' ,endTime = '{2}'
WHERE strAgvNo='{0}' AND endCharge=0;"
, agv.strAgvNo, (int)agv.currentCharge, task.strBeginTime);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sqlInsert);
}
catch (Exception Ex)
{
throw new Exception("InsertAgvCharge:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
/// <summary>
/// 插入删除agv信息
/// </summary>
/// <param name="agv"></param>
/// <param name="type"></param>
/// <returns></returns>
public static bool SqlAgvMsg(Agv agv,string type)
{
try
{
string sql = "";
if (type == "insert")
{
sql = string.Format(@"INSERT INTO T_Base_Agv(strAgvNo,agvGroup,agvAreaType,strBarcode,agvState,heightState,currentCharge,strChooseStation,isEnable,agvHeart,agvMilage,strAgvError,agvmap,startCharges)VALUES
('{0}','{1}','{2}','0','0','0',0,'{3}','{4}','{5}',0,'','{6}',0);"
, agv.strAgvNo, agv.agvGroup,agv.agvAreaType, agv.strChooseStation, agv.isEnable == false ? "0" : "1", DateTime.Now,agv.agvMap);
}
else
{
sql = string.Format(@"DELETE FROM T_Base_Agv WHERE strAgvNo = '{0}';", agv.strAgvNo);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("InsertAgvMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 插入删除站点信息
/// </summary>
/// <param name="station">站点信息</param>
/// <param name="type">增删</param>
/// <returns></returns>
public static bool SqlStationMsg(Station station, string type)
{
try
{
string sql = "";
if (type == "insert")
{
sql = string.Format(@"INSERT INTO T_Base_Station(stationType,stationArea,isEnable,isLocked,strBarcode,strPreBarcode,strStationNo,stationOri,stationLength)VALUES
('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');"
, (int)station.stationType, station.stationArea, station.isEnable == false ? "0" : "1", station.isLocked == false ? "0" : "1", station.strBarcode, '0', station.strStationNo,(int)station.stationOri,station.stationLength);
}
else
{
sql = string.Format(@"DELETE FROM T_Base_Station WHERE stationArea = '{0}';", station.stationArea);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("SqlStationMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// AGV-任务群组绑定
/// </summary>
/// <param name="taskAgvGroup"></param>
/// <param name="type"></param>
/// <returns></returns>
public static bool SqlTaskAgvGroup(TaskAgvGroup taskAgvGroup, string type)
{
try
{
string sql = "";
if (type == "insert")
{
sql = string.Format(@"INSERT INTO T_Config_TaskAgvGroup (taskGroup ,agvGroup) VALUES ('{0}','{1}');", taskAgvGroup.taskGroup, taskAgvGroup.agvGroup);
}
else
{
sql = string.Format(@"DELETE FROM T_Config_TaskAgvGroup WHERE taskGroup = '{0}' AND agvGroup = '{1}';", taskAgvGroup.taskGroup, taskAgvGroup.agvGroup);
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("SqlTaskAgvGroup:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 测试记录AGV历史电量
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
//public static bool InsertAgvChargeLog(Agv agv)
//{
// try
// {
// //找到当前小车电量最后一次插入的时间
// //比对当前时间是否超过30秒
// //插入T_Charge_Log表中
// int intWaitTime = 0;
// string intSql = string.Format(@"SELECT TimeLog FROM T_Charge_Log WHERE AgvNo = '{0}' ORDER BY TimeLog DESC LIMIT 1;", agv.strAgvNo);
// DataSet ds = DbHelperSQL.Query(intSql);
// if (ds.Tables[0].Rows.Count != 0)
// {
// intWaitTime = ComnMethod.DiffTime(DateTime.Parse(ds.Tables[0].Rows[0].ItemArray[0].ToString()));
// }
// if (ds.Tables[0].Rows.Count == 0 || intWaitTime > 5)
// {
// string intSqlResult = string.Format(@"INSERT INTO T_Charge_Log (AgvNo,CurrentCharge,TimeLog)VALUES('{0}','{1}','{2}');"
// , agv.strAgvNo, agv.currentCharge, DateTime.Now);
// int i = DbHelperSQL.ExecuteSql(intSqlResult);
// }
// }
// catch (Exception Ex)
// {
// throw new Exception("InsertAgvChargeLog:" + Ex.Message.Replace(Environment.NewLine, ""));
// }
// return true;
//}
/// <summary>
/// 更新AGV的IP地址
/// </summary>
/// <returns></returns>
public static void UpdateAgvIP(Config_ClientControl clientControl)
{
DataSet ds = DbHelperSQL.Query("SELECT Ip FROM T_Base_Agv WHERE strAgvNo = '" + clientControl.strAgvNo + "';");
string agvIP = ds.Tables[0].Rows[0].ItemArray[0].ToString();
if (agvIP == "" || agvIP != clientControl.strClientIp)
{
string sqlUpdate = string.Format(@"UPDATE T_Base_Agv SET Ip = '{1}' WHERE strAgvNo = '{0}';", clientControl.strAgvNo, clientControl.strClientIp);
int intSqlResult = DbHelperSQL.ExecuteSql(sqlUpdate);
}
}
/// <summary>
/// 更新旋转点及其周围点
/// </summary>
/// <param name="point"></param>
/// <param name="type"></param>
/// <returns></returns>
public static bool SqlConfigPointMsg(List<Point> point)
{
try
{
string sql = "";
List<Point> points = new List<Point>();
Dictionary<string, List<Point>> keyValues = new Dictionary<string, List<Point>>();
foreach (Point turnPoint in point.FindAll(a => a.pointType == EnumMsg.PointType.整体旋转点 || a.pointType == EnumMsg.PointType.托盘旋转点))
{
List<Point> aroundPoints = new List<Point>();
if (turnPoint.xPosPoint != null) { aroundPoints.Add(turnPoint.xPosPoint); }
if (turnPoint.xNegPoint != null) { aroundPoints.Add(turnPoint.xNegPoint); }
if (turnPoint.yPosPoint != null) { aroundPoints.Add(turnPoint.yPosPoint); }
if (turnPoint.yNegPoint != null) { aroundPoints.Add(turnPoint.yNegPoint); }
Point rightUpPoint = App.PointList.Find(a => a.intX == turnPoint.intX + 3 && a.intY == turnPoint.intY + 3);
if (rightUpPoint != null && rightUpPoint.pointType == EnumMsg.PointType.整体旋转点)
{
if (keyValues.ContainsKey(rightUpPoint.strBarcode)) continue;
aroundPoints.Add(rightUpPoint);
}
Point rightDownPoint = App.PointList.Find(a => a.intX == turnPoint.intX + 3 && a.intY == turnPoint.intY - 3);
if (rightDownPoint != null && rightDownPoint.pointType == EnumMsg.PointType.整体旋转点)
{
if (keyValues.ContainsKey(rightDownPoint.strBarcode)) continue;
aroundPoints.Add(rightDownPoint);
}
Point leftUpPoint = App.PointList.Find(a => a.intX == turnPoint.intX - 3 && a.intY == turnPoint.intY + 3);
if (leftUpPoint != null && leftUpPoint.pointType == EnumMsg.PointType.整体旋转点)
{
if (keyValues.ContainsKey(leftUpPoint.strBarcode)) continue;
aroundPoints.Add(leftUpPoint);
}
Point leftDownPoint = App.PointList.Find(a => a.intX == turnPoint.intX - 3 && a.intY == turnPoint.intY - 3);
if (leftDownPoint != null && (leftDownPoint.pointType == EnumMsg.PointType.整体旋转点 || leftDownPoint.intXLength < 1000))
{
if (keyValues.ContainsKey(leftDownPoint.strBarcode)) continue;
aroundPoints.Add(leftDownPoint);
}
if (aroundPoints.Count < 4 && turnPoint.pointType == EnumMsg.PointType.整体旋转点) continue;
keyValues.Add(turnPoint.strBarcode, aroundPoints);
}
if (keyValues.Keys.Count == 0) return true;
for (int i = 0; i < keyValues.Keys.Count; i++)
{
int no = i + 1;
string turnBarcode = keyValues.ElementAt(i).Key;
Point turnPoint = App.PointList.First(a => a.strBarcode == turnBarcode);
//获取旋转点
sql += string.Format(@"INSERT INTO T_Config_Point (No, intX, intY, strBarcode, AreaType, strRegionName)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}');",
no, turnPoint.intX, turnPoint.intY, turnBarcode, turnPoint.AreaType, "");
for (int j = 0; j < keyValues.ElementAt(i).Value.Count; j++)
{
int num = keyValues.ElementAt(i).Value.Count;
//获取旋转周围附属点
Point aroundPoint = keyValues.ElementAt(i).Value.ElementAt(j);
sql += string.Format(@"INSERT INTO T_Config_Point (No, intX, intY, strBarcode, AreaType, strRegionName)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}');",
no, aroundPoint.intX, aroundPoint.intY, aroundPoint.strBarcode, aroundPoint.AreaType, "");
}
}
int intSqlResult = DbHelperSQL.ExecuteSql(sql);
if (intSqlResult < 1) return false;
}
catch (Exception Ex)
{
throw new Exception("SqlConfigPointMsg:" + Ex.Message.Replace(Environment.NewLine, ""));
}
return true;
}
/// <summary>
/// 更新提升机信息
/// </summary>
/// <param name="hoister"></param>
public static void UpdateHoister(Hoister hoister)
{
try
{
//string sqlUpdate = string.Format(@"UPDATE T_Base_Hoister SET hoisterTarget = '{1}' ,hoisterState = '{2}' ,hoisterError = '{3}'
// ,read_heart = '{4}' ,read_isGet = '{5}' ,read_isPutConfirm = '{6}' ,read_isAgvGetConfirm = '{7}' ,read_isPut = '{8}'
// ,read_isGetConfirm = '{9}' ,read_isAgvPutConfirm = '{10}' ,write_isGeting = '{11}' ,write_isGet = '{12}'
// ,write_isGetConfirm = '{13}' ,write_isHoisterPutConfirm = '{14}' ,write_isAgvGetConfirm = '{15}'
// ,write_isPut = '{16}' ,write_isPutConfirm = '{17}' ,write_isHoisterGetConfirm = '{18}' ,write_isAgvPutConfirm = '{19}'
// WHERE hoisterNo = '{0}';", hoister.hoisterNo, hoister.hoisterTarget, hoister.hoisterState, hoister.hoisterError, hoister.read_heart == false ? "0" : "1", hoister.read_isGet == false ? "0" : "1"
// , hoister.read_isPutConfirm == false ? "0" : "1", hoister.read_isAgvGetConfirm == false ? "0" : "1", hoister.read_isPut == false ? "0" : "1", hoister.read_isGetConfirm == false ? "0" : "1"
// , hoister.read_isAgvPutConfirm == false ? "0" : "1", hoister.write_isGeting == false ? "0" : "1", hoister.write_isGet == false ? "0" : "1", hoister.write_isGetConfirm == false ? "0" : "1", hoister.write_isHoisterPutConfirm == false ? "0" : "1"
// , hoister.write_isAgvGetConfirm == false ? "0" : "1", hoister.write_isPut == false ? "0" : "1", hoister.write_isPutConfirm == false ? "0" : "1", hoister.write_isHoisterGetConfirm == false ? "0" : "1", hoister.write_isAgvPutConfirm == false ? "0" : "1");
//DbHelperSQL.ExecuteSql(sqlUpdate);
}
catch (Exception Ex)
{
throw new Exception("UpdateHoister:" + Ex.StackTrace);
}
}
///<summary>
///半小时未动 小车自动删除任务,建立充电任务
/// </summary>
public static void DeleteTask()
{
try
{
string sqlUpdate = string.Format("DELETE t_task where strTaskID ='配送'");
DbHelperSQL.ExecuteSql(sqlUpdate);
}
catch (Exception)
{
throw;
}
}
}
}