333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
using logtxtWrite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wcftest.EnumDefine;
using wcftest.orm;
 
//库位高度 逻辑变动 备份 【EditBy shaocx,2022-10-19】
//namespace wcftest.BussinessExtension.Handle
//{
//    /// <summary>
//    /// 寻找空库位的帮助类
//    /// </summary>
//    public class FindEmptyLocationHandler
//    {
//        /// <summary>
//        /// 获取预留库位数
//        /// </summary>
//        /// <param name="areaCode"></param>
//        /// <param name="position"></param>
//        /// <param name="containerType"></param>
//        /// <param name="restrictNumber"></param>
//        public static void GetRestrictNumber(int areaCode, Base_Position position, int containerType, ref int restrictNumber)
//        {
//            if (position == null)
//            {
//                return;
//            }
//            bool isNeedRestrictNumber = false;//是否需要预留库位给空托盘
//            //小托盘
//            //restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
//            //restrict.Add(" and  (RowCode=1 or RowCode=11 )");
//            int i_rowCode = Convert.ToInt32(position.RowCode);
//            int i_columnCode = Convert.ToInt32(position.ColumnCode);
//            if (areaCode == 1)
//            {//库区1
//                if (i_rowCode == 1 || i_rowCode == 11)
//                {
//                    isNeedRestrictNumber = true;
//                }
//            }
 
//            //大托盘
//            //restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
//            //restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
//            if (areaCode == 2 && containerType == 2)
//            {
//                if ((i_rowCode == 1 || i_rowCode == 13 || i_rowCode == 14) && (i_columnCode < 2 || i_columnCode > 9))
//                {
//                    isNeedRestrictNumber = true;
//                }
//            }
 
//            //处理
//            if (isNeedRestrictNumber)
//            {
//                restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
//            }
//        }
 
//        #region 分配库位(重要!!!!!!!)
 
//        /// <summary>寻找目标库位
//        /// 寻找目标库位
//        /// </summary>
//        ///  <param name="plcTaskId">PLC任务号</param>
//        /// <param name="continerType">托盘类型</param>
//        /// <param name="sysHeight">系统判断的高度</param>
//        /// <param name="checkHeight">光电检测的高度</param>
//        /// <returns></returns>
//        public static string toPlace(int plcTaskId, int continerType, int sysHeight, int checkHeight, ref string findEmptyReason, int wmsTaskId)
//        {
//            //height值说明 小托盘入口检测值是1-6,到1号堆垛机要转换成1-2,到2号堆垛机要转换成1-4,大托盘是对应的直接使用
//            string toplace = "";
//            findEmptyReason = "";
//            if (Form1.single.WaitOne())//增加线程锁防止并发
//            {
//                bool isInMoreHighPosition = false;
//                try
//                {
//                    using (dbModel mod = new dbModel())
//                    {
//                        Purchase_Shelve shelveOrder = null;
//                        Purchase_ShelveList shelveList = null;
 
//                        //修复 [EditBy shaocx,2022-04-18]
//                        //Task_Queue task = mod.Task_Queue.Find(taskId);
//                        Task_Queue task = null;
//                        if (wmsTaskId != 0)
//                        {
//                            task = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId && x.Task_Id == wmsTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
//                        }
//                        else
//                        {//注意:后期稳定后,必须要求wmsTaskId大于0!!!【EditBy shaocx,2022-09-22】
//                            task = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
//                        }
//                        if (task != null)
//                        {
//                            int shelveid = (int)task.Bill_Id;
//                            shelveList = mod.Purchase_ShelveList.Where(x => x.Shelve_Id == shelveid).FirstOrDefault();
//                            shelveOrder = mod.Purchase_Shelve.Find(shelveid);
 
//                            //注意:如果已经找到了该任务,就直接返回该任务的目标位置,不需要再进行查找新库位了 [EditBy shaocx,2022-09-22]
//                            if ((task.TaskStatus == "未下发" || task.TaskStatus == "已下发" || task.TaskStatus == "下发中")
//                                && !string.IsNullOrEmpty(task.ToPositionName) && task.ToPositionName != "0")
//                            {
//                                return task.ToPositionName;
//                            }
//                        }
//                        else
//                        {//没有找到任务号,就报错 【EditBy shaocx,2022-09-22】
//                            findEmptyReason = "根据PLC号" + plcTaskId + ",wms任务号:" + wmsTaskId + ",没有找到任务数据";
//                            return "";
//                        }
 
//                        List<Base_Equipment> srmIsOk = mod.Base_Equipment.Where(x => x.DeviceType == "堆垛机").ToList();
//                        int areaCode = 0;//库区,如果等于0,表示两台堆垛机都没有禁用,如果等于1,表示2号堆垛机被禁用,如果等于2,表示1号堆垛机被禁用
//                        bool srmOne = true;
//                        bool srmTwo = true;
 
