liufu
authored
7 years ago
1
2
3
4
5
6
7
8
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 ;
liufu
authored
7 years ago
9
using SystemLogHelper ;
liufu
authored
7 years ago
10
using LEDhelp ;
liufu
authored
7 years ago
11
12
13
namespace HHWCS.Bll
{
liufu
authored
7 years ago
14
15
public class Bll : IBll
{
liufu
authored
7 years ago
16
17
public static void Main ( String [] args )
{
liufu
authored
7 years ago
18
19
20
// string str = "" ;
// for ( int i = 1 ; i < 3 ; i ++)
//{
liufu
authored
7 years ago
21
// for ( int j = 1 ; j < 33 ; j ++)
liufu
authored
7 years ago
22
23
24
// {
// for ( int k = 1 ; k < 6 ; k ++)
// {
liufu
authored
7 years ago
25
// str += String . Format ( "INSERT INTO `huaheng`.`location` (`code`, `warehouseId`, `warehouseCode`, `row`, `line`, `layer`, `grid`, `roadway`, `type`, `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', 'LK', 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 );
liufu
authored
7 years ago
26
27
28
29
30
31
32
33
34
// }
// }
//}
// LogExecute . WriteInfoLog ( str );
// Console . WriteLine ( str );
// object a = false ;
// object b = "abc" ;
// object c = 1 ;
// object d = ( byte ) 1 ;
liufu
authored
7 years ago
35
36
37
38
39
40
41
42
43
// 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 );
liufu
authored
7 years ago
44
// Console . WriteLine ( d );
liufu
authored
7 years ago
45
46
47
48
// byte a = 0 b00010001 ;
// Console . WriteLine ( a );
// LEDhelp . LEDHelper led = new LEDhelp . LEDHelper ( "192.168.10.110" , 5005 , 1 );
// led . SendLedInfo ( "dfadffgsdgsdfgs\\ndfgsdfgdfg16\\n开发机构涉及地方\\n管理会计师对方了国家\\n受到了房价太高迫而价格\\n破手机而苹果就是独立\\n开发背景来看笑话\\nVB哦时间的反馈给解释答复" );
liufu
authored
7 years ago
49
50
51
// Bll bll = new Bll ();
// var a = bll . GetTaskDetailsByTaskId ( 150 );
// a . Data . ForEach ( t => Console . WriteLine ( t . ToString ()));
liufu
authored
7 years ago
52
53
// Queue < string > q = new Queue < string >();
liufu
authored
7 years ago
54
// LEDHelper led = new LEDHelper ( "192.168.10.110" , 5005 , 1 );
liufu
authored
7 years ago
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// LEDHelper led2 = new LEDHelper ( "192.168.10.110" , 5005 , 1 );
// Task . Run ( async () =>
//{
// while ( true )
// {
// await Task . Delay ( 3000 );
// if ( q . Count > 0 )
// {
// led2 . SendLedInfo ( q . Dequeue ());
// }
// }
//});
// String read = "" ;
// while ( read != "exit" )
//{
// read = Console . ReadLine ();
// // led . SendLedInfo ( read );
// q . Enqueue ( read );
//}
liufu
authored
7 years ago
74
75
76
Console . Read ();
}
liufu
authored
7 years ago
77
78
# region Login
liufu
authored
7 years ago
79
public async Task < BllResult > Login ( string userName , string password )
liufu
authored
7 years ago
80
81
82
83
84
85
{
return BllResultFactory . Sucess ( null , "默认成功" );
}
# endregion
liufu
authored
7 years ago
86
# region Task
liufu
authored
7 years ago
87
liufu
authored
7 years ago
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
public BllResult < List < TaskDetailEntity >> GetTaskDetailsByTaskId ( int taskId )
{
try
{
string sql = $ "SELECT td.*,m.`name` materialName FROM task_detail td join material m on td.materialCode = m.`code` and td.warehouseId = m.warehouseId where td.taskId = {taskId}" ;
var ds = MySqlHelper . ExecuteDataset ( AppCommon . ConnectionString , sql );
if ( ds == null || ds . Tables . Count == 0 || ds . Tables [ 0 ]. Rows . Count == 0 )
{
return BllResultFactory . Error < List < TaskDetailEntity >>( null , "没有数据" );
}
var list = ds . Tables [ 0 ]. AsEnumerable (). Select ( t => new TaskDetailEntity ()
{
Id = Convert . ToInt32 ( t [ "id" ]),
TaskId = ( int ) t [ "taskId" ],
WarehouseId = ( int ) t [ "warehouseId" ],
WarehouseCode = t [ "warehouseCode" ] is DBNull ? null : t [ "warehouseCode" ]. ToString (),
AllocationId = t [ "allocationId" ] is DBNull ? - 1 : Convert . ToInt32 ( t [ "allocationId" ]),
MaterialCode = t [ "materialCode" ] is DBNull ? null : t [ "materialCode" ]. ToString (),
ContainerCode = t [ "containerCode" ] is DBNull ? null : t [ "containerCode" ]. ToString (),
SourceLocation = t [ "sourceLocation" ] is DBNull ? null : t [ "sourceLocation" ]. ToString (),
DestinationLocation = t [ "destinationLocation" ] is DBNull ? null : t [ "destinationLocation" ]. ToString (),
Qty = t [ "qty" ] is DBNull ? 0 : Convert . ToInt32 ( t [ "qty" ]),
Status = Convert . ToInt32 ( t [ "status" ]),
Endtime = t [ "endTime" ] is DBNull ? null : ( DateTime ?)( t [ "endTime" ]),
LastUpdated = t [ "lastUpdated" ] is DBNull ? null : ( DateTime ?) t [ "lastUpdated" ],
LastUpdateBy = t [ "lastUpdatedBy" ] is DBNull ? "" : t [ "lastUpdatedBy" ]. ToString (),
Deleted = Convert . ToBoolean ( t [ "deleted" ]),
MaterialName = t [ "materialName" ] is DBNull ? null : t [ "materialName" ]. ToString ()
}). ToList ();
return BllResultFactory . Sucess < List < TaskDetailEntity >>( list , "成功" );
}
catch ( Exception ex )
{
return BllResultFactory . Error < List < TaskDetailEntity >>( null , "查询失败" );
}
}
liufu
authored
7 years ago
126
/// < summary >
liufu
authored
7 years ago
127
128
129
130
131
132
133
134
135
/// 处理空出
/// </ summary >
/// < param name = "v" ></ param >
/// < param name = "task" ></ param >
/// < returns ></ returns >
public BllResult EmptyOutHandle ( string v , string status , TaskEntity task )
{
try
{
liufu
authored
7 years ago
136
string sql = $ "UPDATE task set isEmptyOut ={v} ,lastStatus = {status},firstStatus={status} where id = {task.Id}" ;
liufu
authored
7 years ago
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
int i = MySqlHelper . ExecuteNonQuery ( AppCommon . ConnectionString , sql );
if ( i == 0 )
{
UpdateLocationStatus ( task . DestinationLocation , AppCommon . WarehouseId , "empty" , AppCommon . ConnectionString );
UpdateLocationStatus ( task . SourceLocation , AppCommon . WarehouseId , "empty" , AppCommon . ConnectionString );
return BllResultFactory . Error ( null , "更新失败" );
}
else
{
return BllResultFactory . Sucess ( null , "成功" );
}
}
catch ( Exception ex )
{
return BllResultFactory . Error ( null , "空出处理失败:" + ex . ToString ());
}
}
/// < summary >
liufu
authored
7 years ago
156
157
158
159
160
/// 处理重入
/// </ summary >
/// < param name = "location" ></ param >
/// < param name = "task" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
161
public BllResult TaskDoubleInHandle ( string flag , String location , int taskId )
liufu
authored
7 years ago
162
163
164
{
try
{
liufu
authored
7 years ago
165
string sql = $ "update task set isDoubleIn = {flag},secondDestinationLocation = '{location}' WHERE id = {taskId}" ;
liufu
authored
7 years ago
166
167
168
169
170
171
172
int i = MySqlHelper . ExecuteNonQuery ( AppCommon . ConnectionString , sql );
if ( i == 0 )
{
return BllResultFactory . Error ( null , "更新失败" );
}
else
{
liufu
authored
7 years ago
173
UpdateLocationStatus ( location , AppCommon . WarehouseId , "lock" , AppCommon . ConnectionString );
liufu
authored
7 years ago
174
175
176
177
178
179
180
181
182
return BllResultFactory . Sucess ( null , "更新成功" );
}
}
catch ( Exception ex )
{
return BllResultFactory . Error ( null , "更新失败:" + ex . ToString ());
}
}
liufu
authored
7 years ago
183
public BllResult < List < TaskEntity >> GetTasks ( string status , string taskNo , string pallet , DateTime ? beginTime , DateTime ? endTime )
liufu
authored
7 years ago
184
{
liufu
authored
7 years ago
185
try
liufu
authored
7 years ago
186
{
liufu
authored
7 years ago
187
188
189
String sql = "select * from task where 1=1 " ;
if (! String . IsNullOrEmpty ( status ))
{
liufu
authored
7 years ago
190
sql += " and lastStatus = '" + status + "'" ;
liufu
authored
7 years ago
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}
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 () + "'" ;
}
liufu
authored
7 years ago
208
sql += " ORDER BY lastUpdated " ;
liufu
authored
7 years ago
209
liufu
authored
7 years ago
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
DataSet ds = MySqlHelper . ExecuteDataset ( AppCommon . ConnectionString , sql );
if ( ds == null || ds . Tables . Count == 0 || ds . Tables [ 0 ]. Rows . 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 (),
liufu
authored
7 years ago
228
229
FirstStatus = Convert . ToInt32 ( x [ "firstStatus" ]),
LastStatus = Convert . ToInt32 ( x [ "lastStatus" ]),
liufu
authored
7 years ago
230
231
232
233
234
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" ],
liufu
authored
7 years ago
235
IsDoubleIn = Convert . ToInt32 ( x [ "isDoubleIn" ]),
liufu
authored
7 years ago
236
237
SecondDestinationLocation = x [ "secondDestinationLocation" ] is DBNull ? null : x [ "secondDestinationLocation" ]. ToString ()
liufu
authored
7 years ago
238
}). OrderByDescending ( t => t . Created ). ToList (), "成功" );
liufu
authored
7 years ago
239
}
liufu
authored
7 years ago
240
catch ( Exception ex )
liufu
authored
7 years ago
241
{
liufu
authored
7 years ago
242
243
return BllResultFactory . Error < List < TaskEntity >>( null , "获取任务出现异常:" + ex . ToString ());
}
liufu
authored
7 years ago
244
245
}
liufu
authored
7 years ago
246
public virtual BllResult SendTaskToWCS ( int id )
liufu
authored
7 years ago
247
248
249
{
try
{
liufu
authored
7 years ago
250
var tasks = GetTasks ( null , id . ToString (), null , null , null );
liufu
authored
7 years ago
251
252
253
254
255
if (! tasks . Success )
{
return BllResultFactory . Error ( null , "未找到任务" );
}
var task = tasks . Data [ 0 ];
liufu
authored
7 years ago
256
if ( task . LastStatus != 0 )
liufu
authored
7 years ago
257
258
259
{
return BllResultFactory . Error ( null , "任务状态不允许下发" );
}
liufu
authored
7 years ago
260
string sql = "update task set lastStatus = 10,firstStatus=10 where id = " + id ;
liufu
authored
7 years ago
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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 ());
}
}
liufu
authored
7 years ago
277
278
279
280
281
282
283
284
285
286
287
/// < 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 >
liufu
authored
7 years ago
288
public BllResult < TaskEntity > CreatTask ( string palletCode , int station , string sourceLocation , string destinationLocation , int status , int type , int priority )
liufu
authored
7 years ago
289
290
291
292
293
294
{
MySqlConnection mySqlConnection = new MySqlConnection ( AppCommon . ConnectionString );
MySqlTransaction tran = null ;
try
{
// 检查参数
liufu
authored
7 years ago
295
if (! String . IsNullOrEmpty ( palletCode ))
liufu
authored
7 years ago
296
297
{
// 校验托盘,查看托盘是否存在任务未完成
liufu
authored
7 years ago
298
int result = Convert . ToInt32 ( MySqlHelper . ExecuteScalar ( AppCommon . ConnectionString , "SELECT count(*) from task where containerCode = @pallet and `lastStatus`<40 and warehouseId= @warehouseId" , new MySqlParameter ( "@pallet" , palletCode ), new MySqlParameter ( "@warehouseId" , AppCommon . WarehouseId )));
liufu
authored
7 years ago
299
300
301
302
303
304
305
306
307
308
309
if ( result > 0 )
{
return BllResultFactory . Error < TaskEntity >( null , "托盘已存在任务" );
}
}
if ( type == 100 || type == 500 || type == 800 )
{
if ( String . IsNullOrEmpty ( destinationLocation ))
{
return BllResultFactory . Error < TaskEntity >( null , "对于整盘入库、空盘入库和移库目标库位不能为空" );
}
liufu
authored
7 years ago
310
311
312
313
else if ( String . IsNullOrEmpty ( palletCode ))
{
return BllResultFactory . Error < TaskEntity >( null , "对于整盘入库、空盘入库和移库托盘号不能为空" );
}
liufu
authored
7 years ago
314
315
else
{
liufu
authored
7 years ago
316
var temp = CheckLocationForCreateTaskIn ( destinationLocation , AppCommon . WarehouseId );
liufu
authored
7 years ago
317
318
319
320
321
322
if (! temp . Success )
{
return temp ;
}
}
}
liufu
authored
7 years ago
323
if ( type == 200 || type == 300 || type == 400 || type == 900 || type == 600 || type == 700 || type == 800 )
liufu
authored
7 years ago
324
325
326
{
if ( String . IsNullOrEmpty ( sourceLocation ))
{
liufu
authored
7 years ago
327
return BllResultFactory . Error < TaskEntity >( null , "对于补充入库、整盘出库、分拣出库、空盘出库、出库查看、盘点和移库源库位不能为空" );
liufu
authored
7 years ago
328
329
330
331
}
else
{
// 校验库位
liufu
authored
7 years ago
332
var temp = GetAllLocations ( null , null , null , null , null , null , sourceLocation );
liufu
authored
7 years ago
333
334
if (! temp . Success )
{
liufu
authored
7 years ago
335
return BllResultFactory . Error < TaskEntity >( null , "未找到" + sourceLocation );
liufu
authored
7 years ago
336
337
338
339
}
var location = temp . Data [ 0 ];
if ( location . Status != "empty" )
{
liufu
authored
7 years ago
340
return BllResultFactory . Error < TaskEntity >( null , sourceLocation + "非空闲" );
liufu
authored
7 years ago
341
342
343
}
if ( string . IsNullOrEmpty ( location . ContainerCode ))
{
liufu
authored
7 years ago
344
return BllResultFactory . Error < TaskEntity >( null , sourceLocation + "没有托盘" );
liufu
authored
7 years ago
345
346
347
348
349
350
351
352
353
}
if ( string . IsNullOrEmpty ( palletCode ))
{
palletCode = location . ContainerCode ;
}
else
{
if ( palletCode != location . ContainerCode )
{
liufu
authored
7 years ago
354
return BllResultFactory . Error < TaskEntity >( null , sourceLocation + "库位托盘为" + location . ContainerCode + "与录入的" + palletCode + "不一致" );
liufu
authored
7 years ago
355
}
liufu
authored
7 years ago
356
}
liufu
authored
7 years ago
357
liufu
authored
7 years ago
358
359
360
361
}
}
mySqlConnection . Open ();
tran = mySqlConnection . BeginTransaction ();
liufu
authored
7 years ago
362
363
string sql = "insert into task(containerCode,station,sourceLocation,destinationLocation,lastStatus,firstStatus,type,priority,warehouseId,warehouseCode,created,createdBy) " +
" VALUES(@pallet, @station, @sourceLocation, @destinationLocation, @lastStatus,@firstStatus, @type, @priority, @warehouseId,@warehouseCode, NOW(),@createdBy)" ;
liufu
authored
7 years ago
364
365
366
367
368
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 ));
liufu
authored
7 years ago
369
370
mySqlParameters . Add ( new MySqlParameter ( "@lastStatus" , status ));
mySqlParameters . Add ( new MySqlParameter ( "@firstStatus" , status ));
liufu
authored
7 years ago
371
372
373
374
375
376
377
378
379
380
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 )
{
liufu
authored
7 years ago
381
var temp = UpdateLocationStatus ( destinationLocation , AppCommon . WarehouseId , "lock" , mySqlConnection );
liufu
authored
7 years ago
382
383
384
385
386
387
if (! temp . Success )
{
tran . Rollback ();
return BllResultFactory . Sucess < TaskEntity >( null , "创建任务失败,更新货位状态失败" );
}
}
liufu
authored
7 years ago
388
if ( type == 200 || type == 300 || type == 400 || type == 900 || type == 600 || type == 700 || type == 800 )
liufu
authored
7 years ago
389
{
liufu
authored
7 years ago
390
var temp = UpdateLocationStatus ( sourceLocation , AppCommon . WarehouseId , "lock" , mySqlConnection );
liufu
authored
7 years ago
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
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 ();
}
}
liufu
authored
7 years ago
419
public BllResult < TaskEntity > CheckLocationForCreateTaskIn ( String code , int warehouseId )
liufu
authored
7 years ago
420
421
422
423
424
425
426
427
{
// 校验库位
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 ();
liufu
authored
7 years ago
428
if ( dr [ "status" ]. ToString () != "empty" )
liufu
authored
7 years ago
429
430
431
432
433
434
435
436
437
438
{
return BllResultFactory . Error < TaskEntity >( null , "目标库位非空闲" );
}
if (! String . IsNullOrEmpty ( dr [ "containerCode" ]. ToString ()))
{
return BllResultFactory . Error < TaskEntity >( null , "目标库位已有货,请不要重入" );
}
return BllResultFactory . Sucess < TaskEntity >( null , "OK" );
}
liufu
authored
7 years ago
439
public BllResult SetTaskStatus ( int taskId , int status )
liufu
authored
7 years ago
440
441
442
{
try
{
liufu
authored
7 years ago
443
string sql = "update task set lastStatus =" + status + ",firstStatus=" + status + " where id =" + taskId ;
liufu
authored
7 years ago
444
445
446
447
448
449
450
451
452
453
454
455
int i = MySqlHelper . ExecuteNonQuery ( AppCommon . ConnectionString , sql );
if ( i > 0 )
{
return BllResultFactory . Sucess ( null , "更新成功" );
}
else
{
return BllResultFactory . Error ( null , "更新失败" );
}
}
catch ( Exception ex )
{
liufu
authored
7 years ago
456
return BllResultFactory . Error ( null , "更新出现异常:" + ex . ToString ());
liufu
authored
7 years ago
457
458
459
460
461
462
463
464
465
466
467
}
}
/// < summary >
/// 更新货位状态
/// </ summary >
/// < param name = "locationCode" ></ param >
/// < param name = "warehouseId" ></ param >
/// < param name = "newStatus" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
468
public BllResult < int > UpdateLocationStatus ( String locationCode , int warehouseId , String newStatus , MySqlConnection mySqlConnection )
liufu
authored
7 years ago
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
{
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 , "成功" );
}
liufu
authored
7 years ago
484
}
liufu
authored
7 years ago
485
liufu
authored
7 years ago
486
487
488
489
490
491
492
/// < summary >
/// 更新货位状态
/// </ summary >
/// < param name = "locationCode" ></ param >
/// < param name = "warehouseId" ></ param >
/// < param name = "newStatus" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
493
public BllResult < int > UpdateLocationStatus ( String locationCode , int warehouseId , String newStatus , String mySqlConnection )
liufu
authored
7 years ago
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
{
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 , "成功" );
}
liufu
authored
7 years ago
509
510
511
512
513
514
515
}
/// < summary >
/// 完成任务
/// todo : 事物管理
/// </ summary >
/// < param name = "task" ></ param >
liufu
authored
7 years ago
516
public virtual BllResult CompleteTask ( string taskId )
liufu
authored
7 years ago
517
518
519
{
try
{
liufu
authored
7 years ago
520
var tasks = GetTasks ( null , taskId , null , null , null );
liufu
authored
7 years ago
521
522
523
524
525
if (! tasks . Success )
{
return BllResultFactory . Error ( null , "未找到任务" );
}
var task = tasks . Data [ 0 ];
liufu
authored
7 years ago
526
if ( task . LastStatus == 40 )
liufu
authored
7 years ago
527
528
529
{
return BllResultFactory . Error ( null , "任务已完成请不要重复完成" );
}
liufu
authored
7 years ago
530
531
532
533
534
// 入库任务将托盘更新到货位上、更新任务状态、更新货位状态
// 整入、空入
if ( task . Type == 100 || task . Type == 500 )
{
// 更新货位状态为空闲
liufu
authored
7 years ago
535
536
var location = GetAllLocations ( null , null , null , null , null , null , task . DestinationLocation ). Data [ 0 ];
var temp = UpdateLocationStatus ( location . Code , task . WarehouseId , "empty" , AppCommon . ConnectionString );
liufu
authored
7 years ago
537
538
539
if ( task . IsDoubleIn == 1 )
{
//
liufu
authored
7 years ago
540
541
UpdateLocationStatus ( task . SecondDestinationLocation , task . WarehouseId , "empty" , AppCommon . ConnectionString );
SetLocationPallet ( task . SecondDestinationLocation , task . ContainerCode );
liufu
authored
7 years ago
542
543
544
545
}
else
{
// 更新托盘到货位上
liufu
authored
7 years ago
546
SetLocationPallet ( location . Code , task . ContainerCode );
liufu
authored
7 years ago
547
}
liufu
authored
7 years ago
548
// 更新任务状态
liufu
authored
7 years ago
549
SetTaskStatus ( task . Id , 40 );
liufu
authored
7 years ago
550
551
}
// 补入、分拣、盘点
liufu
authored
7 years ago
552
if ( task . Type == 200 || task . Type == 400 || task . Type == 900 || task . Type == 700 )
liufu
authored
7 years ago
553
554
{
// 更新货位状态为空闲
liufu
authored
7 years ago
555
556
var location = GetAllLocations ( null , null , null , null , null , null , task . SourceLocation ). Data [ 0 ];
var temp = UpdateLocationStatus ( location . Code , task . WarehouseId , "empty" , AppCommon . ConnectionString );
liufu
authored
7 years ago
557
558
if ( task . IsDoubleIn == 1 )
{
liufu
authored
7 years ago
559
560
UpdateLocationStatus ( task . SecondDestinationLocation , task . WarehouseId , "empty" , AppCommon . ConnectionString );
SetLocationPallet ( task . SecondDestinationLocation , task . ContainerCode );
liufu
authored
7 years ago
561
// 清除原来货位上的托盘
liufu
authored
7 years ago
562
SetLocationPallet ( location . Code , "" );
liufu
authored
7 years ago
563
564
565
566
}
else
{
// 更新托盘到货位上
liufu
authored
7 years ago
567
SetLocationPallet ( location . Code , task . ContainerCode );
liufu
authored
7 years ago
568
}
liufu
authored
7 years ago
569
// 更新任务状态
liufu
authored
7 years ago
570
SetTaskStatus ( task . Id , 40 );
liufu
authored
7 years ago
571
572
573
574
575
}
if ( task . Type == 300 || task . Type == 600 )
{
// 整出、空出
// 更新货位状态为空闲
liufu
authored
7 years ago
576
577
var location = GetAllLocations ( null , null , null , null , null , null , task . SourceLocation ). Data [ 0 ];
var temp = UpdateLocationStatus ( location . Code , task . WarehouseId , "empty" , AppCommon . ConnectionString );
liufu
authored
7 years ago
578
// 清理货位上托盘
liufu
authored
7 years ago
579
SetLocationPallet ( location . Code , "" );
liufu
authored
7 years ago
580
// 更新任务状态
liufu
authored
7 years ago
581
SetTaskStatus ( task . Id , 40 );
liufu
authored
7 years ago
582
583
584
585
}
if ( task . Type == 800 )
{
// 更新货位状态为空闲
liufu
authored
7 years ago
586
587
588
589
var location = GetAllLocations ( null , null , null , null , null , null , task . SourceLocation ). Data [ 0 ];
var location2 = GetAllLocations ( null , null , null , null , null , null , task . DestinationLocation ). Data [ 0 ];
var temp = UpdateLocationStatus ( location . Code , task . WarehouseId , "empty" , AppCommon . ConnectionString );
var temp2 = UpdateLocationStatus ( location2 . Code , task . WarehouseId , "empty" , AppCommon . ConnectionString );
liufu
authored
7 years ago
590
// 清理货位上托盘
liufu
authored
7 years ago
591
SetLocationPallet ( location . Code , "" );
liufu
authored
7 years ago
592
593
if ( task . IsDoubleIn == 1 )
{
liufu
authored
7 years ago
594
595
UpdateLocationStatus ( task . SecondDestinationLocation , task . WarehouseId , "empty" , AppCommon . ConnectionString );
SetLocationPallet ( task . SecondDestinationLocation , task . ContainerCode );
liufu
authored
7 years ago
596
597
598
599
}
else
{
// 新增目标货位上的托盘
liufu
authored
7 years ago
600
SetLocationPallet ( location2 . Code , task . ContainerCode );
liufu
authored
7 years ago
601
}
liufu
authored
7 years ago
602
// 更新任务状态
liufu
authored
7 years ago
603
SetTaskStatus ( task . Id , 40 );
liufu
authored
7 years ago
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
}
return BllResultFactory . Sucess ( null , "完成任务成功" );
}
catch ( Exception ex )
{
return BllResultFactory . Error ( null , "完成任务发生异常:" + ex . ToString ());
}
}
/// < summary >
/// 删除任务,只有生成未执行的任务可以删除
/// </ summary >
/// < param name = "taskId" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
619
public BllResult DeleteTask ( int taskId )
liufu
authored
7 years ago
620
621
622
{
try
{
liufu
authored
7 years ago
623
var tasks = GetTasks ( null , taskId . ToString (), null , null , null );
liufu
authored
7 years ago
624
625
626
627
628
if (! tasks . Success )
{
return BllResultFactory . Error ( null , "未找到任务" );
}
var task = tasks . Data [ 0 ];
liufu
authored
7 years ago
629
if ( task . LastStatus != 0 )
liufu
authored
7 years ago
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
{
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 ());
}
}
liufu
authored
7 years ago
651
652
653
654
655
/// < summary >
/// 根据托盘号获取一条未完成的任务
/// </ summary >
/// < param name = "palletCode" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
656
public BllResult < TaskEntity > GetTaskUncompleteByPalletCode ( string palletCode )
liufu
authored
7 years ago
657
658
659
{
try
{
liufu
authored
7 years ago
660
string sql = "SELECT * from task where `lastStatus`<40 and containerCode = '" + palletCode + "'" ;
liufu
authored
7 years ago
661
var ds = MySqlHelper . ExecuteDataset ( AppCommon . ConnectionString , sql );
liufu
authored
7 years ago
662
if ( ds == null || ds . Tables . Count == 0 || ds . Tables [ 0 ]. Rows . Count == 0 )
liufu
authored
7 years ago
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
{
return BllResultFactory . Error < TaskEntity >( null , "未找到数据" );
}
return BllResultFactory . Sucess < 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 (),
liufu
authored
7 years ago
679
LastStatus = Convert . ToInt32 ( x [ "lastStatus" ]),
liufu
authored
7 years ago
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
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 ()[ 0 ], "成功" );
}
catch ( Exception ex )
{
return BllResultFactory . Error < TaskEntity >( null , "获取数据出现异常:" + ex . ToString ());
}
}
/// < summary >
/// todo : 根据空托盘创建一条空托盘入库任务 , 暂时不实现
/// </ summary >
/// < param name = "palletCode" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
698
public BllResult CreatePalletIn ( string palletCode )
liufu
authored
7 years ago
699
700
701
702
{
return null ;
}
liufu
authored
7 years ago
703
704
705
706
# endregion
# region Device
liufu
authored
7 years ago
707
public BllResult < List < DeviceEntity >> GetAllDevice ()
liufu
authored
7 years ago
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
{
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" ],
liufu
authored
7 years ago
728
Roadway = t [ "roadway" ] is DBNull ? - 1 : Convert . ToInt32 ( t [ "roadway" ]),
liufu
authored
7 years ago
729
SelfAddress = t [ "selfAddress" ] is DBNull ? - 1 : Convert . ToInt32 ( t [ "selfAddress" ]),
liufu
authored
7 years ago
730
BackAddress = t [ "backAddress" ] is DBNull ? null : t [ "backAddress" ]. ToString ()
liufu
authored
7 years ago
731
732
733
734
735
736
737
738
739
740
}). ToList ();
return BllResultFactory . Sucess < List < DeviceEntity >>( list , "成功" );
}
catch ( Exception ex )
{
return BllResultFactory . Error < List < DeviceEntity >>( null , "异常:" + ex . ToString ());
}
}
liufu
authored
7 years ago
741
public BllResult < List < DeviceAddressEntity >> GetAllDeviceAddress ()
liufu
authored
7 years ago
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
{
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 ());
}
}
liufu
authored
7 years ago
771
public BllResult < List < DevicePropEntity >> GetAllDeviceProp ()
liufu
authored
7 years ago
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
{
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 (),
liufu
authored
7 years ago
789
Enable = Convert . ToBoolean ( t [ "enable" ]),
liufu
authored
7 years ago
790
IsMonitor = t [ "isMonitor" ] is DBNull ? null : ( int ?) t [ "isMonitor" ],
liufu
authored
7 years ago
791
792
793
794
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 (),
liufu
authored
7 years ago
795
796
797
798
799
800
801
802
803
}). ToList ();
return BllResultFactory . Sucess < List < DevicePropEntity >>( list , "成功" );
}
catch ( Exception ex )
{
return BllResultFactory . Error < List < DevicePropEntity >>( null , "异常:" + ex . ToString ());
}
}
liufu
authored
7 years ago
804
public BllResult < List < DeviceTypeEntity >> GetAllDeviceType ()
liufu
authored
7 years ago
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
{
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
liufu
authored
7 years ago
834
public BllResult SetLocationPallet ( string locationCode , string palletCode )
liufu
authored
7 years ago
835
836
837
{
try
{
liufu
authored
7 years ago
838
if ( String . IsNullOrEmpty ( locationCode ) || palletCode == null )
liufu
authored
7 years ago
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
{
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 ());
}
}
liufu
authored
7 years ago
859
public BllResult < List < LocationEntity >> GetAllLocations ( String containerCode , string row , string column , string layer , string roadway , string status , string code )
liufu
authored
7 years ago
860
861
862
863
864
865
866
867
868
869
870
871
872
873
{
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 ))
{
liufu
authored
7 years ago
874
sql += " and line =" + column ;
liufu
authored
7 years ago
875
876
877
878
879
880
881
882
883
}
if (! String . IsNullOrEmpty ( layer ))
{
sql += " and layer =" + layer ;
}
if (! String . IsNullOrEmpty ( roadway ))
{
sql += " and roadway =" + roadway ;
}
liufu
authored
7 years ago
884
if (! String . IsNullOrEmpty ( status ) && status != "all" )
liufu
authored
7 years ago
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
{
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" ]),
liufu
authored
7 years ago
905
Line = Convert . ToInt32 ( t [ "line" ]),
liufu
authored
7 years ago
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
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
liufu
authored
7 years ago
924
public BllResult < List < ContainerEntity >> GetAllContainer ( string code , bool isInLocation , bool isPrint )
liufu
authored
7 years ago
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
{
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 (),
liufu
authored
7 years ago
950
Status = t [ "status" ] is DBNull ? "" : t [ "status" ]. ToString (),
liufu
authored
7 years ago
951
952
953
954
955
956
957
958
959
960
961
962
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 ());
}
}
liufu
authored
7 years ago
963
964
965
966
967
968
969
970
/// < summary >
/// todo : 托盘添加
/// </ summary >
/// < param name = "code" ></ param >
/// < param name = "warehouseCode" ></ param >
/// < param name = "warehouseId" ></ param >
/// < param name = "containerTypeId" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
971
public BllResult CreateContainer ( string code , string warehouseCode , int warehouseId , int containerTypeId )
liufu
authored
7 years ago
972
973
974
{
try
{
liufu
authored
7 years ago
975
string sql = $ "insert into container(code ,warehouseId,warehouseCode,containerTypeId,status) values ('{code}',{warehouseId},'{warehouseCode}',{containerTypeId},1)" ;
liufu
authored
7 years ago
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
int i = MySqlHelper . ExecuteNonQuery ( AppCommon . ConnectionString , sql );
if ( i == 0 )
{
return BllResultFactory . Error ( null , "插入失败" );
}
else
{
return BllResultFactory . Sucess ( null , "插入成功" );
}
}
catch ( Exception ex )
{
return BllResultFactory . Error ( null , "异常:" + ex . ToString ());
}
}
liufu
authored
7 years ago
992
public BllResult UpdatePallet ( string code , string print , string status )
liufu
authored
7 years ago
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
{
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
liufu
authored
7 years ago
1034
1035
1036
1037
1038
1039
1040
# region 字符串和 Byte 之间的转化
/// < summary >
/// 数字和字节之间互转
/// </ summary >
/// < param name = "num" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
1041
public int IntToBitConverter ( int num )
liufu
authored
7 years ago
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
{
int temp = 0 ;
byte [] bytes = BitConverter . GetBytes ( num );// 将 int32 转换为字节数组
temp = BitConverter . ToInt32 ( bytes , 0 );// 将字节数组内容再转成 int32 类型
return temp ;
}
/// < summary >
/// 将字符串转为 16 进制字符,允许中文
/// </ summary >
/// < param name = "s" ></ param >
/// < param name = "encode" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
1055
public string StringToHexString ( string s , Encoding encode , string spanString )
liufu
authored
7 years ago
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
{
byte [] b = encode . GetBytes ( s );// 按照指定编码将 string 编程字节数组
string result = string . Empty ;
for ( int i = 0 ; i < b . Length ; i ++)// 逐字节变为 16 进制字符
{
result += Convert . ToString ( b [ i ], 16 ) + spanString ;
}
return result ;
}
/// < summary >
/// 将 16 进制字符串转为字符串
/// </ summary >
/// < param name = "hs" ></ param >
/// < param name = "encode" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
1071
public string HexStringToString ( string hs , Encoding encode )
liufu
authored
7 years ago
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
{
string strTemp = "" ;
byte [] b = new byte [ hs . Length / 2 ];
for ( int i = 0 ; i < hs . Length / 2 ; i ++)
{
strTemp = hs . Substring ( i * 2 , 2 );
b [ i ] = Convert . ToByte ( strTemp , 16 );
}
// 按照指定编码将字节数组变为字符串
return encode . GetString ( b );
}
/// < summary >
/// byte [] 转为 16 进制字符串
/// </ summary >
/// < param name = "bytes" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
1088
public string ByteToHexStr ( byte [] bytes )
liufu
authored
7 years ago
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
{
string returnStr = "" ;
if ( bytes != null )
{
for ( int i = 0 ; i < bytes . Length ; i ++)
{
returnStr += bytes [ i ]. ToString ( "X2" );
}
}
return returnStr ;
}
/// < summary >
/// 将 16 进制的字符串转为 byte []
/// </ summary >
/// < param name = "hexString" ></ param >
/// < returns ></ returns >
liufu
authored
7 years ago
1105
public byte [] StrToHexByte ( string hexString )
liufu
authored
7 years ago
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
{
hexString = hexString . Replace ( " " , "" );
if (( hexString . Length % 2 ) != 0 )
hexString += " " ;
byte [] returnBytes = new byte [ hexString . Length / 2 ];
for ( int i = 0 ; i < returnBytes . Length ; i ++)
returnBytes [ i ] = Convert . ToByte ( hexString . Substring ( i * 2 , 2 ), 16 );
return returnBytes ;
}
liufu
authored
7 years ago
1116
public string ASCIIToString ( short [] ints )
liufu
authored
7 years ago
1117
1118
1119
1120
1121
1122
1123
1124
1125
{
String str = "" ;
foreach ( var item in ints )
{
str += Chr ( item );
}
return str ;
}
liufu
authored
7 years ago
1126
public string Chr ( int asciiCode )
liufu
authored
7 years ago
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
{
if ( asciiCode >= 0 && asciiCode <= 255 )
{
System . Text . ASCIIEncoding asciiEncoding = new System . Text . ASCIIEncoding ();
byte [] byteArray = new byte [] { ( byte ) asciiCode };
string strCharacter = asciiEncoding . GetString ( byteArray );
return ( strCharacter );
}
else
{
throw new Exception ( "ASCII Code is not valid." );
}
}
liufu
authored
7 years ago
1141
public byte [] StringToASCII ( string str )
liufu
authored
7 years ago
1142
1143
1144
1145
{
System . Text . ASCIIEncoding asciiEncoding = new System . Text . ASCIIEncoding ();
return asciiEncoding . GetBytes ( str . PadRight ( 20 , ' ' ));
}
liufu
authored
7 years ago
1146
liufu
authored
7 years ago
1147
public short Asc ( string character )
liufu
authored
7 years ago
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
{
if ( character . Length == 1 )
{
System . Text . ASCIIEncoding asciiEncoding = new System . Text . ASCIIEncoding ();
short intAsciiCode = ( short ) asciiEncoding . GetBytes ( character )[ 0 ];
return ( intAsciiCode );
}
else
{
throw new Exception ( "Character is not valid." );
}
}
liufu
authored
7 years ago
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# endregion
# region Common
public BllResult HeartBeat ()
{
return BllResultFactory . Sucess ( null , "默认实现" );
}
liufu
authored
7 years ago
1173
# endregion
liufu
authored
7 years ago
1174
1175
}
}