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
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
using DAL;
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.仓存管理.条码生成
{
    public class Sc_BarCodeController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
 
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        private WebS.WebService1 oWebs = new WebS.WebService1();
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public Int64 HInterID = 0;      //内码
        public string ModName = "85";
        public string HOrgNumber = "";
        public Int64 HOrgID = -1;
        public string SourceQtyCtl = ""; //超源单数量控制
 
 
        #region 条码生成
 
        #region 条码生成获取工厂代码数据
 
        [Route("Sc_BarCode/GetHWorksNumberBill")]
        [HttpGet]
        public object GetHWorksNumberBill()
        {
            try
            {
                string ERPMode = "";
                string CampanyName = "";
                string SourceQtyCtl = "";
                List<object> list = new List<object>();
                if (oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo) == false)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取系统参数失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    ERPMode = oSystemParameter.omodel.WMS_WMSStockCtl_ERPMode;
                    CampanyName = oSystemParameter.omodel.WMS_CampanyName;
                    SourceQtyCtl = oSystemParameter.omodel.BarCode_SourceQtyCtl;
                }
                if (CampanyName == "飞龙") //系统参数  客户定制化名称
                {
                    list.Add("ZL");
                    list.Add("ST");
                    list.Add("SQ");
                    list.Add("MQ");
                }
                else
                {
                    list.Add("");
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "返回记录成功!";
                objJsonResult.list = list;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        public static DataSet Sc_GetMESBeginStepWorkBill(string sWhere)
        {
            if (sWhere == null || sWhere.Equals(""))
            {
                return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_Sc_MESBeginWorkBillList_NEW order by hmainid desc ", "h_v_Sc_MESBeginWorkBillList_NEW");
            }
            else
            {
                string sql1 = "select * from h_v_Sc_MESBeginWorkBillList_NEW where 1 = 1 ";
                string sql = sql1 + sWhere + " order by hmainid desc ";
                return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Sc_MESBeginWorkBillList_NEW");
            }
 
        }
 
        #endregion
 
        #region 条码生成获取条码类型数据
 
        [Route("Sc_BarCode/GetHBarCodeTypeBill")]
        [HttpGet]
        public object GetHBarCodeTypeBill()
        {
            try
            {
                List<object> list = new List<object>();
                string sCapName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                if (sCapName == "夏宝电器")
                {
                    list.Add("内销机条码");
                    list.Add("外销机条码");
                    list.Add("半成品条码");
                }
                else if (sCapName == "博日科技")
                {
                    list.Add("仪器外购件条码普通规则");
                    list.Add("仪器外购件条码容器规则");
                    list.Add("仪器成品条码规则");
                    list.Add("试剂成品条码规则");
                }
                else
                {
                    list.Add("唯一条码");
                    list.Add("品种条码");
                    list.Add("批次条码");
                    list.Add("托盘条码");
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "返回记录成功!";
                objJsonResult.list = list;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region [通过源单类型查找不通单据信息]
        [Route("Sc_BarCode/ReportFromBillList")]
        [HttpGet]
        public object ReportFromBillList(int page, int limit, string sWhere,string HSouceBillType,string HOrgID)
        {
            oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo);
            List<object> columnNameList = new List<object>();
            try
            {
                int count = 0;
                int pageNum = page;
                int pageSize = limit;
                string sql = "";
                string tabname = "";
                if (sWhere == null || sWhere.Equals(""))
                {
                    sWhere = " where 1=1 and HOrgID='"+HOrgID+"' ";
                }
                else
                {
                    sWhere = " where 1=1 and HOrgID='" + HOrgID + "' " + sWhere;
                }
                switch (HSouceBillType)
                {
                    case "生产订单":
                        tabname = "h_v_IFCLD_ICMOBillList_Source"; 
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IFCLD_ICMOBillList_Source "+sWhere+ " and 任务数量>isnull(入库数量,0)  and 状态<>'结案' order by 单据号", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select * from(select row_number() over (order by 单据号) as HRowNumber,* from h_v_IFCLD_ICMOBillList_Source " + sWhere + " and 任务数量>isnull(入库数量,0)  and 状态<>'结案')   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "生产汇报单":
                        tabname = "h_v_IF_ICMOReportBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_ICMOReportBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_ICMOReportBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "采购订单":
                        tabname = "h_v_IF_POOrderBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_POOrderBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_POOrderBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "收料通知单":
                        tabname = "h_v_IF_POInStockBillList_Source";
                        if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                        {
                            count = new SQLHelper.ClsCN().RunProcReturn("select top 1000 * from h_v_IF_POInStockBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                            sql = string.Format(@"select * from(select  top 1000 row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_POInStockBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        }
                        else
                        {
                            count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_POInStockBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                            sql = string.Format(@"select * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_POInStockBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        }
                        break;
                    case "委外订单":
                        tabname = "h_v_IF_EntrustOrderBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_EntrustOrderBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_EntrustOrderBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "生产入库单":
                        tabname = "h_v_IF_ProductInBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_ProductInBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select top " + pageSize + " * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_ProductInBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "采购入库单":
                        tabname = "h_v_IF_POStockInBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_POStockInBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select top " + pageSize + " * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_POStockInBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "销售退货单":
                        tabname = "h_v_IF_SellOutBackBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_SellOutBackBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select top " + pageSize + " * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_SellOutBackBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "生产退料单":
                        tabname = "h_v_IF_MateOutBackBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_MateOutBackBillList_Source " + sWhere + " order by 单据号 desc,hsubid", tabname).Tables[0].Rows.Count;
                        sql = string.Format(@"select top " + pageSize + " * from(select row_number() over (order by 单据号 desc,hsubid) as HRowNumber,* from h_v_IF_MateOutBackBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    default:
                        break;
                }
                ds = new SQLHelper.ClsCN().RunProcReturn(sql, tabname);
                string aa = ds.Tables[0].Columns[0].ToString();
                //ds.Tables[0].Columns["hmainid"].ColumnName.ToUpper();
                //ds.Tables[0].Columns["hsubid"].ColumnName.ToUpper();
                ds.Tables[0].Columns["hmainid"].ColumnName = "HMainID";
                ds.Tables[0].Columns["hsubid"].ColumnName = "HSubID";
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
 
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = count;
                    objJsonResult.Message = "获取资源绑定数据成功!";
                    objJsonResult.data = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(ds.Tables[0], new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }));  //序列化DataSet中的时间格式,然后再反序列化回来
                    objJsonResult.list = columnNameList;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "暂无资源绑定!";
                    objJsonResult.data = null;
                    objJsonResult.list = columnNameList;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message.ToString();
                objJsonResult.data = null;
                objJsonResult.list = columnNameList;
            }
            return objJsonResult;
        }
        #endregion
 
        #region [通过条码编号获取HItemId]
        [Route("Sc_BarCode/Get_HItemId")]
        [HttpGet]
        public object Get_HItemId(string sWhere)
        {
            List<object> columnNameList = new List<object>();
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_IF_BarCodeBillList where 条码编号 =  '" + sWhere + "'", "h_v_IF_BarCodeBillList");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message.ToString();
                objJsonResult.data = null;
                objJsonResult.list = columnNameList;
            }
            return objJsonResult;
        }
        #endregion
 
        #region [通过选择的源单信息查找源单数据]
        [Route("Sc_BarCode/SelectReportFromBillList")]
        [HttpPost]
        public object SelectReportFromBillList([FromBody] JObject msg)
        {
            //List<DBUtility.BillSelect> oList,string HBarCodeType
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string HSourceBillType = sArray[1].ToString();
            string HBarCodeType = sArray[2].ToString();
            string UserName = sArray[3].ToString();
            ClsPub.CurUserName = UserName;
            ListModels oListModels = new ListModels();
            List<object> ListRows = new List<object>();
            try
            {
               
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                List<DBUtility.BillSelect> oList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DBUtility.BillSelect>>(msg2);
                foreach (DBUtility.BillSelect oSelectRow in oList)
                {
                    HSouceOrderList ordrlist = new HSouceOrderList();
                    switch (oSelectRow.BillType)
                    {
                        case "3710": //生产订单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IFCLD_ICMOList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IFCLD_ICMOList");
                            //写入信息
                            ListRows.Add(HSourceOrderList(ds.Tables[0],ordrlist, HBarCodeType));
                            break;
                        case "3711": //生产汇报单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_ICMOReportList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ICMOReportList");
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1102": //采购订单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_POOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POOrderList");
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1103": //收料通知单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_POInStockList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POInStockList");
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1601": //委外订单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_EntrustOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_EntrustOrderList");
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1202": //生产入库
                             //得到信息
                            ds = oWebs.getDataSetBySQL("select * from h_v_IF_ProductInBillList_Source where HMainID=" + oSelectRow.BillMainID + " and HSubID=" + oSelectRow.BillSubID, "h_v_IF_ProductInBillList_Source", ref DBUtility.ClsPub.sExeReturnInfo);
                            //写入信息
                            ListRows.Add(Sub_WriteInForm_InOut(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1201": //采购入库
                            //得到信息
                            ds = oWebs.getDataSetBySQL("select * from h_v_IF_POStockInBillList_Source     where HMainID=" + oSelectRow.BillMainID + " and HSubID=" + oSelectRow.BillSubID, "h_v_IF_POStockInBillList_Source    ", ref DBUtility.ClsPub.sExeReturnInfo);
                            //写入信息
                            ListRows.Add(Sub_WriteInForm_InOut(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1247": //销售退货
                            //得到信息
                            ds = oWebs.getDataSetBySQL("select * from h_v_IF_SellOutBackBillList_Source where HMainID=" + oSelectRow.BillMainID + " and HSubID=" + oSelectRow.BillSubID, "h_v_IF_SellOutBackBillList_Source", ref DBUtility.ClsPub.sExeReturnInfo);
                            //写入信息
                            ListRows.Add(Sub_WriteInForm_InOut(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1244": //生产退料
                            //得到信息
                            ds = oWebs.getDataSetBySQL("select * from h_v_IF_MateOutBackBillList_Source where HMainID=" + oSelectRow.BillMainID + " and HSubID=" + oSelectRow.BillSubID, "h_v_IF_MateOutBackBillList_Source", ref DBUtility.ClsPub.sExeReturnInfo);
                            //写入信息
                            ListRows.Add(Sub_WriteInForm_InOut(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1403": //退货通知单
                            break;
                        case "1203": //其他入库单
                            break;
                        case "1207": //直接调拨单
                            break;
                        case "1239": //采购退料单
                            break;
                        case "1255": //组装拆卸单
                            break;
                        default:
                            break;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取数据成功!";
                objJsonResult.data = null;
                objJsonResult.list = ListRows;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message.ToString();
                objJsonResult.data = null;
                objJsonResult.list = ListRows;
            }
            return objJsonResult;
        }
 
        public object HSourceOrderList(DataTable dt, HSouceOrderList ordrlist,string HBarCodeType) 
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ordrlist.HQty = dt.Rows[i]["未生成条码数量"].ToString();
                ordrlist.HMinQty = dt.Rows[i]["未生成条码数量"].ToString();
                ordrlist.HMainID = dt.Rows[i]["hmainid"].ToString();
                ordrlist.HSubID = dt.Rows[i]["hsubid"].ToString();
                ordrlist.HBillNo = dt.Rows[i]["单据号"].ToString();
                ordrlist.HSourceBillNo = dt.Rows[i]["单据号"].ToString();
                ordrlist.HBillType = dt.Rows[i]["HBillType"].ToString();
                ordrlist.HDate = dt.Rows[i]["日期"].ToString(); //博日 收料单据日期
                ordrlist.HShowDate = DateTime.Now.ToString();
                ordrlist.HSupID = dt.Rows[i]["hsupid"].ToString();
                ordrlist.HSupNumber = dt.Rows[i]["供应商代码"].ToString();
                ordrlist.HSupName = dt.Rows[i]["供应商"].ToString();
                ordrlist.HDeptID = dt.Rows[i]["HDeptID"].ToString();
                ordrlist.HDeptNumber = dt.Rows[i]["部门代码"].ToString();
                ordrlist.HDeptName = dt.Rows[i]["部门"].ToString();
                ordrlist.HMaterID = dt.Rows[i]["HMaterID"].ToString();
                ordrlist.HMaterNumber = dt.Rows[i]["物料代码"].ToString();
                ordrlist.HMaterName = dt.Rows[i]["物料名称"].ToString();
                ordrlist.HMaterModel = dt.Rows[i]["规格型号"].ToString();
                ordrlist.HBatchNo = dt.Rows[i]["批次"].ToString();
                ordrlist.HUnitID = dt.Rows[i]["HUnitID"].ToString();
                ordrlist.HUnitNumber = dt.Rows[i]["计量单位代码"].ToString();
                ordrlist.HUnitName = dt.Rows[i]["计量单位"].ToString();
                ordrlist.HRemark = dt.Rows[i]["备注"].ToString();
                ordrlist.HMTONo = dt.Rows[i]["计划跟踪号"].ToString();
                ordrlist.HCusID = dt.Rows[i]["HCusID"].ToString();
                ordrlist.HCusNumber = dt.Rows[i]["客户代码"].ToString();
                ordrlist.HCusName = dt.Rows[i]["客户"].ToString();
                ordrlist.HCusType = dt.Rows[i]["客户型号"].ToString();
                ordrlist.HPinfanBarCode = dt.Rows[i]["HPinfanBarCode"].ToString();
                ordrlist.HPinfan = dt.Rows[i]["HPinfan"].ToString();
                ordrlist.HSourceName = dt.Rows[i]["生产线"].ToString();
                ordrlist.HEndDate = dt.Rows[i]["计划完工日期"].ToString();//博日 生产订单 失效日期
                ordrlist.HMinQty = dt.Rows[i]["最小包装数"].ToString();
                if (HBarCodeType == "仪器外购件条码容器规则")
                {
                    ordrlist.HMinQty = dt.Rows[i]["未生成条码数量"].ToString();
                }
                else if (HBarCodeType == "仪器外购件条码普通规则"|| HBarCodeType == "仪器成品条码规则"|| HBarCodeType == "试剂成品条码规则")
                {
                    ordrlist.HMinQty = "1";
                }
                else
                {
                    ordrlist.HMinQty = dt.Rows[i]["最小包装数"].ToString();
                }
            }
            return ordrlist;
        }
 
        public object HSourceOrderList1(DataTable dt, HSouceOrderList ordrlist, string HBarCodeType,string HSourceBillType)
        {
            oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ordrlist.HQty = dt.Rows[i]["未生成条码数量"].ToString();
                ordrlist.HMinQty = dt.Rows[i]["未生成条码数量"].ToString();
                ordrlist.HMainID = dt.Rows[i]["hmainid"].ToString();
                ordrlist.HSubID = dt.Rows[i]["hsubid"].ToString();
                ordrlist.HBillNo = dt.Rows[i]["单据号"].ToString();
                ordrlist.HBillType = dt.Rows[i]["HBillType"].ToString();
                ordrlist.HDate = dt.Rows[i]["日期"].ToString(); //博日 收料单据日期
                ordrlist.HShowDate = DateTime.Now.ToString();
                ordrlist.HDeptID = dt.Rows[i]["HDeptID"].ToString();
                ordrlist.HDeptNumber = dt.Rows[i]["部门代码"].ToString();
                ordrlist.HDeptName = dt.Rows[i]["部门"].ToString();
                ordrlist.HMaterID = dt.Rows[i]["HMaterID"].ToString();
                ordrlist.HMaterNumber = dt.Rows[i]["物料代码"].ToString();
                ordrlist.HMaterName = dt.Rows[i]["物料名称"].ToString();
                ordrlist.HMaterModel = dt.Rows[i]["规格型号"].ToString();
                ordrlist.HBatchNo = dt.Rows[i]["批次"].ToString();
                ordrlist.HUnitID = dt.Rows[i]["HUnitID"].ToString();
                ordrlist.HUnitNumber = dt.Rows[i]["计量单位代码"].ToString();
                ordrlist.HUnitName = dt.Rows[i]["计量单位"].ToString();
                ordrlist.HRemark = dt.Rows[i]["备注"].ToString();
                ordrlist.HMTONo = dt.Rows[i]["计划跟踪号"].ToString();
 
                if(HSourceBillType == "收料通知单")
                {
                    if (oSystemParameter.omodel.WMS_CampanyName != "瑞与祺")
                    {
                        ordrlist.HFurnaceNO = dt.Rows[i]["炉号"].ToString();
                        ordrlist.HCoilNO = dt.Rows[i]["钢卷捆包号"].ToString();
                        ordrlist.HheatNO = dt.Rows[i]["热处理"].ToString();
                    }
                }
 
                if (HBarCodeType == "仪器外购件条码容器规则")
                {
                    ordrlist.HMinQty = dt.Rows[i]["未生成条码数量"].ToString();
                }
                else if (HBarCodeType == "仪器外购件条码普通规则")
                {
                    ordrlist.HMinQty = "1";
                }
                else
                {
                    ordrlist.HMinQty = dt.Rows[i]["最小包装数"].ToString();
                }
                ordrlist.HMaker = ClsPub.CurUserName;
                if (HSourceBillType== "收料通知单"|| HSourceBillType== "采购订单"|| HSourceBillType=="委外订单"|| HSourceBillType== "采购入库单") 
                {
                    ordrlist.HInnerBillNo = dt.Rows[i]["内部采购订单号"].ToString();
                    ordrlist.HSupID= dt.Rows[i]["hsupid"].ToString();
                    ordrlist.HSupNumber = dt.Rows[i]["供应商代码"].ToString();
                    ordrlist.HSupName = dt.Rows[i]["供应商"].ToString();
                    if (HSourceBillType == "收料通知单")
                    {
                        if (dt.Rows[i]["是否赠品"].ToString() == "是")
                        {
                            ordrlist.HGiveAwayFlag = 1;
                        }
                        else
                        {
                            ordrlist.HGiveAwayFlag = 0;
                        }
                    }
                }
                if (HSourceBillType == "退货通知单")
                {
                    ordrlist.HCusID = dt.Rows[i]["HCusID"].ToString();
                    ordrlist.HCusNumber = dt.Rows[i]["客户代码"].ToString();
                    ordrlist.HCusName= dt.Rows[i]["客户"].ToString();
                }
                if (HSourceBillType == "其他入库单")
                {
                    ordrlist.HWhID = dt.Rows[i]["HWhID"].ToString();
                    ordrlist.HWhNumber = dt.Rows[i]["仓库代码"].ToString();
                    ordrlist.HWhName = dt.Rows[i]["仓库"].ToString();
                    ordrlist.HSPID = dt.Rows[i]["HSPID"].ToString();
                    ordrlist.HSPNumber = dt.Rows[i]["仓位代码"].ToString();
                    ordrlist.HSPName = dt.Rows[i]["仓位"].ToString();
                }
            }
            return ordrlist;
        }
 
        //根据TABLE写入界面(出入库单据) 
        private object Sub_WriteInForm_InOut(DataTable dt, HSouceOrderList ordrlist, string HBarCodeType, string HSourceBillType)
        {
 
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ordrlist.HQty = dt.Rows[i]["可生成条码数量"].ToString();
                ordrlist.HinitQty = dt.Rows[i]["可生成条码数量"].ToString();
                ordrlist.HMinQty = dt.Rows[i]["最小包装数"].ToString();
                ordrlist.HMainID = dt.Rows[i]["HMainID"].ToString();
                ordrlist.HSubID = dt.Rows[i]["HSubID"].ToString();
                ordrlist.HBillNo = dt.Rows[i]["单据号"].ToString();
                ordrlist.HBillType = dt.Rows[i]["HBillType"].ToString();
                ordrlist.HDeptID = dt.Rows[i]["HDeptID"].ToString();
                ordrlist.HDeptNumber = dt.Rows[i]["部门代码"].ToString();
                ordrlist.HDeptName = dt.Rows[i]["部门"].ToString();
                ordrlist.HMaterID = dt.Rows[i]["HMaterID"].ToString();
                ordrlist.HMaterNumber = dt.Rows[i]["物料代码"].ToString();
                ordrlist.HMaterName = dt.Rows[i]["物料名称"].ToString();
                ordrlist.HMaterModel = dt.Rows[i]["规格型号"].ToString();
                ordrlist.HBatchNo = dt.Rows[i]["批号"].ToString();
                ordrlist.HUnitID = dt.Rows[i]["HUnitID"].ToString();
                ordrlist.HUnitNumber = dt.Rows[i]["计量单位代码"].ToString();
                ordrlist.HUnitName = dt.Rows[i]["计量单位"].ToString();
                ordrlist.HAuxPropID = dt.Rows[i]["HAuxPropID"].ToString();
                ordrlist.HAuxPropNumber = dt.Rows[i]["辅助属性代码"].ToString();
                ordrlist.HAuxPropName = dt.Rows[i]["辅助属性"].ToString();
                ordrlist.HWhID = dt.Rows[i]["HWhID"].ToString();
                ordrlist.HWhNumber = dt.Rows[i]["仓库代码"].ToString();
                ordrlist.HWhName = dt.Rows[i]["仓库"].ToString();
                ordrlist.HSPID = dt.Rows[i]["HSPID"].ToString();
                ordrlist.HSPNumber = dt.Rows[i]["仓位代码"].ToString();
                ordrlist.HSPName = dt.Rows[i]["仓位"].ToString();
                ordrlist.HMTONo = dt.Rows[i]["计划跟踪号"].ToString();
                ordrlist.HDate = dt.Rows[i]["日期"].ToString(); 
                ordrlist.HShowDate = DateTime.Now.ToString();
            }
            return ordrlist;
        }
        #endregion
 
        #region [同步资料]
        [Route("Sc_BarCode/Sync_data")]
        [HttpGet]
        public object Sync_data()
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            try
            {
                oCn.RunProc("exec h_p_IF_ERPDataToLocal", ref DBUtility.ClsPub.sExeReturnInfo);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "同步基础资料成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "同步基础资料失败!" + e;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region [批次]
        [Route("Sc_BarCode/Batch")]
        [HttpGet]
        public object Batch(int HMaterID, string HBatchNo)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            bool b = false;
            if (HMaterID != 0)
            {
                DataSet oDs = oCn.RunProcReturn("exec h_p_Gy_BarCodeBill_GetBatchNo " + HMaterID.ToString() + ",'" + HBatchNo + "','" + "" + "','" + "" + "'", "h_p_Gy_BarCodeBill_GetBatchNo");
                //
                if (oDs == null && oDs.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.Message="生成批次失败!";
                    return objJsonResult;
                }
                else if (DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0][0]) == "1")
                {
                    objJsonResult.code = "1";
                    objJsonResult.Message = "生成批次成功!";
                    objJsonResult.data = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HBatchNo"]);
                    HBatchNo = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HBatchNo"]);
                    b = true;
                    return objJsonResult;
                }
            }
            //明细表是否为零行
            if (b == false)
            {
                objJsonResult.code = "1";
                objJsonResult.Message="没有需要生成批次的明细行!";
                return objJsonResult;
            }
            else //完全封闭
            {
                return null;
            }
        }
        #endregion
 
        #region [条码生成接口]
        [Route("Sc_BarCode/Sub_SaveBill")]
        [HttpPost]
        public object Sub_SaveBill([FromBody] JObject msg)
        {
            try
            {
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString();
                string HOrgType = sArray[1].ToString();
                string HSourceBillTypeName = sArray[2].ToString();
                string HSelectBarCodeType = sArray[3].ToString();
                string CampanyName = sArray[4].ToString()=="xxx"?"": sArray[4].ToString();
                string UserName = sArray[5].ToString();
                ClsPub.CurUserName = UserName;
 
                //获取内码
                HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
                HOrgNumber = "";
                if (oClsGy_ORGANIZATIONS_View.GetInfoByName(HOrgType))
                {
                    HOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
                    HOrgNumber = DBUtility.ClsPub.isStrNull(oClsGy_ORGANIZATIONS_View.omodel.HNumber);
                }
                if (HOrgID == -1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "选择组织有错误!";
                    return objJsonResult;
                }
                if (!Sub_AllowSave(msg2, HSelectBarCodeType))//单据完整性判断
                {
                    return objJsonResult;
                }
                if (HSelectBarCodeType == "仪器成品条码规则")
                {
                    //客户定制
                }
                else
                {
                    //生成条码
                    SaveBarCode(msg2, HSelectBarCodeType, CampanyName, HSourceBillTypeName);
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "条码生成失败!"+e.Message;
                return objJsonResult;
            }
            return objJsonResult;
        }
        #endregion        
 
        #region[单据完整性判断]
        private bool Sub_AllowSave(string msg2, string HSelectBarCodeType)
        {
            msg2 = msg2.Replace("\\", "");
            msg2 = msg2.Replace("\n", "");  //\n
            List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
 
            string sHRemark = "";
            for (int i = 0; i < ordrlist.Count; i++)
            {
                long HSno = i + 1;                                                          // 序号
                string HBarCodeType = HSelectBarCodeType;                                   // 条码类型
                string HSourceBillNo = DBUtility.ClsPub.isStrNull(ordrlist[i].HBillNo);     // 源单单号
                long HMaterID = DBUtility.ClsPub.isLong(ordrlist[i].HMaterID);              // 物料内码
                string HBatchNo = DBUtility.ClsPub.isStrNull(ordrlist[i].HBatchNo);         // 批号
                long HAuxPropID = DBUtility.ClsPub.isLong(ordrlist[i].HAuxPropID);          // 辅助属性ID
                double HSourceQty = DBUtility.ClsPub.isDoule(ordrlist[i].HMinQty);          // 源单数量
                double HQty = DBUtility.ClsPub.isDoule(ordrlist[i].HQty);                   // 数量
                double HMinQty = DBUtility.ClsPub.isDoule(ordrlist[i].HMinQty);             // 最小包装数
                if (HMaterID != 0)
                {
                    DataSet oDsCheck = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_AddCheck " + HSno.ToString() + ",'" + HBarCodeType + "','" + HSourceBillNo + "'," + HMaterID.ToString() + ",'" + HBatchNo + "'," + HAuxPropID.ToString() + "," + HSourceQty.ToString() + "," + HQty.ToString() + "," + HMinQty.ToString() + "," + HOrgID.ToString() + ",'" + SourceQtyCtl + "'", "h_p_Gy_BarCodeBill_AddCheck");
                    if (oDsCheck == null && oDsCheck.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "条码生成完整性判断错误";
                        return false;
                    }
                    else if (DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0][0]) == "1")
                    {
                        sHRemark = sHRemark + DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HRemark"]);
                    }
                }
            }
            if (sHRemark != "")
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = sHRemark;
                return false;
            }
            return true;
        }
 
        #endregion
 
        #region[条码生成方法]
        private object SaveBarCode(string msg2, string HSelectBarCodeType, string CampanyName,string HSourceBillTypeName)
        {
            int LSHlen = 6;             //流水号长度
            int SumLen = 10;            //总长度
            string TM = "";             //条码
            string HNumber = "";        //物料内码
            string HMaterNumber = "";   //物料代码
            double HSumQty = 0;         //产品数量
            double HMinQty = 0;         //最小包装数
            int HBQty = 0;              //箱数
            double HQty = 0;            //数量
            string WeiShu = "";         //尾数
            int LSH = 0;                //流水号
            string LSH2 = "";           //流水号转换成字符
            string sDate = "";          //日期
            string sYear = "";          //年
            string sPeriod = "";        //月
            string sDay = "";           //日
            string HBatchNo = "";       //批次
            string HYasuoji = "";       //压缩机
            string HModelName = "";       //机型
            string HICMOBillNo = "";       //源单号
            string HBarCodeBatchNo = "";       //条码批次号
            string HBarCodeDate = "";         //条码日期
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string sTMNumber = "";      //条码自定义前缀
 
            string HCoilNO = "";
            string HFurnaceNO = "";
            string HFactory = "";
            decimal HAuxQty = 0;
            string HheatNO = "";
 
            DataSet Ds;
            msg2 = msg2.Replace("\\", "");
            msg2 = msg2.Replace("\n", "");  //\n
            List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
            List<HBarCodeList> ListRows = new List<HBarCodeList>();
            for (int j = 0; j < ordrlist.Count; j++)
            {
                if (ClsPub.isLong(ordrlist[j].HMaterID) != 0)
                {
                    HNumber = DBUtility.ClsPub.isStrNull(ordrlist[j].HMaterID);
                    HMaterNumber = DBUtility.ClsPub.isStrNull(ordrlist[j].HMaterNumber);
                    HBatchNo = ClsPub.isStrNull(ordrlist[j].HBatchNo);
 
                    HCoilNO = ClsPub.isStrNull(ordrlist[j].HCoilNO);
                    HFurnaceNO = ClsPub.isStrNull(ordrlist[j].HFurnaceNO);
                    HFactory = ClsPub.isStrNull(ordrlist[j].HFactory);
                    HAuxQty = ClsPub.isLong(ordrlist[j].HAuxQty);
                    HheatNO = ClsPub.isStrNull(ordrlist[j].HheatNO);
                    //日期获取方式
                    sDate = DateTime.Now.ToString();
                    //
                    if (HSelectBarCodeType == "仪器外购件条码普通规则" || HSelectBarCodeType == "仪器外购件条码容器规则") //单据日期(收料通知单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(ordrlist[j].HDate);
                    }
                    else if (HSelectBarCodeType == "试剂成品条码规则")// 失效日期(生产订单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(ordrlist[j].HEndDate);
                    }
                    else if (CampanyName == "夏宝电器")// 日期:生产订单 条码日期
                    {
                        sDate = DBUtility.ClsPub.isStrNull(ordrlist[j].HDate);
                    }
                    HYasuoji = DBUtility.ClsPub.isStrNull(ordrlist[j].HPinfan); //压缩机代码(夏宝电器)
                    HModelName = DBUtility.ClsPub.isStrNull(ordrlist[j].HCusType); //机型(夏宝电器)
                    HICMOBillNo = DBUtility.ClsPub.isStrNull(ordrlist[j].HSourceBillNo); //生产订单号(夏宝电器)
                    HBarCodeBatchNo = DBUtility.ClsPub.isStrNull(ordrlist[j].HPinfanBarCode); //条码批次号(夏宝电器)
                    HBarCodeDate = DBUtility.ClsPub.isStrNull(ordrlist[j].HSupNumber); //条码日期(夏宝电器)
                    //
                    sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                    sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                    sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                    sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                    sDay = sDay.Substring(sDay.Length - 2, 2);
                    //==================================
                    if (HSelectBarCodeType == "唯一条码")
                    {
                        if (CampanyName == "卓力") //系统参数  客户定制化名称
                        {
                            //条码前缀 = 物料代码 + 年 + 月 + 日
                            sTMNumber = HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        }
                        else if (CampanyName == "飞龙")
                        {
                            string HWorksNumber = "";
                            HWorksNumber = CampanyName;
                            if (HWorksNumber == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "工厂代码不能为空!";
                                return objJsonResult;
                            }
                            //条码前缀 = 工厂代码 + 物料内码 + 日期
                            sTMNumber = HWorksNumber + HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        }
                        else  //通用方法
                        {
                            //条码前缀 = 组织代码 + 物料代码 + 年 + 月 + 日
                            sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        }
                    }
                    else if (HSelectBarCodeType == "品种条码")
                    {
                        if (CampanyName == "五云") //系统参数  客户定制化名称
                        {
                            TM = HNumber + ";" + DBUtility.ClsPub.isStrNull(ordrlist[j].HMTONo);
                        }
                        else
                        {
                            TM = HOrgNumber + HNumber;
                        }
                    }
                    else if (HSelectBarCodeType == "批次条码")
                    {
                        TM = HOrgNumber + HNumber + HBatchNo;
                    }//博日特殊处理
                    else if (HSelectBarCodeType == "仪器外购件条码普通规则" || HSelectBarCodeType == "仪器外购件条码容器规则")
                    {
                        //物料编码+单据日期(YYMMDD)+流水4位 
                        sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                    }
                    else if (HSelectBarCodeType == "仪器成品条码规则") //另外处理了
                    {
                        //物料编码+序列号+生产日期
                        //sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
                        //Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        //                                                                                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                    }
                    else if (HSelectBarCodeType == "试剂成品条码规则")
                    {
                        //物料编码+生产批号+流水号6位-
                        sTMNumber = HMaterNumber + HBatchNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 6;
                    }
                    else if (HSelectBarCodeType == "内销机条码")
                    {
                        //制造本部1位(默认1)+机型代码5位()+年2位+月1位(A、B、C代替10月份)
                        //+日2位+条码批次码2位+压缩机代码1位+00+流水号4位+校验码(默认0)
                        sTMNumber = "1" + HModelName + HBarCodeDate + HBarCodeBatchNo + HYasuoji + "00";
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                        if (sTMNumber.Length != 16)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "条码长度不够16位,是否数据不全!制造本部1位:[0] + 机型代码5位:[" + HModelName + "] + 年月日5位:[" + HBarCodeDate + "] + 批次号2位:[" + HBarCodeBatchNo + "]+ 压缩机1位:[" + HYasuoji + "]+00 ; ";
                            return objJsonResult;
                        }
                    }
                    else if (HSelectBarCodeType == "外销机条码")
                    {
                        //物料代码11位+年2位+月1位(A、B、C代替10月份)+日2位+批次2位+流水号4位
                        //sTMNumber = HMaterNumber.Replace(Convert.ToChar("."),Convert.ToChar("")) + HBarCodeDate + HBarCodeBatchNo;
                        sTMNumber = HMaterNumber.Replace(".", "") + HBarCodeDate + HBarCodeBatchNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                        if (sTMNumber.Length != 18)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "条码长度不够18位,是否数据不全!物料代码11位:[" + HMaterNumber.Replace(".", "") + "]+年月日5位:[" + HBarCodeDate + "]+批次号2位:[" + HBarCodeBatchNo + "];";
                            return objJsonResult;
                        }
                    }
                    else if (HSelectBarCodeType == "半成品条码")
                    {
                        //生产订单号+4位流水号
                        sTMNumber = HICMOBillNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                    }
                    else if (HSelectBarCodeType == "托盘条码")
                    {
                        LSHlen = 4;     //流水号长度
                        //条码前缀 = 物料内码 + 年 + 月 + 日
                        sTMNumber = HNumber + sYear + sPeriod + sDay;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "错误的条码类型,不能生成条码!";
                        return objJsonResult;
                    }
 
                    HBQty = HBQty + ClsPub.isInt(ordrlist[j].HBQty);
                    HMinQty = ClsPub.isDoule(ordrlist[j].HMinQty);
                    HSumQty = ClsPub.isDoule(ordrlist[j].HQty);
                    n = 0;
                    
                    for (int i = k; i < HBQty; i++)
                    {
                        if (HSumQty - HMinQty > 0)
                        {
                            WeiShu = "";
                            HSumQty = HSumQty - HMinQty;
                        }
                        else
                        {
                            if (HSumQty == HMinQty)
                            {
                                WeiShu = "";
                            }
                            else
                            {
                                WeiShu = "尾数";
                            }
                            HMinQty = HSumQty;
                        }
                        //
                        LSH = LSH + 1;
                        LSH2 = LSH.ToString();
                        while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                        {
                            LSH2 = "0" + LSH2;
                        }
                        if (HSelectBarCodeType == "唯一条码" || HSelectBarCodeType == "托盘条码")
                        {
                            //条码编号 = 条码前缀 + 流水号
                            TM = sTMNumber + LSH2;
                        }
                        else if (HSelectBarCodeType == "仪器外购件条码普通规则" || HSelectBarCodeType == "仪器外购件条码容器规则" || HSelectBarCodeType == "试剂成品条码规则"
                            || HSelectBarCodeType == "半成品条码" || HSelectBarCodeType == "外销机条码")
                        {
                            TM = sTMNumber + LSH2;
 
                        }
                        else if (HSelectBarCodeType == "内销机条码")
                        {
                            TM = sTMNumber + LSH2 + "0";
                        }
                        //
                        if (TM.Trim() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "条形码不能为空,不能生成条码!";
                            return objJsonResult;
                        }
                        HBarCodeList barcode = new HBarCodeList();
                        barcode.HBarCode2 = TM;
                        barcode.HEntryID2 = ClsPub.isStrNull(j + 1);
                        barcode.HMaterID2 = ordrlist[j].HMaterID;
                        barcode.HMaterNumber2 = ordrlist[j].HMaterNumber;
                        barcode.HMaterName2 = ordrlist[j].HMaterName;
                        barcode.HMaterModel2 = ordrlist[j].HMaterModel;
                        barcode.HPinfan2 = ordrlist[j].HPinfan;
                        barcode.HPinfanBarCode2 = ordrlist[j].HPinfanBarCode;
 
 
                        barcode.HAuxPropID2 = ordrlist[j].HAuxPropID;
                        barcode.HAuxPropNumber2 = ordrlist[j].HAuxPropNumber;
                        barcode.HAuxPropName2 = ordrlist[j].HAuxPropName;
 
                        barcode.HUnitID2 = ordrlist[j].HUnitID;
                        barcode.HUnitNumber2 = ordrlist[j].HUnitNumber;
                        barcode.HUnitName2 = ordrlist[j].HUnitName;
 
                        barcode.HQty2 = ClsPub.isStrNull(HMinQty);
                        barcode.HBatchNo2 = ordrlist[j].HBatchNo;
                        barcode.HSourceInterID2 = ordrlist[j].HMainID;
                        barcode.HSourceEntryID2 = ordrlist[j].HSubID;
                        barcode.HSourceBillNo2 = ordrlist[j].HBillNo;
                        barcode.HSourceBillType2 = ordrlist[j].HBillType;
                        barcode.HPrint = "0";
                        barcode.HWei = WeiShu;
                        barcode.HBarcodeNo = ClsPub.isStrNull(n + 1);
                        barcode.HBarcodeQtys = ordrlist[j].HBQty;
                        barcode.HSupID2 = ordrlist[j].HSupID;
                        barcode.HSupNumber2 = ordrlist[j].HSupNumber;
                        barcode.HSupName2 = ordrlist[j].HSupName;
                        barcode.HDeptID2 = ordrlist[j].HDeptID;
                        barcode.HDeptNumber2 = ordrlist[j].HDeptNumber;
                        barcode.HDeptName2 = ordrlist[j].HDeptName;
                        barcode.HRemark2 = ordrlist[j].HRemark;
                        barcode.HDate2 = ordrlist[j].HDate;
                        barcode.HShowDate2 = ordrlist[j].HShowDate;
                        barcode.HWhID2 = ordrlist[j].HWhID;
                        barcode.HWhNumber2 = ordrlist[j].HWhNumber;
                        barcode.HWhName2 = ordrlist[j].HWhName;
                        barcode.HSPID2 = ordrlist[j].HSPID;
                        barcode.HSPNumber2 = ordrlist[j].HSPNumber;
                        barcode.HSPName2 = ordrlist[j].HSPName;
                        barcode.HMTONo2 = ordrlist[j].HMTONo;
                        barcode.HCusID2 = ordrlist[j].HCusID;
                        barcode.HCusNumber2 = ordrlist[j].HCusNumber;
                        barcode.HCusName2 = ordrlist[j].HCusName;
                        barcode.HCusType2 = ordrlist[j].HCusType;
                        barcode.HSourceID2 = ordrlist[j].HSourceID;
                        barcode.HSourceNumber2 = ordrlist[j].HSourceNumber;
                        barcode.HSourceName2 = ordrlist[j].HSourceName;
                        barcode.HEndDate2 = ordrlist[j].HEndDate;
                        barcode.HSeOrderBillNo2 = ordrlist[j].HSeOrderBillNo;
                        barcode.HInnerBillNo2 = ordrlist[j].HInnerBillNo;
                        barcode.HMaker2 = ordrlist[j].HMaker;
                        barcode.HGiveAwayFlag2 = ordrlist[j].HGiveAwayFlag;
 
                        barcode.HCoilNO = ordrlist[j].HCoilNO;
                        barcode.HFurnaceNO = ordrlist[j].HFurnaceNO;
                        barcode.HFactory = ordrlist[j].HFactory;
                        barcode.HAuxQty = ordrlist[j].HAuxQty;
                        barcode.HheatNO = ordrlist[j].HheatNO;
                        ListRows.Add(barcode);
                        k = k + 1;
                        n = n + 1;
                        oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    }
                }
            }
            string HWei = "";      //尾数
            string HBarCode = "";
            string HBarCodeType = "";
            Int64 HMaterID = 0;
            Int64 HAuxPropID = 0;
            Int64 HUnitID = 0;
            double HQty2 = 0;
            string HBatchNo2 = "";
            Int64 HSupID = 0;
            Int64 HGroupID = 0;
            int HPrintQty = 0;
            Int64 HSourceInterID = 0;
            Int64 HSourceEntryID = 0;
            string HSourceBillNo = "";
            string HSourceBillType = "";
            Int64 HBarcodeNo = 0;       //托号
            Int64 HBarcodeQtys = 0;     //总托数
            Int64 HDeptID = 0;
            Int64 HWhID = 0;
            Int64 HSPID = 0;
            string HRemark = "";
            string HMaterName = "";
            string HMaterModel = "";
            string HPinfan = "";
            string HMTONo = "";
            Int64 HCusID = 0;
            string HCusType = "";
            DateTime HEndDate;
            string HWorkLineName = "";
            string HSeOrderBillNo = "";
            string HInnerBillNo = "";
            bool HGiveAwayFlag = false;
            Int64 HEntryID = 0;
 
            string HCoilNO2 = "";
            string HFurnaceNO2 = "";
            string HFactory2 = "";
            decimal HAuxQty2 = 0;
            string HheatNO2 = "";
            DateTime HProduceDate;
            DateTime HExpiryDate;
            try
            {
                oCN.BeginTran();
                for (int i = 0; i < ListRows.Count; i++)
                {
                    if (ClsPub.isLong(ListRows[i].HMaterID2) != 0)
                    {
                        HWei = ClsPub.isStrNull(ListRows[i].HWei);
                        HBarCode = ClsPub.isStrNull(ListRows[i].HBarCode2);
                        //
                        HBarCodeType = ClsPub.isStrNull(HSelectBarCodeType);
                        if (CampanyName == "博日科技" || CampanyName == "夏宝电器")
                        {
                            HBarCodeType = "唯一条码";
                        }
                        //
                        HMaterID = ClsPub.isLong(ListRows[i].HMaterID2);
                        HEntryID = ClsPub.isLong(ListRows[i].HEntryID2);
                        HAuxPropID = ClsPub.isLong(ListRows[i].HAuxPropID2);
                        HUnitID = ClsPub.isLong(ListRows[i].HUnitID2);
                        HQty2 = ClsPub.isDoule(ListRows[i].HQty2);
                        HBatchNo2 = ClsPub.isStrNull(ListRows[i].HBatchNo2);
                        HSourceInterID = ClsPub.isLong(ListRows[i].HSourceInterID2);
                        HSourceEntryID = ClsPub.isLong(ListRows[i].HSourceEntryID2);
                        HSourceBillNo = ClsPub.isStrNull(ListRows[i].HSourceBillNo2);
                        HSourceBillType = ClsPub.isStrNull(ListRows[i].HSourceBillType2);
                        HBarcodeQtys = ClsPub.isLong(ListRows[i].HBarcodeQtys);
                        HBarcodeNo = ClsPub.isLong(ListRows[i].HBarcodeNo);
                        HSupID = ClsPub.isLong(ListRows[i].HSupID2);
                        HDeptID = ClsPub.isLong(ListRows[i].HDeptID2);
                        HWhID = ClsPub.isLong(ListRows[i].HWhID2);
                        HSPID = ClsPub.isLong(ListRows[i].HSPID2);
                        HRemark = ClsPub.isStrNull(ListRows[i].HRemark2);
                        HMaterName = ClsPub.isStrNull(ListRows[i].HMaterName2);
                        HMaterModel = ClsPub.isStrNull(ListRows[i].HMaterModel2);
                        HPinfan = ClsPub.isStrNull(ListRows[i].HPinfan2);
                        HMTONo = ClsPub.isStrNull(ListRows[i].HMTONo2);
                        HCusID = ClsPub.isLong(ListRows[i].HCusID2);
                        HCusType = ClsPub.isStrNull(ListRows[i].HCusType2);
                        HEndDate = ClsPub.isDate(ListRows[i].HEndDate2);
                        HWorkLineName = ClsPub.isStrNull(ListRows[i].HSourceName2);
                        HSeOrderBillNo = ClsPub.isStrNull(ListRows[i].HSeOrderBillNo2);
                        HInnerBillNo = ClsPub.isStrNull(ListRows[i].HInnerBillNo2);
                        HGiveAwayFlag = ClsPub.isBool(ListRows[i].HGiveAwayFlag2);
 
                        HCoilNO2 = ClsPub.isStrNull(ListRows[i].HCoilNO);
                        HFurnaceNO2 = ClsPub.isStrNull(ListRows[i].HFurnaceNO);
                        HFactory2 = ClsPub.isStrNull(ListRows[i].HFactory);
                        HAuxQty2 = ClsPub.isLong(ListRows[i].HAuxQty);
                        HheatNO2 = ClsPub.isStrNull(ListRows[i].HheatNO);
                        HProduceDate = ClsPub.isDate(ListRows[i].HProduceDate);
                        HExpiryDate = ClsPub.isDate(ListRows[i].HExpiryDate);
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                    ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                    ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                    ",HGiveAwayFlag " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo" +
                                    ",HCoilNO,HFurnaceNO,HFactory,HAuxQty,HheatNO,HProduceDate,HExpiryDate " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
                                    + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                    + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                    + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + "," + HEntryID.ToString() + ""
                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "','" + HCoilNO2 + "','" + HFurnaceNO2 + "','" + HFactory2 + "'," + HAuxQty2 + ",'" + HheatNO2 + "','" + HProduceDate + "','" + HExpiryDate + "'" + ")");
 
 
                        //HNumber = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        //if (cmbHBarCodeType.Text == "唯一条码")
                        //{
                        //    if (CampanyName == "卓力") //系统参数  客户定制化名称
                        //    {
                        //        //条码前缀 = 物料代码 + 年 + 月 + 日
                        //        sTMNumber = HNumber + sYear + sPeriod + sDay; 
                        //    }
                        //    else if (CampanyName == "飞龙")
                        //    {
                        //        string HWorksNumber = "";
                        //        HWorksNumber = cmbHWorksNumber.Text;
                        //        if (HWorksNumber == "")
                        //        {
                        //            MessageBox.Show("工厂代码不能为空!");
                        //            return;
                        //        }
                        //        //条码前缀 = 工厂代码 + 物料内码 + 日期
                        //        sTMNumber = HWorksNumber + HNumber + sYear + sPeriod + sDay; 
                        //    }
                        //    else  //通用方法
                        //    {
                        //        //条码前缀 = 组织代码 + 物料代码 + 年 + 月 + 日
                        //        sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay; 
                        //    }
                        //}
                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    }
                }
                //增加 条码超过未生成功能控制
 
                //
 
 
                //条码生成时同步生成条码出入库记录
                if (HSourceBillTypeName.Trim() == "生产入库单" || HSourceBillTypeName.Trim() == "采购入库单"
                    || HSourceBillTypeName.Trim() == "销售退货单" || HSourceBillTypeName.Trim() == "生产退料单")
                {
                    if (!oWebs.set_BarCodeAutoWMS(HInterID, HSourceBillType, HOrgID, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        objJsonResult.list = null;
                        return objJsonResult;
                    }
                }
 
                oCN.Commit();
                List<Object> listobj = ListRows.ConvertAll(s => (object)s);//List实体类转换为object
                //获取生成的条码信息
                string sql = string.Format(@"select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " order by HItemID");
                ds = new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_IF_ICMOBillList_Table");
 
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取资源绑定数据成功!";
                    objJsonResult.data = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(ds.Tables[0], new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }));  //序列化DataSet中的时间格式,然后再反序列化回来
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何结果,条码不存在!";
                    objJsonResult.data = null;
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "条码生成失败!" + e.Message;
                return objJsonResult;
            }
        }
        #endregion
 
        #region[条码打印更新打印次数]
        /// <summary>
        /// 更新打印次数
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="msg2"></param>
        /// <returns></returns>
        [Route("Sc_BarCode/UpdateBarcodePrintQty")]
        [HttpPost]
        public object UpdateBarcodePrintQty(string msg)
        {
            try
            {
                oCN.RunProc("update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0)+1 where HitemID in("+msg+")", ref DBUtility.ClsPub.sExeReturnInfo);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "更新打印次数成功";
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "打印失败!打印结束 :" + e.ToString();
                return objJsonResult;
            }
        }
        #endregion
 
        #endregion
    }
}