//                        #region 使用事务 [EditBy shaocx,2022-09-22]
//                        using (var trans = mod.Database.BeginTransaction())
//                        {
//                            bool transBool = true;
//                            try
//                            {
//                                #region 判断堆垛机是否禁用 来设置库区
//                                if (srmIsOk != null)
//                                {
//                                    #region 查询堆垛机是否可用
//                                    foreach (var item in srmIsOk)
//                                    {
//                                        if (item.DeviceCode == "1")
//                                        {
//                                            if (item.Enable == 0)
//                                            {
//                                                srmOne = false;
//                                            }
//                                        }
//                                        if (item.DeviceCode == "2")
//                                        {
//                                            if (item.Enable == 0)
//                                            {
//                                                srmTwo = false;
//                                            }
//                                        }
//                                    }
//                                    #endregion
//                                    if (srmOne == false && srmTwo == false)
//                                    {
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, " 类名:Form1/函数名:toPlace 码盘上架,两台堆垛机已禁用无法分配库位,任务ID: ");
//                                        return "";
//                                    }
//                                    if (srmOne == false)
//                                    {
//                                        areaCode = 2;
//                                    }
//                                    if (srmTwo == false)
//                                    {
//                                        areaCode = 1;
//                                    }
//                                }
//                                else
//                                {
//                                    findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,读取堆垛机设置失败,任务ID: ");
//                                    return "";
//                                }
//                                #endregion
 
//                                #region 大托盘入库
//                                if (continerType == 2)
//                                {
//                                    if (areaCode == 1)
//                                    {
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,堆垛机2已经禁用,不能入大托盘,任务ID:", 0, "", 0, checkHeight, "大托盘不能去一号库位");
//                                        return "";
//                                    }
//                                    areaCode = 2;
//                                    if (checkHeight > 4)
//                                    {//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,WCS托盘参数传入错误,任务ID:", 0, "", sysHeight, checkHeight, "高度异常,光电检测高度为:" + checkHeight);
//                                        return "";
//                                    }
//                                    toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                    if (toplace == "")
//                                    {
//                                        changPlateCode();
//                                        Form1.lastPlateCode = "1";
//                                        shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                        int saveResult = mod.SaveChanges();
//                                        if (saveResult < 1)
//                                        {
//                                            mod.SaveChanges();
//                                        }
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 找不到库位,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                        return "";
//                                    }
//                                    findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                    return areaCode + "-" + toplace;
 
//                                }
//                                #endregion
//                                #region  小托盘入库
//                                if (continerType == 1)
//                                {
//                                    #region 如果有堆垛机被禁用
//                                    //如果堆垛机2被禁用
//                                    if (areaCode == 1)
//                                    {
//                                        //height = height > 3 ? 2 : 1;
//                                        //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            Form1.lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = "堆垛机2被禁用,1号库位没有了-光电检测高度:" + checkHeight + ",系统转换的检测高度:" + sysHeight;
 
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(堆垛机2被禁用,1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "堆垛机2被禁用,1号库位没有了");
//                                            return "";
//                                        }
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    //如果堆垛机1被禁用
//                                    if (areaCode == 2)
//                                    {
//                                        if (checkHeight >= 6)
//                                        {//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(2号库位没有这个高度,光电检测高度为:" + checkHeight + "),任务ID: ");
//                                            return "";
//                                        }
//                                        //height = height > 3 ? height - 1 : height;
//                                        //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
//                                        toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            Form1.lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = "堆垛机1被禁用,2号库位没有了-光电检测高度:" + checkHeight + ",系统转换的检测高度:" + sysHeight;
 
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(堆垛机1被禁用,2号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "堆垛机1被禁用,2号库位没有了");
//                                            return "";
//                                        }
//                                        findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    #endregion
 
//                                    //如果堆垛机没禁用
//                                    if (areaCode == 0)
//                                    {
 
//                                        //找到物料编号 用来分别哪个哪个巷道物料多
 
//                                        if (task == null)
//                                        {
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(寻找小库位,查不到任务号),任务ID: ", 0, "", 0, checkHeight, "任务被删除");
//                                            return toplace = "";
//                                        }
//                                        if (shelveList == null)
//                                        {
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(寻找小库位,查不到码盘上架明细),任务ID: ", 0, "", sysHeight, checkHeight, "出库单被删除");
//                                            return toplace = "";
//                                        }
//                                        string productNo = shelveList.ProductCode;
//                                        #region 先检查2号库有没有小托盘空位 没有直接放1号库
//                                        string sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode='2' " +
//                                         " and ColumnCode>1 and ColumnCode<10" + " and IsLocked=" + (int)IsLockedEnum.未锁定 +
//                                         " and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze    是否有货   先拿这个字段用 
//                                        List<Base_Position> smallPosition = mod.Database.SqlQuery<Base_Position>(sql).ToList();
//                                        //先检查2号库有没有小托盘空位 没有直接放1号库
//                                        if (smallPosition.Count == 0)
//                                        {
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            areaCode = 1;
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
 
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                Form1.lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        #endregion
 
