Bll.cs
32.4 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
using HHWCS.Model;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemLogHelper;
namespace HHWCS.Bll
{
public class Bll
{
public static void Main(String[] args)
{
//string str = "";
//for (int i = 1; i < 3; i++)
//{
// for (int j = 1; j < 17; j++)
// {
// for (int k = 1; k < 6; k++)
// {
// str += String.Format("INSERT INTO `hhwcs`.`location` (`code`, `warehouseId`, `warehouseCode`, `row`, `column`, `layer`, `grid`, `roadway`, `locationTypeId`, `containerId`, `containerCode`, `zoneId`, `zoneCode`, `status`, `lastCycleCountDate`, `created`, `createdBy`, `lastUpdated`, `lastUpdatedBy`, `enable`, `deleted`, `userDef1`, `userDef2`, `userDef3`, `userDef4`, `userDef5`) VALUES ('{0}', '1', 'CS0001', '{1}', '{2}', '{3}', '0', '1', '1', NULL, NULL, NULL, NULL, 'empty', NULL, '2018-08-24 11:31:27', NULL, '2018-08-24 14:31:46', NULL, b'01', b'00', NULL, NULL, NULL, NULL, NULL);\r\n", "A" + i.ToString().PadLeft(2, '0') + j.ToString().PadLeft(2, '0') + k.ToString().ToString().PadLeft(2, '0'), i, j, k);
// }
// }
//}
//LogExecute.WriteInfoLog(str);
//Console.WriteLine(str);
//object a = false;
//object b = "abc";
//object c = 1;
//object d = (byte)1;
object a =Convert.ToBoolean("True");
object b = Convert.ToInt32("1");
object c = Convert.ToByte("1");
object d = Convert.ToBoolean("0");
Console.WriteLine(a.GetType()+" - "+a);
Console.WriteLine(b.GetType() +" - "+b);
Console.WriteLine(c.GetType()+" - "+c);
Console.WriteLine(d.GetType()+ " - " + d);
//Console.WriteLine(d);
Console.Read();
}
#region Task
public static BllResult<List<TaskEntity>> GetTasks(string status, string taskNo, string pallet, DateTime? beginTime, DateTime? endTime)
{
String sql = "select * from task where 1=1 ";
if (!String.IsNullOrEmpty(status))
{
sql += " and status = '" + status + "'";
}
if (!String.IsNullOrEmpty(taskNo))
{
sql += " and id = " + taskNo;
}
if (!String.IsNullOrEmpty(pallet))
{
sql += " and containerCode = '" + pallet + "'";
}
if (beginTime != null)
{
sql += " and created>='" + beginTime.ToString() + "'";
}
if (endTime != null)
{
sql += " and created<='" + endTime.ToString() + "'";
}
DataSet ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0)
{
return BllResultFactory.Error<List<TaskEntity>>(null, "未找到数据");
}
return BllResultFactory.Sucess<List<TaskEntity>>(ds.Tables[0].AsEnumerable().Select(x => new TaskEntity
{
Id = (int)x["id"],
WarehouseId = Convert.ToInt32(x["warehouseId"]),
WarehouseCode = x["warehouseCode"]?.ToString(),
CompanyId = x["companyId"] is DBNull ? null : (int?)x["companyId"],
Priority = Convert.ToInt32(x["priority"]),
Type = Convert.ToInt32(x["type"]),
Station = x["station"] is DBNull ? null : (int?)x["station"],
ContainerId = x["containerId"] is DBNull ? null : (int?)x["containerId"],
ContainerCode = x["containerCode"]?.ToString(),
SourceLocation = x["sourceLocation"]?.ToString(),
DestinationLocation = x["destinationLocation"]?.ToString(),
Status = Convert.ToInt32(x["status"]),
Created = x["created"] is DBNull ? null : (DateTime?)x["created"],
CreatedBy = x["createdBy"]?.ToString(),
BeginTime = x["beginTime"] is DBNull ? null : (DateTime?)x["beginTime"],
EndTime = x["endTime"] is DBNull ? null : (DateTime?)x["endTime"],
LastUpdated = x["lastUpdated"] is DBNull ? null : (DateTime?)x["lastUpdated"],
}).OrderByDescending(t => t.Created).ToList(), "成功");
}
public static BllResult SendTaskToWCS(int id)
{
try
{
var tasks = Bll.GetTasks(null, id.ToString(), null, null, null);
if (!tasks.Success)
{
return BllResultFactory.Error(null, "未找到任务");
}
var task = tasks.Data[0];
if (task.Status != 0)
{
return BllResultFactory.Error(null, "任务状态不允许下发");
}
string sql = "";
int i = MySqlHelper.ExecuteNonQuery(AppCommon.ConnectionString, sql);
if (i > 0)
{
return BllResultFactory.Sucess(null, "成功");
}
else
{
return BllResultFactory.Error(null, "更新失败");
}
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "更新出现异常:" + ex.ToString());
}
}
/// <summary>
/// 创建任务
/// </summary>
/// <param name="palletCode"></param>
/// <param name="station"></param>
/// <param name="sourceLocation"></param>
/// <param name="destinationLocation"></param>
/// <param name="status"></param>
/// <param name="type"></param>
/// <param name="priority"></param>
/// <returns>注意,任务实体没有返回</returns>
public static BllResult<TaskEntity> CreatTask(string palletCode, int station, string sourceLocation, string destinationLocation, int status, int type, int priority)
{
MySqlConnection mySqlConnection = new MySqlConnection(AppCommon.ConnectionString);
MySqlTransaction tran = null;
try
{
//检查参数
if (String.IsNullOrEmpty(palletCode))
{
return BllResultFactory.Error<TaskEntity>(null, "托盘号不能为空");
}
else
{
//校验托盘,查看托盘是否存在任务未完成
int result = Convert.ToInt32(MySqlHelper.ExecuteScalar(AppCommon.ConnectionString, "SELECT count(*) from task where containerCode = @pallet and `status`<40 and warehouseId= @warehouseId", new MySqlParameter("@pallet", palletCode), new MySqlParameter("@warehouseId", AppCommon.WarehouseId)));
if (result > 0)
{
return BllResultFactory.Error<TaskEntity>(null, "托盘已存在任务");
}
}
if (type == 100 || type == 500 || type == 800)
{
if (String.IsNullOrEmpty(destinationLocation))
{
return BllResultFactory.Error<TaskEntity>(null, "对于整盘入库、空盘入库和移库目标库位不能为空");
}
else
{
var temp = Bll.CheckLocationForCreateTask(destinationLocation, AppCommon.WarehouseId);
if (!temp.Success)
{
return temp;
}
}
}
if (type == 200 || type == 300 || type == 400 || type == 600 || type == 700 || type == 800)
{
if (String.IsNullOrEmpty(sourceLocation))
{
return BllResultFactory.Error<TaskEntity>(null, "对于补充入库、整盘出库、分拣出库、空盘出库、盘点和移库源库位不能为空");
}
else
{
//校验库位
var temp = Bll.CheckLocationForCreateTask(sourceLocation, AppCommon.WarehouseId);
if (!temp.Success)
{
return temp;
}
}
}
mySqlConnection.Open();
tran = mySqlConnection.BeginTransaction();
string sql = "insert into task(containerCode,station,sourceLocation,destinationLocation,status,type,priority,warehouseId,created,createdBy) " +
" VALUES(@pallet, @station, @sourceLocation, @destinationLocation, @status, @type, @priority, @warehouseId,@warehouseCode, NOW(),@createdBy)";
List<MySqlParameter> mySqlParameters = new List<MySqlParameter>();
mySqlParameters.Add(new MySqlParameter("@pallet", palletCode));
mySqlParameters.Add(new MySqlParameter("@station", station));
mySqlParameters.Add(new MySqlParameter("@sourceLocation", sourceLocation));
mySqlParameters.Add(new MySqlParameter("@destinationLocation", destinationLocation));
mySqlParameters.Add(new MySqlParameter("@status", status));
mySqlParameters.Add(new MySqlParameter("@type", type));
mySqlParameters.Add(new MySqlParameter("@priority", priority));
mySqlParameters.Add(new MySqlParameter("@warehouseId", AppCommon.WarehouseId));
mySqlParameters.Add(new MySqlParameter("@createdBy", AppCommon.User.UserName));
mySqlParameters.Add(new MySqlParameter("@warehouseCode", AppCommon.WarehouseCode));
int i = MySqlHelper.ExecuteNonQuery(mySqlConnection, sql, mySqlParameters.ToArray());
if (i == 1)
{
if (type == 100 || type == 500 || type == 800)
{
var temp = Bll.UpdateLocationStatus(destinationLocation, AppCommon.WarehouseId, "lock", mySqlConnection);
if (!temp.Success)
{
tran.Rollback();
return BllResultFactory.Sucess<TaskEntity>(null, "创建任务失败,更新货位状态失败");
}
}
if (type == 200 || type == 300 || type == 400 || type == 600 || type == 700 || type == 800)
{
var temp = Bll.UpdateLocationStatus(sourceLocation, AppCommon.WarehouseId, "lock", mySqlConnection);
if (!temp.Success)
{
tran.Rollback();
return BllResultFactory.Sucess<TaskEntity>(null, "创建任务失败,更新货位状态失败");
}
}
//更新货位状态为预定
tran.Commit();
return BllResultFactory.Sucess<TaskEntity>(null, "成功");
}
else
{
tran.Rollback();
return BllResultFactory.Error<TaskEntity>(null, "插入任务失败");
}
}
catch (Exception ex)
{
tran?.Rollback();
return BllResultFactory.Error<TaskEntity>(null, "出现异常:" + ex.ToString());
}
finally
{
mySqlConnection.Close();
mySqlConnection.Dispose();
}
}
private static BllResult<TaskEntity> CheckLocationForCreateTask(String code, int warehouseId)
{
//校验库位
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, "SELECT * from location where `code` = @code and warehouseId = @warehouseId", new MySqlParameter("@code", code), new MySqlParameter("@warehouseId", AppCommon.WarehouseId));
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<TaskEntity>(null, "没有找到库位");
}
var dr = ds.Tables[0].AsEnumerable().FirstOrDefault();
if (!String.IsNullOrEmpty(dr["containerCode"].ToString()))
{
return BllResultFactory.Error<TaskEntity>(null, "目标库位非空闲");
}
if (!String.IsNullOrEmpty(dr["containerCode"].ToString()))
{
return BllResultFactory.Error<TaskEntity>(null, "目标库位已有货,请不要重入");
}
return BllResultFactory.Sucess<TaskEntity>(null, "OK");
}
public static BllResult SetTaskStatus(int taskId,int status)
{
try
{
string sql = "update task set status =" + status + " where id =" + taskId;
int i = MySqlHelper.ExecuteNonQuery(AppCommon.ConnectionString, sql);
if (i > 0)
{
return BllResultFactory.Sucess(null, "更新成功");
}
else
{
return BllResultFactory.Error(null, "更新失败");
}
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "更新出现异常:"+ex.ToString());
}
}
/// <summary>
/// 更新货位状态
/// </summary>
/// <param name="locationCode"></param>
/// <param name="warehouseId"></param>
/// <param name="newStatus"></param>
/// <returns></returns>
public static BllResult<int> UpdateLocationStatus(String locationCode, int warehouseId, String newStatus, MySqlConnection mySqlConnection)
{
string sql = "update location set `status` = @status where code = @code;";
List<MySqlParameter> mySqlParameters = new List<MySqlParameter>();
mySqlParameters.Add(new MySqlParameter("@status", newStatus));
mySqlParameters.Add(new MySqlParameter("@code", locationCode));
//mySqlParameters.Add(new MySqlParameter("@warehouseId", warehouseId));
int i = MySqlHelper.ExecuteNonQuery(mySqlConnection, sql, mySqlParameters.ToArray());
if (i != 1)
{
return BllResultFactory.Error<int>(0, "失败");
}
else
{
return BllResultFactory.Sucess<int>(0, "成功");
}
}
/// <summary>
/// 完成任务
/// todo:事物管理
/// </summary>
/// <param name="task"></param>
public static BllResult CompleteTask(string taskId)
{
try
{
var tasks = Bll.GetTasks(null, taskId, null, null, null);
if (!tasks.Success)
{
return BllResultFactory.Error(null, "未找到任务");
}
var task = tasks.Data[0];
if (task.Status == 40)
{
return BllResultFactory.Error(null, "任务已完成请不要重复完成");
}
//入库任务将托盘更新到货位上、更新任务状态、更新货位状态
//整入、空入
if (task.Type == 100 || task.Type == 500)
{
//更新货位状态为空闲
var location = Bll.GetAllLocations(null, null, null, null, null, null, task.DestinationLocation).Data[0];
var temp = Bll.UpdateLocationStatus(location.Code, task.WarehouseId, "empty", new MySqlConnection(AppCommon.ConnectionString));
//更新托盘到货位上
Bll.SetLocationPallet(location.Code, task.ContainerCode);
//更新任务状态
Bll.SetTaskStatus(task.Id, 40);
}
//补入、分拣、盘点
if (task.Type == 200 || task.Type == 400 || task.Type == 700)
{
//更新货位状态为空闲
var location = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation).Data[0];
var temp = Bll.UpdateLocationStatus(location.Code, task.WarehouseId, "empty", new MySqlConnection(AppCommon.ConnectionString));
//更新托盘到货位上
Bll.SetLocationPallet(location.Code, task.ContainerCode);
//更新任务状态
Bll.SetTaskStatus(task.Id, 40);
}
if (task.Type == 300 || task.Type == 600)
{
//整出、空出
//更新货位状态为空闲
var location = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation).Data[0];
var temp = Bll.UpdateLocationStatus(location.Code, task.WarehouseId, "empty", new MySqlConnection(AppCommon.ConnectionString));
//清理货位上托盘
Bll.SetLocationPallet(location.Code, "");
//更新任务状态
Bll.SetTaskStatus(task.Id, 40);
}
if (task.Type == 800)
{
//更新货位状态为空闲
var location = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation).Data[0];
var location2 = Bll.GetAllLocations(null, null, null, null, null, null, task.DestinationLocation).Data[0];
var temp = Bll.UpdateLocationStatus(location.Code, task.WarehouseId, "empty", new MySqlConnection(AppCommon.ConnectionString));
var temp2 = Bll.UpdateLocationStatus(location2.Code, task.WarehouseId, "empty", new MySqlConnection(AppCommon.ConnectionString));
//清理货位上托盘
Bll.SetLocationPallet(location.Code, "");
//新增目标货位上的托盘
Bll.SetLocationPallet(location2.Code, task.ContainerCode);
//更新任务状态
Bll.SetTaskStatus(task.Id, 40);
}
return BllResultFactory.Sucess(null, "完成任务成功");
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "完成任务发生异常:" + ex.ToString());
}
}
/// <summary>
/// 删除任务,只有生成未执行的任务可以删除
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
public static BllResult DeleteTask(int taskId)
{
try
{
var tasks = Bll.GetTasks(null, taskId.ToString(), null, null, null);
if (!tasks.Success)
{
return BllResultFactory.Error(null, "未找到任务");
}
var task = tasks.Data[0];
if (task.Status != 0)
{
return BllResultFactory.Error(null, "任务状态不允许删除");
}
string sql = "DELETE from task where id = " + taskId;
int i = MySqlHelper.ExecuteNonQuery(AppCommon.ConnectionString, sql);
if (i > 0)
{
return BllResultFactory.Sucess(null, "删除成功");
}
else
{
return BllResultFactory.Error(null, "删除失败");
}
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "删除任务出现异常:" + ex.ToString());
}
}
#endregion
#region Device
public static BllResult<List<DeviceEntity>> GetAllDevice()
{
try
{
string sql = "select * from devicelist where enable = 1";
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<DeviceEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new DeviceEntity
{
Id = (int)t["id"],
Code = t["code"].ToString(),
Name = t["name"].ToString(),
Type = (int)t["type"],
IP = t["ip"].ToString(),
S7_Connect = t["S7_Connect"].ToString(),
GroupName = t["groupName"].ToString(),
Enable = Convert.ToBoolean(t["enable"]),
DeviceTypeId = (int)t["deviceTypeId"],
Roadway = t["roadway"] is DBNull?-1:Convert.ToInt32(t["roadway"]),
SelfAddress = t["selfAddress"] is DBNull?-1:Convert.ToInt32(t["selfAddress"])
}).ToList();
return BllResultFactory.Sucess<List<DeviceEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<DeviceEntity>>(null, "异常:" + ex.ToString());
}
}
public static BllResult<List<DeviceAddressEntity>> GetAllDeviceAddress()
{
try
{
string sql = "select * from deviceaddress where enable = 1";
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<DeviceAddressEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new DeviceAddressEntity
{
Id = (int)t["id"],
DeviceId = t["deviceId"] is DBNull ? null : (int?)t["deviceId"],
DevicePropId = t["devicePropId"] is DBNull ? null : (int?)t["devicePropId"],
DevicePropCode = t["devicePropCode"].ToString(),
ServerHandle = (int)t["serverHandle"],
Address = t["address"].ToString(),
value = t["value"].ToString(),
Enable = Convert.ToBoolean(t["enable"])
}).ToList();
return BllResultFactory.Sucess<List<DeviceAddressEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<DeviceAddressEntity>>(null, "异常:" + ex.ToString());
}
}
public static BllResult<List<DevicePropEntity>> GetAllDeviceProp()
{
try
{
string sql = "select * from deviceprop where enable=1";
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<DevicePropEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new DevicePropEntity
{
Id = (int)t["id"],
DeviceTypeId = (int)t["deviceTypeId"],
Code = t["code"].ToString(),
Name = t["name"].ToString(),
Type = t["type"].ToString(),
Description = t["description"].ToString(),
Enable = Convert.ToBoolean(t["enable"]),
IsMonitor = t["isMonitor"] is DBNull?null:(int?)t["isMonitor"],
MonitorCompareValue = t["monitorCompareValue"] is DBNull ? null : t["monitorCompareValue"].ToString(),
MonitorFailure = t["monitorFailure"] is DBNull ? null : t["monitorFailure"].ToString(),
MonitorNormal = t["monitorNormal"] is DBNull ? null : t["monitorNormal"].ToString(),
}).ToList();
return BllResultFactory.Sucess<List<DevicePropEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<DevicePropEntity>>(null, "异常:" + ex.ToString());
}
}
public static BllResult<List<DeviceTypeEntity>> GetAllDeviceType()
{
try
{
string sql = "select * from devicetype where enable=1";
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<DeviceTypeEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new DeviceTypeEntity
{
Id = (int)t["id"],
Code = t["code"].ToString(),
Name = t["name"].ToString(),
Description = t["description"].ToString(),
Enable = Convert.ToBoolean(t["enable"])
}).ToList();
return BllResultFactory.Sucess<List<DeviceTypeEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<DeviceTypeEntity>>(null, "异常:" + ex.ToString());
}
}
#endregion
#region location
public static BllResult SetLocationPallet(string locationCode,string palletCode)
{
try
{
if (String.IsNullOrEmpty(locationCode) || palletCode==null)
{
return BllResultFactory.Error(null, "参数不全");
}
string sql = "update location set containerCode ='" + palletCode + "' where code ='" + locationCode + "'";
int i = MySqlHelper.ExecuteNonQuery(AppCommon.ConnectionString, sql);
if (i > 0)
{
return BllResultFactory.Sucess(null, "更新成功");
}
else
{
return BllResultFactory.Error(null, "更新失败");
}
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "更新出现异常:" + ex.ToString());
}
}
public static BllResult<List<LocationEntity>> GetAllLocations(String containerCode, string row, string column, string layer, string roadway, string status,string code)
{
try
{
string sql = "select * from location where 1=1 ";
if (!String.IsNullOrEmpty(containerCode))
{
sql += " and containerCode = '" + containerCode + "'";
}
if (!String.IsNullOrEmpty(row))
{
sql += " and row =" + row;
}
if (!String.IsNullOrEmpty(column))
{
sql += " and column =" + column;
}
if (!String.IsNullOrEmpty(layer))
{
sql += " and layer =" + layer;
}
if (!String.IsNullOrEmpty(roadway))
{
sql += " and roadway =" + roadway;
}
if (!String.IsNullOrEmpty(status)&&status!="all")
{
sql += " and status = '" + status + "'";
}
if (!String.IsNullOrEmpty(code))
{
sql += " and code ='" + code + "'";
}
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<LocationEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new LocationEntity
{
Id = (int)t["id"],
Code = t["code"].ToString(),
WarehouseCode = t["warehouseCode"].ToString(),
Row = Convert.ToInt32(t["row"]),
Column = Convert.ToInt32(t["column"]),
Layer = Convert.ToInt32(t["layer"]),
Grid = t["grid"] is DBNull ? 0 : Convert.ToInt32(t["grid"]),
Roadway = (int)t["roadway"],
ContainerCode = t["containerCode"] is DBNull ? "" : t["containerCode"].ToString(),
Status = t["status"].ToString()
}).ToList();
return BllResultFactory.Sucess<List<LocationEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<LocationEntity>>(null, "访问异常:" + ex.ToString());
}
}
#endregion
#region pallet
public static BllResult<List<ContainerEntity>> GetAllContainer(string code,bool isInLocation,bool isPrint)
{
try
{
string sql = "select * from container t where 1=1 ";
if (!String.IsNullOrEmpty(code))
{
sql += " and t.code = '" + code + "'";
}
if (isPrint)
{
sql += " and t.printCount > 0";
}
if (isInLocation)
{
sql += " and EXISTS(SELECT * from location where containerCode = t.`code`);";
}
var ds = MySqlHelper.ExecuteDataset(AppCommon.ConnectionString, sql);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
return BllResultFactory.Error<List<ContainerEntity>>(null, "没有数据");
}
var list = ds.Tables[0].AsEnumerable().Select(t => new ContainerEntity
{
Id = (int)t["id"],
Code = t["code"].ToString(),
Status = t["status"] is DBNull?"":t["status"].ToString(),
PrintCount = (int)t["printCount"],
Enable = Convert.ToBoolean(t["enable"])
}).ToList();
return BllResultFactory.Sucess<List<ContainerEntity>>(list, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<List<ContainerEntity>>(null, "访问异常:" + ex.ToString());
}
}
public static BllResult UpdatePallet(string code,string print,string status)
{
try
{
if (String.IsNullOrEmpty(print) && String.IsNullOrEmpty(status))
{
return BllResultFactory.Error(null, "数据不全");
}
string sql = "update container set ";
bool flag = false;
if (!String.IsNullOrEmpty(print))
{
sql += "printCount = printCount+" + print;
flag = true;
}
if (!String.IsNullOrEmpty(status))
{
if (flag)
{
sql += ", ";
}
sql += "`status` = '" + status + "'";
}
sql += " where code ='" + code + "'";
int i = MySqlHelper.ExecuteNonQuery(AppCommon.ConnectionString, sql);
if (i > 0)
{
return BllResultFactory.Sucess(null, "成功");
}
else
{
return BllResultFactory.Error(null, "更新失败");
}
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "更新打印次数出现异常:" + ex.ToString());
}
}
#endregion
}
}