jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
737
738
739
740
741
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
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
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
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
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
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
 
using HH.WMS.Entitys.Basic;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using HH.WMS.Entitys.Common;
using HH.WMS.Common;
using HH.MData;
using System.Data.OracleClient;
using HH.WMS.Entitys.Autobom;
using HH.WMS.Entitys;
 
namespace HH.WMS.DAL.Basic
{
    public class TN_WM_LOCATION_EXTDAL : DapperBaseDAL
    {
        #region UPDATE
 
        /// <summary>
        /// 更新贮存状态和货位状态
        /// </summary>
        /// <param name="locationCode">货位编号</param>
        /// <param name="state">货位状态</param>
        /// <param name="useState">贮存状态</param>
        /// <param name="trans">事务</param>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] created 2018-5-18 </History>
        public SqlExecuteResult UpdateStateAndTaskNo(string taskNo, string locationCode, string state, string useState, DbTransaction trans, string currState = "")
        {
            try
            {
                string strSql = @"UPDATE  tn_wm_b_location_ext SET ";
                string strWhere = "";
                if (!string.IsNullOrEmpty(state))
                {
                    strWhere += " CN_S_LOCATION_STATE='" + state + "'";
                    if (state.Equals(Constants.Location_State_Normal))
                    {
                        strWhere += " ,CN_S_TASK_NO='' ";
                    }
                    else
                    {
                        strWhere += " ,CN_S_TASK_NO='" + taskNo + "' ";
                    }
 
                }
                if (!string.IsNullOrEmpty(useState))
                {
                    if (strWhere.Length != 0)
                        strWhere += " ,CN_S_USE_STATE='" + useState + "'";
                    else
                        strWhere += " CN_S_USE_STATE='" + useState + "'";
                }
                strSql += strWhere + " where CN_S_LOCATION_CODE=:CN_S_LOCATION_CODE ";
 
                if (!string.IsNullOrEmpty(currState))
                    strSql += " and CN_S_LOCATION_STATE='" + currState + "'";
 
                DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
                DataAccess.AddInParameter(cmd, "CN_S_LOCATION_CODE", DbType.String, locationCode);
                return ExecuteCommand(cmd, trans);
            }
            catch (Exception ex)
            {
                return new SqlExecuteResult();
            }
        }
 
        #endregion
 
 
        #region 获得可用的货位扩展信息
 
        /// <summary>
        /// 货位数量超过一定长度则分步骤获取
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<TN_WM_LOCATION_EXTEntity> GetLocationExtListBy(string stockCode, List<string> locationCodes, string opType)
        {
            string strSql = @"SELECT CN_S_STOCK_CODE,CN_S_ROW,CN_S_LOCATION_CODE,CN_S_LOCATION_STATE,CN_S_USE_STATE,
                              CN_S_BEF_FAULT_STATE,CN_N_DELIVERY_BEAT 
                              FROM tn_wm_b_location_ext WHERE 1=1 AND CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ";
 
            if (!string.IsNullOrEmpty(stockCode))
            {
                strSql += " AND CN_S_STOCK_CODE='" + stockCode + "' ";
            }
            if (locationCodes != null && locationCodes.Count > 0)
            {
                if (locationCodes.Count == 1)
                {
                    strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                }
                else
                {
                    string locations = string.Join(",", locationCodes).Replace(",", "','");
                    strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                }
            }
            switch (opType)
            {
                case "入库":
                    strSql += " AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "'";
                    break;
                case "入流离库":
                    strSql += " AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Empty + "'";
                    break;
                case "出库":
                    strSql += " AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Full + "'";
                    break;
                default:
                    break;
            }
            List<TN_WM_LOCATION_EXTEntity> list = ExecuteQuery<TN_WM_LOCATION_EXTEntity>(strSql.ToString());
            return list;
        }
        /// <summary>
        /// 获取可用货位的集合,为提高效率,该方法只返回货位编码字段
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<TN_WM_LOCATIONCODE_EXT_Entity> GetLocationCodeListBy(string stockCode, string areaCode, List<string> locationCodes, string areaType)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATIONCODE_EXT_Entity> list = new List<TN_WM_LOCATIONCODE_EXT_Entity>();
 
            strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE
                              FROM tn_wm_b_location_ext WHERE 1=1 AND CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ";
 