//                                        #region 假如高度等于6必须要去1号库位
//                                        if (checkHeight == 6)
//                                        {//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
//                                            areaCode = 1;
//                                            sysHeight = 2;//注意:这里将系统检测高度写死为2,就表示去找库区1的高库位(放到 975-1850的高度库位)
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位,注意:这里将系统检测高度写死为2,就表示去找库区1的高库位(放到 975-1850的高度库位)
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                Form1.lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 6号高度去1号巷道 找不到库位(1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        #endregion
//                                        #region 比较巷道里的货物数量
 
//                                        //原先的写法,我发现了,有跟踪号的计算物料数量和没有跟踪号的计算物料数量里面的代码是一模一样的,不管shelveList.TrackingNumber是不是NULL,因此判定代码重复了,因此我整理了一下 【EditBy shaocx,2022-09-17】
//                                        //【存疑】这里我发现一个问题,为什么只要是查找库区1找不到库存,就放弃再次寻找库区2的库存,为什么呢? 【EditBy shaocx,2022-09-17】
//                                        #region 计算物料数量,新代码  【EditBy shaocx,2022-09-17】
 
//                                        var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();
//                                        var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();
//                                        if (productOne.Count == 0)
//                                        {
//                                            areaCode = 1;
//                                            //height = height > 3 ? 2 : 1;//一排只有两种高度,高度>3就是高库位否则是低库位
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                Form1.lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 一号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        if (productTwo.Count == 0)
//                                        {
//                                            //height = height > 3 ? height - 1 : height;
//                                            //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                            areaCode = 2;
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                areaCode = 1;//如果2号小库位找不到就去一号库位找
//                                                //height = height > 3 ? 2 : 1;
//                                                //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                                sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                                toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                                if (toplace == "")
//                                                {
 
//                                                    changPlateCode();
//                                                    Form1.lastPlateCode = "1";
//                                                    shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                    findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 2号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                    int saveResult = mod.SaveChanges();
//                                                    if (saveResult < 1)
//                                                    {
//                                                        mod.SaveChanges();
//                                                    }
//                                                    return "";
//                                                }
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                                return areaCode + "-" + toplace;
 
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
//                                        decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
//                                        if (oneQty > twoQty)
//                                        {
//                                            areaCode = 2;
//                                            //height = height > 3 ? height - 1 : height;
//                                            //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                areaCode = 1;//如果2号小库位找不到就去一号库位找
//                                                //height = height > 3 ? 2 : 1;
//                                                //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                                sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                                toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                                if (toplace == "")
//                                                {
//                                                    changPlateCode();
//                                                    Form1.lastPlateCode = "1";
//                                                    shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                    findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排都找不到可用空库位");
//                                                    int saveResult = mod.SaveChanges();
//                                                    if (saveResult < 1)
//                                                    {
//                                                        mod.SaveChanges();
//                                                    }
//                                                    return "";
//                                                }
 
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                                return areaCode + "-" + toplace;
 
 
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        else
//                                        {
//                                            areaCode = 1;
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                Form1.lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
 
//                                        #endregion
 
//                                        #region 放弃的代码  【EditBy shaocx,2022-09-17】
//                                        /*
//                                //有跟踪号的计算物料数量
//                                if (shelveList.TrackingNumber == null)
//                                {
//                                    #region 有跟踪号的计算物料数量
 
//                                    var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();
//                                    var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();
//                                    if (productOne.Count == 0)
//                                    {
//                                        areaCode = 1;
//                                        //height = height > 3 ? 2 : 1;//一排只有两种高度,高度>3就是高库位否则是低库位
//                                        //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                            findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 一号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            return "";
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    if (productTwo.Count == 0)
//                                    {
//                                        //height = height > 3 ? height - 1 : height;
//                                        //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                        areaCode = 2;
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            areaCode = 1;//如果2号小库位找不到就去一号库位找
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
 
//                                                changPlateCode();
//                                                lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 2号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
 
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
//                                    decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
//                                    if (oneQty > twoQty)
//                                    {
//                                        areaCode = 2;
//                                        //height = height > 3 ? height - 1 : height;
//                                        //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            areaCode = 1;//如果2号小库位找不到就去一号库位找
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排都找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
 
//                                            findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
 
 
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    else
//                                    {
//                                        areaCode = 1;
//                                        //height = height > 3 ? 2 : 1;
//                                        //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                            findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            return "";
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
 
//                                    #endregion
//                                }
//                                //没有跟踪号的计算物料数量
//                                else
//                                {
//                                    #region 没有跟踪号的计算物料数量
 
//                                    string tranckingNumber = shelveList.TrackingNumber;
 
//                                    var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();//.Sum(x => x.ProductStorage);
//                                    var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();// Sum(x => x.ProductStorage);
 
//                                    if (productOne.Count == 0)
//                                    {
//                                        areaCode = 1;
//                                        //height = height > 3 ? 2 : 1;
//                                        //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                            findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            return "";
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    if (productTwo.Count == 0)
//                                    {
//                                        areaCode = 2;
//                                        //height = height > 3 ? height - 1 : height;
//                                        //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            areaCode = 1;//如果2排找不到就去一排找
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
//                                    decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
//                                    if (oneQty > twoQty)
//                                    {
//                                        areaCode = 2;
//                                        //height = height > 3 ? height - 1 : height;
//                                        //bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            areaCode = 1;//如果2排找不到就去一排找
//                                            //height = height > 3 ? 2 : 1;
//                                            //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                            sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                            toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                            if (toplace == "")
//                                            {
//                                                changPlateCode();
//                                                lastPlateCode = "1";
//                                                shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                                findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排找不到可用空库位");
//                                                int saveResult = mod.SaveChanges();
//                                                if (saveResult < 1)
//                                                {
//                                                    mod.SaveChanges();
//                                                }
//                                                return "";
//                                            }
//                                            findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                            return areaCode + "-" + toplace;
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
//                                    else
//                                    {
//                                        areaCode = 1;
//                                        //height = height > 3 ? 2 : 1;
//                                        //bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
//                                        sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
 
//                                        toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
//                                        if (toplace == "")
//                                        {
//                                            changPlateCode();
//                                            lastPlateCode = "1";
//                                            shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
//                                            findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
//                                            int saveResult = mod.SaveChanges();
//                                            if (saveResult < 1)
//                                            {
//                                                mod.SaveChanges();
//                                            }
//                                            return "";
//                                        }
//                                        findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
//                                        return areaCode + "-" + toplace;
//                                    }
 
//                                    #endregion
//                                }
//                                //*/
//                                        #endregion
 
//                                        #endregion
//                                    }
//                                }
//                                #endregion
//                            }
//                            catch (Exception)
//                            {
//                                transBool = false;
//                                throw;
//                            }
//                            finally
//                            {
//                                if (transBool)
//                                {
//                                    trans.Commit();
//                                }
//                                else
//                                {
//                                    trans.Rollback();
//                                }
//                            }
//                        }
//                        #endregion
 
 
//                    }
//                }
//                catch (Exception ex)
//                {
//                    toplace = "";
//                    logtxt.txtWrite("类名:Form1/函数名:toPlace  找目标库位产生异常" + ex.Message + "出错行号" + (string)ex.StackTrace, 2);
//                }
//                finally { Form1.single.ReleaseMutex(); }//一轮结束
//            }
//            if (toplace == "")
//            {
//                Form1.lastPlateCode = "1";
//            }
 
//            return toplace;
 
//        }
//        /// <summary>
//        /// 找库位处理结果
//        /// </summary>
//        /// <param name="isInMoreHighPosition">是否入的是匹配自己高度的更高库位,这些库位需要移库的</param>
//        /// <param name="findEmptyReason">原因</param>
//        /// <param name="plcTaskId">PLC任务号</param>
//        /// <param name="info"></param>
//        /// <param name="areaCode"></param>
//        /// <param name="toplace"></param>
//        /// <param name="height">系统判断的高度</param>
//        /// <param name="checkHeight">光电检测的高度</param>
//        /// <param name="msg"></param>
//        private static void findStorageReuslt(int wmsTaskId, dbModel mod, bool isInMoreHighPosition, string findEmptyReason, int plcTaskId, string info, int areaCode = 0, string toplace = "", int height = 0, int checkHeight = 0, string msg = "")
//        {
//            try
//            {
//                Form1.lastPlateCode = "0";
//                //修复 [EditBy shaocx,2022-04-18]
//                //查找对应任务
//                //Task_Queue changeTaksStatus = mod.Task_Queue.Find(taskId);
//                Task_Queue curTask = null;
//                if (wmsTaskId != 0)
//                {
//                    curTask = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId && x.Task_Id == wmsTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
//                }
//                else
//                {//注意:后期稳定后,必须要求wmsTaskId大于0!!!【EditBy shaocx,2022-09-22】
//                    curTask = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
//                }
 
//                if (curTask != null)
//                {
//                    if (areaCode == 0)//没传库区值就是异常
//                    {
//                        if (height > 0)//传高度值就是找不到库位
//                        {
//                            curTask.TaskStatus = msg + "-" + "光电检测高度:" + checkHeight + ",系统校验高度:" + height + "," + findEmptyReason;
//                        }
//                        else //没传高度值 可能是任务被删除或入库单被删除
//                        {
//                            curTask.TaskStatus = msg;
//                        }
//                        logtxt.txtWrite("类名:Form1/函数名:findStorageError ,不能找库位" + info, 2);
//                    }
//                    else
//                    {
//                        curTask.LogicHeight = height;//逻辑高度(系统判断的高度)【EditBy shaocx,2022-08-25】
//                        curTask.PhysicsHeight = checkHeight;//物理高度(光电检测的高度)【EditBy shaocx,2022-08-25】
//                        curTask.ToPositionName = toplace;//高度检测获取后,并且找到了库存后,才写入任务表的ToPositionName值 【EditBy shaocx,2022-08-25】
//                        curTask.DoCount = areaCode;
//                        //我注释了该代码,因为 常规入库任务,在创建任务时状态是“下发中”,经过线程common_autoSendTask下发给WCS成功后,就改为 状态“已下发”
//                        //因此这个地方就没有必要重复改此状态了,避嫌 【EditBy shaocx,2022-09-10】
//                        //curTask.TaskStatus = "已下发"; 
//                        curTask.IsInMoreHighPosition = isInMoreHighPosition == true ? 1 : 0;// 【EditBy shaocx,2022-09-19】
//                    }
//                    mod.SaveChanges();
//                }
//            }
//            catch (Exception ex)
//            {
//                logtxt.txtWrite("类名:Form1/函数名:finishConfirm  查询任务完成产生异常" + ex.Message + "出错行号" + (string)ex.StackTrace, 2);
//            }
//        }
 
 
//        /// <summary> 分配库位
//        /// 分配库位
//        /// </summary>
//        /// <param name="filter_shelveCode">按照排数过滤</param>
//        /// <param name="isNeedSaveChangeWhenFind">当发现空库位时,是否需要更新数据(目前仅供闲时移库使用,闲时移库传递false,其他情况传递true)</param>
//        /// <param name="areaCode">库区号</param>
//        /// <param name="containerType">托盘类型</param>
//        /// <param name="containerHeight">托盘总高(系统检测高度)</param>
//        ///  <param name="restrictNumber">预留库位数</param>
//        /// <returns>返回格式:格式: 01-03-01</returns>
//        public static string findStorage(dbModel mod, string filter_shelveCode, bool isNeedSaveChangeWhenFind, ref bool isInMoreHighPosition, ref string findEmptyReason, int areaCode, int containerType, int containerHeight, int restrictNumber = 1)
//        {
//            string errMsg = "";
//            string position = "";
//            if (Form1.single.WaitOne())//增加线程锁防止并发
//            {
//                try
//                {//满托回库  入库  移库
 
//                    List<string> restrict = new List<string>();//筛选条件
 
 
//                    #region 库位范围和排序
//                    if (areaCode == 1)
//                    {
//                        #region 一号机都是小托盘
//                        switch (containerHeight)
//                        {
//                            case 1:
//                                //一号机975以下
//                                //【存疑】这里为什么没有优先原则,而是只能放到大于1或小于11的地方?按道理不应该全部库位都能放吗?[EditBy shaocx,2022-09-17]
//                                restrict.Add(" and  RowCode>1 and RowCode<11 ");
//                                //增加以下代码,没有低库位就去高库位找 【EditBy shaocx,2022-09-19】
//                                restrict.Add(" and  (RowCode=1 or RowCode=11 )");
//                                break;
//                            case 2://放到 975-1850的高度库位
//                                //注释以下代码,统一用方法GetRestrictNumber判断 【EditBy shaocx,2022-09-19】
//                                //restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
//                                restrict.Add(" and  (RowCode=1 or RowCode=11 )");
//                                break;
//                        }
//                        #endregion
//                    }
//                    else
//                    {
//                        #region 二号机小托盘
//                        if (areaCode == 2 && containerType == 1)
//                        {
//                            switch (containerHeight)
//                            {//二号堆垛机 小托盘 750以下都是2-10层 750-1150 是3 
//                                case 1:
//                                    //二号机小托盘650以下 优先放 2 ,4,6,8
//                                    //下面的restrict集合是分配执行的,保证了优先原则 [EditBy shaocx,2022-09-17]
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=2 or RowCode=4 or RowCode=6 or RowCode=8)");
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=3 or RowCode=5 or RowCode=7 or RowCode=9 or RowCode=10)");
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=1 or RowCode=11 )");
//                                    break;
//                                case 2://同650一样条件
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=2 or RowCode=4 or RowCode=6 or RowCode=8)");
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=3 or RowCode=5 or RowCode=7 or RowCode=9 or RowCode=10)");
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=1 or RowCode=11 ) ");
//                                    break;
//                                case 3://750-1150高度优先放3,5,7,9,10 其次是1和11而且只能在这其中
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=3 or RowCode=5 or RowCode=7 or RowCode=9 or RowCode=10)");
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=1 or RowCode=11 )");
//                                    break;
//                                case 4://1150-1350只能放1和11层
//                                    restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode=1 or RowCode=11 )");
//                                    break;
//                            }
 
//                        }
//                        #endregion
 
//                        #region 二号机大托盘
//                        else
//                        {
//                            switch (containerHeight)
//                            {//二号堆垛机  大托盘 
//                                case 1:
//                                    //二号机大托盘600以下 所有层都可以放 优先放 4,5,7,8,10,11层理
//                                    //下面的restrict集合是分配执行的,保证了优先原则 [EditBy shaocx,2022-09-17]
//                                    //ColumnCode是当前列,RowCode是当前层
//                                    //【存疑】为什么要ColumnCode<2 or ColumnCode>9? 列要小于2或者大于9?? [EditBy shaocx,2022-09-17]
//                                    //回答上面:因为 从2到9排 放的都是小托盘,其他排放的都是大托盘 【EditBy shaocx,2022-09-19】
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=4 or RowCode=5 or RowCode=7 or RowCode=8 or RowCode=10 or RowCode=11)");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=3 or RowCode=6 or RowCode=9 or RowCode=12 )");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and RowCode=2 ");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
//                                    break;
//                                case 2://同600-750 只能在1,2,3,6,9,12,13,14层里
 
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=3 or RowCode=6 or RowCode=9 or RowCode=12 )");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and RowCode=2 ");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
//                                    break;
//                                case 3://750-1150高度优先放1,2,13,14 优先放2层
 
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and RowCode=2 ");
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
//                                    break;
//                                case 4://1150-1350只能放1,13,14
//                                    //注释以下代码,统一用方法GetRestrictNumber判断 【EditBy shaocx,2022-09-19】
//                                    //restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
//                                    restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
//                                    break;
 