            if (!string.IsNullOrEmpty(stockCode))
            {
                strSql += " AND CN_S_STOCK_CODE='" + stockCode + "' ";
            }
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql += " AND CN_S_AREA_CODE='" + areaCode + "' ";
            }
            if (locationCodes != null && locationCodes.Count > 0)
            {
                if (locationCodes.Count == 1)
                {
                    strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                }
                else
                {
                    string locations = string.Join(",", locationCodes).Replace(",", "','");
                    strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                }
            }
            switch (areaType)
            {
                case "平库":
                    strSql += " AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "'";
                    break;
                case "立库":
                    strSql += " AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "'";
                    break;
                case "流离式":
                    strSql += " AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Empty + "')";
                    break;
                default:
                    break;
            }
            Log.AlgorInfo("InAssign-GetLocationCodeExtListBy", "获取货位扩展表中可用货位的sql语句:" + strSql);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql);
            list = ExecuteQuery<TN_WM_LOCATIONCODE_EXT_Entity>(strSql.ToString());
 
            return list;
 
        }
 
        public List<TN_WM_LOCATIONCODE_EXT_Entity> GetLocationCodeListByLocationCode(List<string> locationCodes)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATIONCODE_EXT_Entity> list = new List<TN_WM_LOCATIONCODE_EXT_Entity>();
 
            strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE,CN_S_ROW,CN_S_COL
                              FROM tn_wm_b_location_ext WHERE 1=1  ";
 
       
            if (locationCodes != null && locationCodes.Count > 0)
            {
                if (locationCodes.Count == 1)
                {
                    strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                }
                else
                {
                    string locations = string.Join(",", locationCodes).Replace(",", "','");
                    strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                }
            }
       
            Log.AlgorInfo("InAssign-GetLocationCodeExtListBy", "获取货位扩展表中可用货位的sql语句:" + strSql);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql);
            list = ExecuteQuery<TN_WM_LOCATIONCODE_EXT_Entity>(strSql.ToString());
 
            return list;
 
        }
        #region 获取库区中包含某物料的货位
        /// <summary>
        /// 获取出入库锁定的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetLocationByItemCode(string itemCode, string itemState, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT CN_S_LOCATION_CODE,CN_S_ROW,CN_S_COL,CN_S_FLOOR   FROM  ");
            strSql.AppendLine("  tn_wm_b_location_ext  ");
            strSql.AppendLine(" WHERE  CN_S_LOCATION_STATE='正常' AND CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND CN_S_AREA_CODE = '" + areaCode + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
 
            return list;
 
        }
        #endregion
        #region 获取库区中包含某物料的货位
        /// <summary>
        /// 获取出入库锁定的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetLocationByInLockYM(string itemCode, string itemState, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT CN_S_LOCATION_CODE,CN_S_ROW,CN_S_COL,CN_S_FLOOR   FROM  ");
            strSql.AppendLine("  tn_wm_b_location_ext  ");
            strSql.AppendLine(" WHERE  CN_S_LOCATION_STATE = '预入库锁定' ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND CN_S_AREA_CODE = '" + areaCode + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
 
            return list;
 
        }
        #endregion
        /// <summary>
        /// 获取可用货位的集合,为提高效率,该方法只返回货位编码字段
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<TN_WM_LOCATION_EXTEntity> GetLocationCodeExtListBy(string stockCode, string areaCode, List<string> locationCodes, string opType)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATION_EXTEntity> list = new List<TN_WM_LOCATION_EXTEntity>();
            try
            {
                strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE
                              FROM tn_wm_b_location_ext WHERE  CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ";
 
                if (!string.IsNullOrEmpty(stockCode))
                {
                    strSql += " AND CN_S_STOCK_CODE='" + stockCode + "' ";
                }
                if (!string.IsNullOrEmpty(areaCode))
                {
                    strSql += " AND CN_S_AREA_CODE='" + areaCode + "' ";
                }
                if (locationCodes != null && locationCodes.Count > 0)
                {
                    if (locationCodes.Count == 1)
                    {
                        strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                    }
                    else
                    {
                        string locations = string.Join(",", locationCodes).Replace(",", "','");
                        strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                    }
                }
                switch (opType)
                {
                    case "入库":
                        strSql += " AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "'";
                        break;
                    case "入流离库":
                        strSql += " AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Empty + "')";
                        break;
                    case "出库":
                        strSql += " AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Full + "')";
                        break;
                    default:
                        break;
                }
                Log.AlgorInfo("GetTrueLocationCodes", strSql);
                list = ExecuteQuery<TN_WM_LOCATION_EXTEntity>(strSql.ToString());
            }
            catch (Exception ex)
            {
 
            }
            return list;
 
        }
 
        public List<TN_WM_LOCATION_EXTEntity> GetLocationCreateTime(List<string> locationCodes)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATION_EXTEntity> list = new List<TN_WM_LOCATION_EXTEntity>();
            try
            {
                strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE,CN_T_CREATE
                              FROM tn_wm_b_location_ext WHERE  CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ";
 
   
                if (locationCodes != null && locationCodes.Count > 0)
                {
                    if (locationCodes.Count == 1)
                    {
                        strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                    }
                    else
                    {
                        string locations = string.Join(",", locationCodes).Replace(",", "','");
                        strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                    }
                }
                Log.AlgorInfo("GetLocationCreateTime", strSql);
                list = ExecuteQuery<TN_WM_LOCATION_EXTEntity>(strSql.ToString());
            }
            catch (Exception ex)
            {
 
            }
            return list;
 
        }
 
        #endregion
 
        #region 出入库计算货位时修改货位状态
        /// <summary>
        /// 出入库计算货位时修改货位状态
        /// </summary>
        /// <param name="locationCode"></param>
        /// <param name="state"></param>
        /// <param name="opType"></param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public SqlExecuteResult UpdateLocationState(string locationCode, string state, string opType, DbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("UPDATE tn_wm_b_location_ext SET CN_S_LOCATION_STATE=:CN_S_LOCATION_STATE ");
            strSql.AppendLine("WHERE CN_S_LOCATION_CODE=:CN_S_LOCATION_CODE ");
            switch (opType)
            {
                case "入库":
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ");
                    strSql.AppendLine(" AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "' ");
                    break;
                case "入库回滚":
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + Constants.Location_State_InLock + "' ");
                    strSql.AppendLine(" AND CN_S_USE_STATE = '" + Constants.Use_State_Empty + "' ");
                    break;
                case "补料":
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ");
                    strSql.AppendLine(" AND CN_S_USE_STATE = '" + Constants.Use_State_Full + "' ");
                    break;
                case "补料回滚":
                    strSql.AppendLine("  ");
                    break;
                case "出库":
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + Constants.Location_State_Normal + "' ");
                    strSql.AppendLine(" AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Full + "') ");
                    break;
                case "出库回滚":
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + Constants.Location_State_OutLock + "' ");
                    strSql.AppendLine(" AND (CN_S_USE_STATE='" + Constants.Use_State_NoFull + "' or CN_S_USE_STATE='" + Constants.Use_State_Full + "') ");
                    break;
                default:
                    break;
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            DataAccess.AddInParameter(cmd, "CN_S_LOCATION_CODE", ComDbType.STRING, locationCode);
            DataAccess.AddInParameter(cmd, "CN_S_LOCATION_STATE", ComDbType.STRING, state);
            return ExecuteCommand(cmd, trans);
        }
        #endregion
 
        /// <summary>
        /// 根据巷道获取巷道内的货位状态
        /// </summary>
        /// <param name="stockCode">仓库号</param>
        /// <param name="areaCode">库区号</param>
        /// <param name="roadway">巷道号</param>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] created 2018/12/03</History>
        public DataTable ViewState(string stockCode, string areaCode, string roadway)
        {
            string sql = @"SELECT CN_S_LOCATION_CODE,CN_S_FLOOR,CN_S_COL,CN_S_ROW,
                            VIEW_STATE = case CN_S_LOCATION_STATE
                                when '正常' then 
                                    case CN_S_USE_STATE
                                        when '满' then '满'
                                        when '空' then '空'
                                        when '不满' then '不满'
                                    end
                                else CN_S_LOCATION_STATE 
                            end
                            FROM tn_wm_b_location_ext WHERE CN_S_STOCK_CODE=@CN_S_STOCK_CODE 
            and CN_S_AREA_CODE=@CN_S_AREA_CODE ";
 
            if (!string.IsNullOrEmpty(roadway))
            {
                sql += "and CN_S_ROADWAY in('" + roadway.Replace(",", "','") + "')";
            }
 
            return ExecuteDataTable(sql, new
            {
                CN_S_STOCK_CODE = stockCode,
                CN_S_AREA_CODE = areaCode,
            });
        }
 
        public DataTable ViewStateByAreaCode(string stockCode, string areaCodes, string roadway)
        {
            string sql = string.Format(@"SELECT CN_S_LOCATION_CODE,CN_S_FLOOR,CN_S_COL,CN_S_ROW,
                            VIEW_STATE = case CN_S_LOCATION_STATE
                                when '正常' then 
                                    case CN_S_USE_STATE
                                        when '满' then '满'
                                        when '空' then '空'
                                        when '不满' then '不满'
                                    end
                                else CN_S_LOCATION_STATE 
                            end
                            FROM tn_wm_b_location_ext WHERE CN_S_STOCK_CODE='{0}'
            and CN_S_AREA_CODE IN ('{1}') ", stockCode, areaCodes.Replace(",", "','"));
 
            if (!string.IsNullOrEmpty(roadway))
            {
                sql += "and CN_S_ROADWAY in('" + roadway.Replace(",", "','") + "')";
            }
            
            return ExecuteDataTable(sql);
        }
 
        public List<TN_WM_LOCATION_EXTEntity> GetModel(string strWhere)
        {
            string sql = @" SELECT * FROM TN_WM_B_LOCATION_EXT " + strWhere;
            return ExecuteQuery<TN_WM_LOCATION_EXTEntity>(sql);
        }
        public List<TN_WM_LOCATION_EXTEntity> GetModelByRow(string strRow,string strArea)
        {
            string sql = @" SELECT * FROM TN_WM_B_LOCATION_EXT WHERE CN_S_ROW = '" + strRow +"'" + " AND CN_S_AREA_CODE = '"+ strArea +"' ";
            return ExecuteQuery<TN_WM_LOCATION_EXTEntity>(sql);
        }
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="CN_GUID"></param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public SqlExecuteResult Delete(string Where, DbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();
            string sql = @" delete  from tn_wm_b_location_ext " + Where;
            DbCommand cmd = DataAccess.GetSqlStringCommand(sql);
            return ExecuteCommand(cmd, trans);
        }
        #endregion
 
        public SqlExecuteResult UpdateSync(TN_WM_LOCATION_EXTEntity entity, DbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" UPDATE tn_wm_b_location_ext SET ");
            strSql.Append(" CN_S_AREA_CODE = @CN_S_AREA_CODE,");
            if (!string.IsNullOrEmpty(entity.CN_S_LOCATION_STATE))
                strSql.Append(" CN_S_LOCATION_STATE = @CN_S_LOCATION_STATE,");
            strSql.Append(" CN_S_ROADWAY = @CN_S_ROADWAY");
            strSql.Append(" where CN_S_STOCK_CODE=@CN_S_STOCK_CODE");
            strSql.Append(" and CN_S_LOCATION_CODE=@CN_S_LOCATION_CODE");
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            DataAccess.AddInParameter(cmd, "CN_S_AREA_CODE", DbType.String, entity.CN_S_AREA_CODE);
            DataAccess.AddInParameter(cmd, "CN_S_ROADWAY", DbType.String, entity.CN_S_ROADWAY);
            DataAccess.AddInParameter(cmd, "CN_S_STOCK_CODE", DbType.String, entity.CN_S_STOCK_CODE);
            DataAccess.AddInParameter(cmd, "CN_S_LOCATION_CODE", DbType.String, entity.CN_S_LOCATION_CODE);
            if (!string.IsNullOrEmpty(entity.CN_S_LOCATION_STATE))
                DataAccess.AddInParameter(cmd, "CN_S_LOCATION_STATE", DbType.String, entity.CN_S_LOCATION_STATE);
            return ExecuteCommand(cmd, trans);
        }
 
        public SqlExecuteResult UpdateBFState(string where, string tableName, DbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();
            string sql = "";
            if (!string.IsNullOrEmpty(tableName))
            {
                sql = @" UPDATE " + tableName + " SET CN_S_LOCATION_STATE='报废' " + where;
            }
            else
            {
                sql = @" UPDATE " + "TN_WM_B_LOCATION_EXT" + " SET CN_S_LOCATION_STATE='报废' " + where;
            }
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(sql);
            return ExecuteCommand(cmd, trans);
        }
 
        /// <summary>
        /// 更新货位扩展表
        /// </summary>
        /// <param name="locationCode">货位编码</param>
        /// <param name="locationState">货位状态</param>
        /// <param name="locationUseState">贮存状态</param>
        /// <param name="taskNo">任务编号</param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public OperateResult UpdateLocationExtState(string locationCode, string locationState, string bLocationState, string taskNo, IDbTransaction trans)
        {
            OperateResult result = new OperateResult();
            try
            {
                if (string.IsNullOrEmpty(locationState) && string.IsNullOrEmpty(bLocationState) && string.IsNullOrEmpty(taskNo))
                    return OperateResult.Error("更新参数缺失!");
 
                StringBuilder strSql = new StringBuilder();
                strSql.AppendLine("UPDATE TN_WM_B_LOCATION_EXT SET CN_T_CREATE =CN_T_CREATE ");
                if (!string.IsNullOrEmpty(locationState))
                {
                    strSql.AppendLine(" ,CN_S_LOCATION_STATE='" + locationState + "' ");
                }
                if (!string.IsNullOrEmpty(taskNo))
                {
                    strSql.AppendLine(" ,CN_S_TASK_NO='" + taskNo + "' ");
                }
                strSql.AppendLine("WHERE CN_S_LOCATION_CODE='" + locationCode + "' ");
 
                if (!string.IsNullOrEmpty(bLocationState))
                {
                    strSql.AppendLine(" AND CN_S_LOCATION_STATE='" + bLocationState + "' ");
                }
                result = ExecuteTranSql(strSql.ToString(), null, trans);
            }
            catch(Exception ex)
            {
                result = OperateResult.Error(ex.Message);
            }
            return result;
        }
  
 
        public OperateResult UpdateStateByTrayCode(string trayCode, string locationState, string useState, IDbTransaction trans)
        {
            if (string.IsNullOrEmpty(trayCode))
            {
                return OperateResult.Error("更新参数缺失!");
            }
 
            if (string.IsNullOrEmpty(locationState) && string.IsNullOrEmpty(useState))
            {
                return OperateResult.Error("更新参数缺失!");
            }
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("UPDATE TN_WM_B_LOCATION_EXT SET CN_T_CREATE =CN_T_CREATE ");
            if (!string.IsNullOrEmpty(locationState))
            {
                strSql.AppendLine(" ,CN_S_LOCATION_STATE='" + locationState + "' ");
            }
            if (!string.IsNullOrEmpty(useState))
            {
                strSql.AppendLine(" ,CN_S_USE_STATE='" + useState + "' ");
            }
            strSql.AppendLine(" WHERE CN_S_LOCATION_CODE IN (SELECT CN_S_LOCATION_CODE FROM tn_wm_b_tray_location WHERE CN_S_TRAY_CODE='" + trayCode + "')");
            return ExecuteTranSql(strSql.ToString(), null, trans);
        }
 
        /// <summary>
        /// 更新货位扩展表
        /// </summary>
        /// <param name="locationCode">货位编码</param>
        /// <param name="locationState">货位状态</param>
        /// <param name="locationUseState">贮存状态</param>
        /// <param name="taskNo">任务编号</param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public OperateResult UpdateLocationExtStateLock(string locationCode, string locationState, string locationBeforeState, string locationUseState, string taskNo, IDbTransaction trans)
        {
            if (string.IsNullOrEmpty(locationState) && string.IsNullOrEmpty(locationUseState) && string.IsNullOrEmpty(taskNo))
                return OperateResult.Error("更新参数缺失!");
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("UPDATE TN_WM_B_LOCATION_EXT SET CN_T_CREATE =CN_T_CREATE ");
            if (!string.IsNullOrEmpty(locationState))
            {
                strSql.AppendLine(" ,CN_S_LOCATION_STATE='" + locationState + "' ");
            }
            if (!string.IsNullOrEmpty(locationUseState))
            {
                strSql.AppendLine(" ,CN_S_USE_STATE='" + locationUseState + "' ");
            }
            if (!string.IsNullOrEmpty(taskNo))
            {
                strSql.AppendLine(" ,CN_S_TASK_NO='" + taskNo + "' ");
            }
            strSql.AppendLine("WHERE CN_S_LOCATION_CODE='" + locationCode + "' ");
            if (!string.IsNullOrEmpty(locationBeforeState))
            {
                strSql.AppendLine("  AND CN_S_LOCATION_STATE='" + locationBeforeState + "' ");
            }
            return ExecuteTranSql(strSql.ToString(), null, trans);
        }
 
 
 
        #region 查询货位拓展表
        /// <summary>
        /// 查询货位拓展表
        /// </summary>
        /// <param name="searchModel">实体</param>
        /// <returns></returns>
        /// <History>[HANHE(lt)] CREATED BY 2018-12-18</History>
        public OperateResult GetLocationExtList(SearchModel searchModel)
        {
            var condition = searchModel.SearchCondition;
            string ConStr = "where 1=1 ";
            if (condition != null)
            {
                if (!string.IsNullOrEmpty(condition.CN_S_LOCATION_CODE.ToString()))
                {
                    ConStr = ConStr + " and CN_S_LOCATION_CODE like '%" + condition.CN_S_LOCATION_CODE + "%'";
                }
                if (!string.IsNullOrEmpty(condition.CN_S_AREA_CODE.ToString()))
                {
                    ConStr = ConStr + " and CN_S_AREA_CODE = '" + condition.CN_S_AREA_CODE + "'";
                }
 
            }
            string sql = @"(SELECT * FROM TN_WM_B_LOCATION_EXT) T " + ConStr;
 
            OperateResult result = new OperateResult();
 
            return ExecutePagingResult(sql, searchModel.PageIndex, searchModel.PageSize, "", "");
        }
        #endregion
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stockCode"></param>
        /// <returns></returns>
        public DataTable GetAreaStorageInfo(string stockCode, string[] areas)
        {
            string sql = @"  select CN_S_AREA_CODE,ISNULL([不满],0) 不满,ISNULL([空],0) 空,ISNULL([满],0) 满 from (select CN_S_AREA_CODE,COUNT(CN_S_LOCATION_CODE) SumLocation,CN_S_USE_STATE from tn_wm_b_location_ext ";
            if (!string.IsNullOrEmpty(stockCode))
                sql += " where CN_S_STOCK_CODE='" + stockCode + "' ";
            if (!string.IsNullOrEmpty(stockCode) && areas.Length > 0)
                sql += " and CN_S_AREA_CODE in ('" + string.Join("','", areas) + "')";
            else
                sql += " WHERE CN_S_AREA_CODE in ('" + string.Join("','", areas) + "')";
            sql += @"group by CN_S_AREA_CODE,CN_S_USE_STATE ) k
                            PIVOT 
                            (
                                SUM(SumLocation)  FOR 
                                k.CN_S_USE_STATE IN ([不满],[空],[满])
                            ) AS T ";
 
            return ExecuteDataTable(sql);
        }
 
        public List<TN_WM_LOCATION_EXTEntity> GetLocationList()
        {
            string sql = @" SELECT * FROM TN_WM_B_LOCATION_EXT ";
            return ExecuteQuery<TN_WM_LOCATION_EXTEntity>(sql);
        }
 
        public OperateResult UpdateLocationUseState(List<ImportTemplateEntity> InitEntity, string useState, IDbTransaction trans)
        {
            string sql = "UPDATE TN_WM_B_LOCATION_EXT SET CN_S_USE_STATE='{0}' WHERE CN_S_LOCATION_CODE=@CN_S_LOCATION_CODE ";
            sql = string.Format(sql, useState);
            return ExecuteTranSql(sql, InitEntity, trans);
        }
 
        public DataTable GetStateQty(string stockCode)
        {
            string sql = @"select RTRIM(CN_S_ROADWAY) CN_S_ROADWAY,RTRIM(CN_S_LOCATION_STATE) CN_S_LOCATION_STATE,COUNT(CN_S_LOCATION_STATE) QTY from (
                        SELECT case when CN_S_LOCATION_STATE='正常'
                              then CN_S_USE_STATE
                              else CN_S_LOCATION_STATE
                              end CN_S_LOCATION_STATE,CN_S_ROADWAY
                          FROM tn_wm_b_location_ext where CN_S_STOCK_CODE='{0}') t
                          group by CN_S_ROADWAY,CN_S_LOCATION_STATE";
 
            sql = string.Format(sql, stockCode);
            return ExecuteDataTable(sql);
        }
 
        public OperateResult UpdateLocationByCode(string locationCode, string state, IDbTransaction trans)
        {
            string sql = "UPDATE TN_WM_B_LOCATION_EXT SET CN_S_USE_STATE='{1}' WHERE CN_S_LOCATION_CODE like '%{0}%' ";
            sql = string.Format(sql, locationCode, state);
            return ExecuteTranSql(sql, null, trans);
        }
 
 
        public OperateResult UpdateLocationByListCode(List<string> list, string state, IDbTransaction trans)
        {
            OperateResult result = new OperateResult();
            foreach (var locationCode in list)
            {
                string sql = "UPDATE TN_WM_B_LOCATION_EXT SET CN_S_USE_STATE='{1}' WHERE CN_S_LOCATION_CODE like '%{0}%' ";
                sql = string.Format(sql, locationCode, state);
                result = ExecuteTranSql(sql, null, trans);
            }
            return result;
        }
 
        public SqlExecuteResult UpdateLocationNormal(string locationCodeS, string state, DbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine("UPDATE tn_wm_b_location_ext SET CN_S_LOCATION_STATE=@CN_S_LOCATION_STATE ");
            strSql.AppendLine("WHERE CN_S_LOCATION_CODE IN  IN (" + locationCodeS + ")");
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            DataAccess.AddInParameter(cmd, "CN_S_LOCATION_STATE", ComDbType.STRING, state);
            return ExecuteCommand(cmd, trans);
        }
 
        /// <summary>
        /// 释放任务起点
        /// </summary>
        /// <param name="taskNo">任务号</param>
        /// <param name="stratBit">起点</param>
        /// <param name="trans">事务</param>
        /// <History>[Hanhe(DBS)] created 2019/3/12</History>
        public OperateResult UnLockTaskStartBit(string taskNo, string stratBit, IDbTransaction trans)
        {
            string sql = @"update tn_wm_b_location_ext SET CN_S_LOCATION_STATE=@CN_S_LOCATION_STATE,CN_S_USE_STATE=@CN_S_USE_STATE,CN_S_TASK_NO=''
                        WHERE CN_S_LOCATION_CODE=@CN_S_LOCATION_CODE and CN_S_TASK_NO=@CN_S_TASK_NO";
            return ExecuteTranSql(sql, new
            {
                CN_S_LOCATION_STATE = Constants.Location_State_Normal,
                CN_S_USE_STATE = Constants.Use_State_Empty,
                CN_S_LOCATION_CODE = stratBit,
                CN_S_TASK_NO = taskNo
            }, trans);
        }
 
        /// <summary>
        /// 释放任务结束点
        /// </summary>
        /// <param name="taskNo">任务号</param>
        /// <param name="endBit">终点</param>
        /// <param name="trans">事务</param>
        /// <History>[Hanhe(DBS)] created 2019/3/12</History>
        public OperateResult UnLockTaskEndBit(string taskNo, string endBit, IDbTransaction trans)
        {
            string sql = @"update tn_wm_b_location_ext SET CN_S_LOCATION_STATE=@CN_S_LOCATION_STATE,CN_S_USE_STATE=@CN_S_USE_STATE,CN_S_TASK_NO=''
                        WHERE CN_S_LOCATION_CODE=@CN_S_LOCATION_CODE and CN_S_TASK_NO=@CN_S_TASK_NO";
            return ExecuteTranSql(sql, new
            {
                CN_S_LOCATION_STATE = Constants.Location_State_Normal,
                CN_S_USE_STATE = Constants.Use_State_Full,
                CN_S_LOCATION_CODE = endBit,
                CN_S_TASK_NO = taskNo
            }, trans);
        }
 
        #region 更新货位状态(由货位编号、货位状态)
 
        public OperateResult UpdateLocationStateByCodeAndState(string locationCode, string beforeLocationState, string afterLocationState, IDbTransaction trans)
        {
            string sql = " UPDATE tn_wm_b_location_ext SET CN_S_LOCATION_STATE = '" + beforeLocationState + "'  WHERE CN_S_LOCATION_CODE='" + locationCode + "'  AND CN_S_LOCATION_STATE = '" + afterLocationState + "' ";
            return ExecuteTranSql(sql, null, trans);
        }
 
        #endregion
 
        #region 获取出入库锁定的货位
        /// <summary>
        /// 获取出入库锁定的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<TN_WM_LOCATIONCODE_EXT_Entity> GetLockLocationByState(string stockCode, string areaCode, List<string> locationCodes, string locState)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATIONCODE_EXT_Entity> list = new List<TN_WM_LOCATIONCODE_EXT_Entity>();
 
            strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE, CN_S_ROW, CN_S_COL, CN_S_FLOOR
                              FROM tn_wm_b_location_ext WHERE 1=1 AND CN_S_LOCATION_STATE='" + locState + "' ";
 
            if (!string.IsNullOrEmpty(stockCode))
            {
                strSql += " AND CN_S_STOCK_CODE='" + stockCode + "' ";
            }
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql += " AND CN_S_AREA_CODE='" + areaCode + "' ";
            }
            if (locationCodes != null && locationCodes.Count > 0)
            {
                if (locationCodes.Count == 1)
                {
                    strSql += " AND CN_S_LOCATION_CODE = '" + locationCodes[0] + "' ";
                }
                else
                {
                    string locations = string.Join(",", locationCodes).Replace(",", "','");
                    strSql += " AND CN_S_LOCATION_CODE in ('" + locations + "') ";
                }
            }
            list = ExecuteQuery<TN_WM_LOCATIONCODE_EXT_Entity>(strSql);
 
            return list;
 
        }
        #endregion
        #region 获取库区中包含某物料的货位
        /// <summary>
        /// 获取出入库锁定的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetLocationByItemCode(string itemCode, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_LOCATION_CODE,TB2.CN_S_ROW,TB2.CN_S_COL,TB2.CN_S_FLOOR   FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine("  INNER JOIN tn_wm_b_location_ext TB2 on B.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
 
         
    
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND B.CN_S_STOCK_AREA = '" + areaCode + "' ");
            }
            //追加查询条件
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCode + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
 
            return list;
 
        }
        #endregion
        #region 查找该库区中即将要存放该物料的货位
        /// <summary>
        /// 查找该库区中即将要存放该物料的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetInTaskLocationByItemCode(string itemCode, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_END_BIT AS CN_S_LOCATION_CODE,TB2.CN_S_ROW,TB2.CN_S_COL,TB2.CN_S_FLOOR   FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_TASK B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine("  INNER JOIN tn_wm_b_location_ext TB2 on B.CN_S_END_BIT=TB2.CN_S_LOCATION_CODE ");
 
            strSql.AppendLine(" WHERE  B.CN_S_STATE IN ('未执行','执行中','取货完成','卸货完成')   ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND B.CN_S_END_AREA = '" + areaCode + "' ");
            }
            //追加查询条件
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCode + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetInTaskLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
            return list;
 
        }
        #endregion
        #region 华凯 获取库区中包含某物料和批次的货位
        /// <summary>
        /// 获取出入库锁定的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetLocationByItemCodeAndLotNo(string itemCode,string lotNo, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_LOCATION_CODE,TB2.CN_S_ROW,TB2.CN_S_COL,TB2.CN_S_FLOOR   FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_B_TRAY_ITEM_DTL C ON A.CN_GUID = C.CN_PARENT_GUID ");
            strSql.AppendLine(" INNER JOIN dbo.tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine("  INNER JOIN tn_wm_b_location_ext TB2 on B.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND B.CN_S_STOCK_AREA = '" + areaCode + "' ");
            }
            //追加查询条件
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCode + "' ");
            }
            if (!string.IsNullOrEmpty(lotNo))
            {
                strSql.AppendLine(" AND C.CN_S_PRODUCTION_BATCH = '" + lotNo + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
 
            return list;
 
        }
        #endregion
        #region 华凯 查找该库区中即将要存放该物料和批次的货位
        /// <summary>
        /// 查找该库区中即将要存放该物料的货位
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="locationCodes"></param>
        /// <param name="opType"></param>
        /// <returns></returns>
        public List<AutoBomLocationAbbreEntity> GetInTaskLocationByItemCodeAndLotNo(string itemCode, string lotNo, string areaCode)
        {
 
            List<AutoBomLocationAbbreEntity> list = new List<AutoBomLocationAbbreEntity>();
 
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_END_BIT AS CN_S_LOCATION_CODE,TB2.CN_S_ROW,TB2.CN_S_COL,TB2.CN_S_FLOOR   FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_B_TRAY_ITEM_DTL C ON A.CN_GUID = C.CN_PARENT_GUID ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_TASK B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine("  INNER JOIN tn_wm_b_location_ext TB2 on B.CN_S_END_BIT=TB2.CN_S_LOCATION_CODE ");
 
            strSql.AppendLine(" WHERE  B.CN_S_STATE IN ('未执行','执行中','取货完成','卸货完成')   ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" AND B.CN_S_END_AREA = '" + areaCode + "' ");
            }
            //追加查询条件
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCode + "' ");
            }
            if (!string.IsNullOrEmpty(lotNo))
            {
                strSql.AppendLine(" AND C.CN_S_PRODUCTION_BATCH = '" + lotNo + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("GetInTaskLocationByItemCode", "sql语句为:" + strSql.ToString());
            list = ExecuteQuery<AutoBomLocationAbbreEntity>(strSql.ToString());
            return list;
 
        }
        #endregion
        #region 检验区按排下达任务
        public List<TN_WM_LOCATION_EXTEntity> GetLocationByRow(string rowNo)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATION_EXTEntity> list = new List<TN_WM_LOCATION_EXTEntity>();
 
            strSql = @"SELECT RTRIM(CN_S_LOCATION_CODE) AS CN_S_LOCATION_CODE,CN_S_LOCATION_STATE,CN_S_USE_STATE,CN_S_COL
                              FROM tn_wm_b_location_ext WHERE  CN_S_ROW ='" + rowNo + "' order by CN_S_COL desc";
            list = ExecuteQuery<TN_WM_LOCATION_EXTEntity>(strSql.ToString());
            return list;
        }
        public List<TN_WM_LOCATION_EXTEntity> GetLocationByArea(string areaCode)
        {
            string strSql = string.Empty;
            List<TN_WM_LOCATION_EXTEntity> list = new List<TN_WM_LOCATION_EXTEntity>();
 
            strSql = @"SELECT DISTINCT CN_S_ROW
                              FROM tn_wm_b_location_ext WHERE  CN_S_AREA_CODE ='" + areaCode + "' ";
            list = ExecuteQuery<TN_WM_LOCATION_EXTEntity>(strSql.ToString());
            return list;
        }
        #endregion
 
 
    }
}