//                            }
//                        }
//                        #endregion
 
//                    }
//                    #endregion
 
//                    int index = 0;
//                    //[注意]这里分批次执行,就决定了优先放哪层的逻辑
//                    foreach (var item in restrict)
//                    {
//                        index++;
 
//                        if (isNeedSaveChangeWhenFind == false && index >= 2)
//                        {//说明是闲时移库寻找库存,那么如果是寻找不是最合适库存,则终止寻找。注意:这里的闲时移库类型包括(高库位寻找合适库位+库存平衡) 【EditBy shaocx,2022-09-26】
//                            errMsg = findEmptyReason = "闲时移库寻找库存,那么如果是寻找不是最合适库存,则终止寻找,查找的是库区:" + areaCode;
//                            position = "";
//                            break;
//                        }
 
//                        //入库优化策略  先判断哪排空库位多  再判断两头哪边空库位多(两头往中间放),
//                        Base_Position storage = null;//最终寻找到的目标库位对象
//                        //一号库位 都是小托盘
//                        if (areaCode == 1)
//                        {
//                            findStorageForAreaCode1(filter_shelveCode, mod, areaCode, item, ref restrictNumber, ref storage, containerType);
//                        }
//                        else
//                        {
//                            findStorageForAreaCode2(filter_shelveCode, mod, areaCode, item, ref restrictNumber, ref storage, containerType);
//                        }
 
//                        if (storage != null)
//                        {
//                            if (restrictNumber == 3)
//                            {
//                                errMsg = "预留库位数等于" + restrictNumber + ",设置寻找的库位为空,即使找到了空库位" + storage.PositionName;
//                                findEmptyReason = "空库存不足预留库位数" + restrictNumber + ",查找的是库区:" + areaCode;
//                                position = "";
//                                break;
//                            }
//                            #region MyRegion
 
//                            int pid = storage.Position_Id;
//                            //mod.SaveChanges();
//                            Base_Position storage1 = mod.Base_Position.Find(pid);
 
//                            //mod.Base_Position.AddOrUpdate(storage);
//                            string[] positions = storage1.PositionName.Split('-');
//                            position = positions[1] + "-" + positions[2] + "-" + positions[3];//格式: 01-03-01
 
//                            if (isNeedSaveChangeWhenFind)
//                            {//需要更新数据
//                                storage1.IsLocked = 1;//找到空库位时,库位锁定!
//                                storage1.Remark = "正常入库-找到空库位时,库位锁定!";
//                                //storage1.IsFreeze = 1;
//                                storage1.IsFreeze = (int)IsFreezeEnum.有货;
 
//                                int dd = mod.SaveChanges();
//                                if (dd < 1)
//                                {//保存数据失败
//                                    logtxt.txtWrite("类名:Form1/函数名:findStorage/ 库区=" + areaCode.ToString() + "托盘类型=" + containerType.ToString() + "托盘高度=" + containerHeight.ToString() + "保存数据库失败", 2);
//                                    findEmptyReason = errMsg = "保存数据库失败";
//                                    position = "";
//                                }
//                                else
//                                {//找到库位,并保存数据成功
//                                    if (index != 1)
//                                    {
//                                        isInMoreHighPosition = true;//表示不是按照最佳匹配高度找到的库位 【EditBy shaocx,2022-09-19】
//                                    }
//                                }
//                            }
//                            else
//                            {//不需要更新数据
//                                if (index != 1)
//                                {
//                                    isInMoreHighPosition = true;//表示不是按照最佳匹配高度找到的库位 【EditBy shaocx,2022-09-19】
//                                }
//                            }
//                            #endregion
 
//                            break;
//                        }
//                        else
//                        {
//                            errMsg = "未找到空闲库位";
//                            position = "";
 
//                        }
 
//                    }
//                }
//                catch (Exception ex)
//                {
//                    logtxt.txtWrite("类名:Form1/函数名:findStorage/产生异常 库区=" + areaCode.ToString() + "托盘类型=" + containerType.ToString() + "托盘高度=" + containerHeight.ToString() + "-出错信息" + ex.Message + "-出错行号" + (string)ex.StackTrace, 2);
//                    errMsg = "出现异常:" + ex.Message;
//                    findEmptyReason = "出现异常:" + ex.Message;
//                    position = "";
//                    throw ex;//抛出异常
//                }
//                finally { Form1.single.ReleaseMutex(); }//一轮结束
//            }
//            return position;
 
//        }
 
//        /// <summary>
//        /// 在库区1中分配库位
//        /// </summary>
//        /// <param name="mod"></param>
//        /// <param name="areaCode"></param>
//        /// <param name="item"></param>
//        /// <param name="restrictNumber"></param>
//        /// <param name="storage"></param>
//        private static void findStorageForAreaCode1(string filter_shelveCode, dbModel mod, int areaCode, string item, ref int restrictNumber, ref Base_Position storage, int containerType)
//        {
//            #region 库区1
//            //第一排搜索
//            string row1Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='01' and IsLocked=" + (int)IsLockedEnum.未锁定 +
//            " and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze    是否有货   先拿这个字段用 
//            FitlerShelveCode(filter_shelveCode, ref row1Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
//            List<Base_Position> row1Storage = mod.Database.SqlQuery<Base_Position>(row1Sql).ToList();
//            //第二排搜索
//            string row2Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='02' and IsLocked=" + (int)IsLockedEnum.未锁定 +
//            " and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze    是否有货   先拿这个字段用 
//            FitlerShelveCode(filter_shelveCode, ref row2Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
//            List<Base_Position> row2Storage = mod.Database.SqlQuery<Base_Position>(row2Sql).ToList();
 
//            //再次筛选出真正的空闲库位,将有库存的剔除掉 【EditBy shaocx,2022-03-03】
//            row1Storage = BussinessExtension.FitlterFindEmptyPlace(row1Storage, areaCode, mod);
//            row2Storage = BussinessExtension.FitlterFindEmptyPlace(row2Storage, areaCode, mod);
//            int total_storage = row1Storage.Count + row2Storage.Count;//真正的空库位的总数(一个库区的)
 
//            //找出哪排空库位多
//            List<Base_Position> rowResultSpl = row1Storage.Count > row2Storage.Count ? row1Storage : row2Storage;
//            //左右均放策略  右边要倒序
 
//            List<Base_Position> colRigthSpl = rowResultSpl.Where(x => Convert.ToInt32(x.ColumnCode) > 14).OrderBy(x => x.RowCode).ThenByDescending(x => x.ColumnCode).ToList();
 
//            List<Base_Position> colLeftSpl = rowResultSpl;
//            //移除右边库位得到左边库位 
//            if (colRigthSpl.Count > 0)
//            {
//                foreach (var itemColRemove in colRigthSpl)
//                {
//                    colLeftSpl.Remove(itemColRemove);
//                }
//            }
//            //判断左右两边数量
//            List<Base_Position> finallyResultSql = colRigthSpl.Count > colLeftSpl.Count ? colRigthSpl : colLeftSpl;
//            if (finallyResultSql.Count > 0)
//            {
//                storage = finallyResultSql[0];
//            }
 
//            //获取预留库位数 【EditBy shaocx,2022-09-19】
//            FindEmptyLocationHandler.GetRestrictNumber(areaCode, storage, containerType, ref restrictNumber);
 
//            if (restrictNumber == 2)
//            {//表示系统要预留至少两个空库位,用于存放空托盘
//                //if (finallyResultSql.Count < 4)
//                if (total_storage < 4) //改为用真正的空库位的总数(一个库区的)判断【EditBy shaocx,2022-03-03】
//                {
//                    restrictNumber = 3;
//                }
 
//            }
//            #endregion
//        }
 
//        /// <summary>
//        /// 在库区2中分配库位
//        /// </summary>
//        /// <param name="mod"></param>
//        /// <param name="areaCode"></param>
//        /// <param name="item"></param>
//        /// <param name="restrictNumber"></param>
//        /// <param name="storage"></param>
//        private static void findStorageForAreaCode2(string filter_shelveCode, dbModel mod, int areaCode, string item, ref int restrictNumber, ref Base_Position storage, int containerType)
//        {
//            #region 库区2
//            //库区2有一小半是是小托盘,所以只做排策略,两头不做
//            //第一排搜索
//            string areaCode2row1Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='01' and IsLocked=" + (int)IsLockedEnum.未锁定 +
//            " and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze    是否有货   先拿这个字段用 
//            FitlerShelveCode(filter_shelveCode, ref areaCode2row1Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
//            List<Base_Position> row1Storage = mod.Database.SqlQuery<Base_Position>(areaCode2row1Sql).ToList();
//            //第二排搜索
//            string areaCode2row2Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='02' and IsLocked=" + (int)IsLockedEnum.未锁定 +
//            " and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze    是否有货   先拿这个字段用 
//            FitlerShelveCode(filter_shelveCode, ref areaCode2row2Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
//            List<Base_Position> row2Storage = mod.Database.SqlQuery<Base_Position>(areaCode2row2Sql).ToList();
 
//            //重新筛选那些没有库存的库位【EditBy shaocx,2022-01-27】
//            row1Storage = BussinessExtension.FitlterFindEmptyPlace(row1Storage, areaCode, mod);
//            //重新筛选那些没有库存的库位【EditBy shaocx,2022-01-27】
//            row2Storage = BussinessExtension.FitlterFindEmptyPlace(row2Storage, areaCode, mod);
 
//            int total_storage = row1Storage.Count + row2Storage.Count;//真正的空库位的总数(一个库区的)
 
//            //找出哪排空库位多
//            List<Base_Position> rowResultSpl = row1Storage.Count > row2Storage.Count ? row1Storage : row2Storage;
 
//            if (rowResultSpl.Count > 0)
//            {
//                //验证
//                List<string> toPlaceList = mod.Task_Queue.Where(x => x.TaskType == TaskTypeEnum.常规入库.ToString() && (x.TaskStatus == "未下发" || x.TaskStatus == "下发中" || x.TaskStatus == "已下发")).Select(x => x.ToPositionName).ToList();
//                var Toplace = rowResultSpl.Where(x => !toPlaceList.Contains(x.PositionName)).ToList();
//                if (Toplace.Count > 0)
//                {
//                    #region 找到集合就赋值给toplace
//                    if (Form1.lastPosition == Toplace[0].PositionName)//假如等于上一次找的库位,这次就给list里第二个数据
//                    {
//                        logtxt.txtWrite("类名:Form1/函数名:findStorage/ 上次找的库位=" + Form1.lastPosition + " 本次找的库位" + Toplace[0].PositionName, 2);
 
//                        if (rowResultSpl.Count >= 2)
//                        {
//                            storage = Toplace[1];
//                            Form1.lastPosition = Toplace[1].PositionName;
//                        }
//                    }
//                    else
//                    {
//                        storage = Toplace[0];
//                        Form1.lastPosition = Toplace[0].PositionName;
 
//                    }
//                    #endregion
 
//                }
//            }
 
//            //获取预留库位数 【EditBy shaocx,2022-09-19】
//            FindEmptyLocationHandler.GetRestrictNumber(areaCode, storage, containerType, ref restrictNumber);
 
//            if (restrictNumber == 2)
//            {
//                //if (rowResultSpl.Count < 4)
//                if (total_storage < 4) //改为用真正的空库位的总数(一个库区的)判断【EditBy shaocx,2022-03-03】
//                {
//                    restrictNumber = 3;
//                }
//            }
//            #endregion
//        }
 
//        /// <summary>
//        /// 按照排数过滤
//        /// </summary>
//        /// <param name="filter_shelveCode"></param>
//        /// <param name="rowSql"></param>
//        private static void FitlerShelveCode(string filter_shelveCode, ref string rowSql)
//        {
//            if (!string.IsNullOrEmpty(filter_shelveCode))
//            {
//                rowSql += " and ShelveCode='" + filter_shelveCode + "' ";
//            }
//        }
 
//        #endregion
 
//        public static void changPlateCode()
//        {
//            Form1.lastPlateCode = "0";
//        }
//    }
//}