chenhaozhe
2025-07-03 e4f1a927520a98fbc69dd63ef982dd890ba4fbdc
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
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
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(CampanyName);
                }
                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 if (sCapName == "添康科技")
                {
                    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;
                    case "工序流转卡":
                        tabname = "h_v_IF_ProcessExchangeBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_ProcessExchangeBillList_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_ProcessExchangeBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "销售出库单":
                        tabname = "h_v_IF_SellOutBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_SellOutBillList_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_SellOutBillList_Source " + sWhere + ")   as A where HRowNumber >" + pageSize + " *(" + pageNum + "-1)");
                        break;
                    case "领料出库单":
                        tabname = "h_v_IF_MateOutBillList_Source";
                        count = new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_MateOutBillList_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_MateOutBillList_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 "1205": //销售出库单
                            //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_SellOutBillList_BarCode where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_SellOutBillList_BarCode");
                            //写入信息
                            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;
                        case "3772": //工序流转卡
                                     //得到信息
                            ds = oCN.RunProcReturn("select * from h_v_IF_ProcessExchangeList where HMainID=" + oSelectRow.BillMainID + " and HSubID=" + oSelectRow.BillSubID, "h_v_IF_ProcessExchangeList", ref DBUtility.ClsPub.sExeReturnInfo);
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            break;
                        case "1204": //领料出库单
                            //得到信息
                            ds = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_MateOutBillList " + oSelectRow.BillMainID.ToString() + "," + oSelectRow.BillSubID.ToString(), "h_p_Gy_BarCodeBill_MateOutBillList");
                            //写入信息
                            ListRows.Add(HSourceOrderList1(ds.Tables[0], ordrlist, HBarCodeType, HSourceBillType));
                            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) 
        {
            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.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 (oSystemParameter.omodel.WMS_CampanyName == "九菱") //系统参数  客户定制化名称     空白为通用
                {
                    ordrlist.HGroupID = Convert.ToInt32(dt.Rows[i]["HBeginWorkGroupID"]);
                    ordrlist.HGroupNumber = dt.Rows[i]["开工班组代码"].ToString();
                    ordrlist.HGroupName = dt.Rows[i]["开工班组名称"].ToString();
                    ordrlist.HEmpID = Convert.ToInt32(dt.Rows[i]["HBeginWorkEmpID"]);
                    ordrlist.HEmpNumber = dt.Rows[i]["开工人代码"].ToString();
                    ordrlist.HEmpName = 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 == "其他入库单" || 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();
                }
                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= "[0000-2-053]生成批次失败!";
                    return objJsonResult;
                }
                else if (DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0][0]) == "1")
                {
                    objJsonResult.code = "1";
                    objJsonResult.Message = "[0000-2-054]生成批次成功!";
                    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= "[3899-2-003]没有需要生成批次的明细行!";
                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 = "[0000-2-055]选择组织有错误!";
                    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 = "[3899-2-006]条码生成失败!" + 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 = "[3899-2-007]条码生成完整性判断错误";
                        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 = "";
 
            Int64 HGroupID = 0;
            long HEmpID = 0;
            string HCusModel = ""; //客户物料规格
            string HCusMaterName = ""; //客户物料名称
            string HCheckEmpName = ""; //检验员名称
 
            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);
                    HGroupID = ClsPub.isInt(ordrlist[j].HGroupID);
                    HEmpID = ClsPub.isLong(ordrlist[j].HEmpID);
                    HCusModel = ClsPub.isStrNull(ordrlist[j].HCusModel);
                    HCusMaterName = ClsPub.isStrNull(ordrlist[j].HCusMaterName);
                    HCheckEmpName = ClsPub.isStrNull(ordrlist[j].HCheckEmpName);
                    //日期获取方式
                    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);
                    }
                    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 if (CampanyName == "瑞与祺") {
                            var date = DateTime.Now.ToString("yyMMdd");//日期
                            if (HSourceBillTypeName == "收料通知单")
                            {
                                //物料代码-包装标识-日期-供应商代码-八位流水号
                                LSHlen = 8;//流水号是8位
 
                                DataSet dataDs = oCN.RunProcReturn($@"select  isnull(pr.FNUMBER,'') F_TEZV_BASE from  AIS20220308151944..T_PUR_Receive a 
inner join AIS20220308151944..T_PUR_RECEIVEENTRY b on a.FID = b.FID 
left join AIS20220308151944..T_BAS_PREBDONE pr on b.F_TEZV_BASE=pr.FID 
where a.FID={ordrlist[j].HMainID} and b.FENTRYID={ordrlist[j].HSubID}", "T_PUR_Receive");
                                if (dataDs.Tables[0].Rows.Count == 0)
                                {
                                    objJsonResult.code = "0";
                                    objJsonResult.count = 0;
                                    objJsonResult.Message = "单据不存在!";
                                    return objJsonResult;
                                }
 
                                sTMNumber = ordrlist[j].HMaterNumber + "-" + dataDs.Tables[0].Rows[0]["F_TEZV_BASE"].ToString() + "-" + date + "-" + ordrlist[j].HSupNumber + "-";
 
                                //sTMNumber = ordrlist[j].HMaterNumber + "-包装标识-" + date + "-" + ordrlist[j].HSupNumber + "-";
                                Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                            }
                            else if (HSourceBillTypeName == "生产入库单")
                            {
                                //物料代码-包装标识-日期-组织代码-八位流水号
                                LSHlen = 8;//流水号是8位
                                DataSet dataDs = oCN.RunProcReturn($@"select  isnull(pr.FNUMBER,'') F_bsv_Base1,a.FPRDORGID from  AIS20220308151944..T_PRD_INSTOCK a 
inner join AIS20220308151944..T_PRD_INSTOCKENTRY b on a.FID = b.FID
join(
select HERPInterID, HERPEntryID, HInterID, HEntryID from Kf_ICStockBillSub
)kf on b.FID = kf.HERPInterID and b.FENTRYID = kf.HERPEntryID
left join AIS20220308151944..T_BAS_PREBDONE pr on b.F_bsv_Base1=pr.FID
where kf.HInterID = {ordrlist[j].HMainID} and kf.HEntryID = {ordrlist[j].HSubID}", "T_PRD_INSTOCK");
                                if (dataDs.Tables[0].Rows.Count == 0)
                                {
                                    objJsonResult.code = "0";
                                    objJsonResult.count = 0;
                                    objJsonResult.Message = "单据不存在!";
                                    return objJsonResult;
                                }
                                string RQHNumber = "";
                                if (dataDs.Tables[0].Rows[0]["FPRDORGID"].ToString() == "100014")//江苏
                                {
                                    RQHNumber = "1.07.008";
                                }
                                else if (dataDs.Tables[0].Rows[0]["FPRDORGID"].ToString() == "100012")//上海
                                {
                                    RQHNumber = "1.04.008";
                                }
 
                                sTMNumber = ordrlist[j].HMaterNumber + "-" + dataDs.Tables[0].Rows[0]["F_bsv_Base1"].ToString() + "-" + date + "-" + RQHNumber + "-";
 
                                //sTMNumber = ordrlist[j].HMaterNumber + "-包装标识-"+ date + "-组织代码-";
                                Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                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");    //获取最大流水号
                                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;
 
                        barcode.HGroupID2 = ordrlist[j].HGroupID;
                        barcode.HEmpID2 = ordrlist[j].HEmpID;
                        barcode.HCusModel2 = ordrlist[j].HCusModel;
                        barcode.HCusMaterName2 = ordrlist[j].HCusMaterName;
                        barcode.HCheckEmpName2 = ordrlist[j].HCheckEmpName;
                        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 HGroupID2 = 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;
            long HEmpID2 = 0;
            string HCusModel2 = "";
            string HCusMaterName2 = "";
            string HCheckEmpName2 = "";
 
            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 = "唯一条码";
                        }
                        if (CampanyName == "九菱")
                        {
                            HBarCode = HBarCode + ClsPub.isStrNull(ListRows[i].HMTONo2);
                        }
                        //
                        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);
                        HGroupID2 = ClsPub.isInt(ListRows[i].HGroupID2);
                        HEmpID2 = ClsPub.isLong(ListRows[i].HEmpID2);
                        HCusModel2 = ClsPub.isStrNull(ListRows[i].HCusModel2);
                        HCusMaterName2 = ClsPub.isStrNull(ListRows[i].HCusMaterName2);
                        HCheckEmpName2 = ClsPub.isStrNull(ListRows[i].HCheckEmpName2);
                        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,HEmpID,HCusModel,HCusMaterName,HCheckEmpName " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID2.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 + "'," + HEmpID2.ToString() + ",'" + HCusModel2 + "','" + HCusMaterName2 + "','" + HCheckEmpName2 + "'" + ")");
 
 
                        //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 = "[0000-1-037]获取资源绑定数据成功!";
                    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 = "[0000-2-020]没有返回任何结果,条码不存在!";
                    objJsonResult.data = null;
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + 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
 
 
        #region [条码生成接口-迦南]
        [Route("Sc_BarCode/Sub_SaveBill_JiaNan")]
        [HttpPost]
        public object Sub_SaveBill_JiaNan([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 = "[0000-2-055]选择组织有错误!";
                    return objJsonResult;
                }
                if (!Sub_AllowSave(msg2, HSelectBarCodeType))//单据完整性判断
                {
                    return objJsonResult;
                }
 
                //生成条码
                SaveBarCode_JiaNan(msg2, HSelectBarCodeType, CampanyName, HSourceBillTypeName);
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + e.Message;
                return objJsonResult;
            }
            return objJsonResult;
        }
        #endregion        
 
        #region[条码生成方法_迦南]
        private object SaveBarCode_JiaNan(string msg2, string HSelectBarCodeType, string CampanyName, string HSourceBillTypeName)
        {
            DateTime sDate = DateTime.Now;                      //日期
            string HSourceBillType_Temp = "";                   //源单类型
            int n = 0;                                          //同批生成的条码索引
 
            //获取明细信息
            msg2 = msg2.Replace("\\", "");
            msg2 = msg2.Replace("\n", "");  //\n
            List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
            List<HBarCodeList> ListRows = new List<HBarCodeList>();
 
            DataSet Ds;
            for (int i = 0; i < ordrlist.Count; i++)
            {
                HSourceBillType_Temp = ordrlist[i].HBillType;
 
                if (ClsPub.isLong(ordrlist[i].HMaterID) != 0)
                {
                    if (HSelectBarCodeType == "BarCode")
                    {
                        //拆分每条物料记录为多条条码记录
                        double HSumQty = ClsPub.isDoule(ordrlist[i].HQty);                      //产品数量
                        double HQty = ClsPub.isDoule(ordrlist[i].HQty);                         //数量
                        double HMinQty = ClsPub.isDoule(ordrlist[i].HMinQty);                   //最小包装数
                        int HBQty = ClsPub.isInt(ordrlist[i].HBQty);                            //箱数
                        string WeiShu = "";                                                     //尾数
 
                        for (int j = 0; j < HBQty; j++)
                        {
                            string HBarCode_Temp = "";                                                  //条码
                            string sTMNumber = "";                                                      //条码前缀
                            string LSH = "";                                                            //最大流水号
                            int HLen = 4;                                                            //流水号长度
 
                            //条码拼接所需字段
                            string HSupNumber = DBUtility.ClsPub.isStrNull(ordrlist[i].HSupNumber).Replace(".", "");             //供应商代码(去掉分隔符)
                            string sDateStr = sDate.ToString("yyMMdd");                                                         //启动日期(YYMMDD)
 
                            if (HSupNumber.Trim() == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "供应商代码不能为空,不能生成条码!";
                                return objJsonResult;
                            }
 
                            //条码前缀 = R+供应商代码(去掉分隔符)+启动日期(YYMMDD)+四位流水号
                            sTMNumber = "R" + HSupNumber + sDateStr;
 
                            //根据条码前缀获取最大流水号
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");
                            LSH = String.Format("{0:D" + HLen + "}", ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1);
 
                            //拼接条码
                            HBarCode_Temp = sTMNumber + LSH;
 
 
                            if (HSumQty - HMinQty > 0)
                            {
                                WeiShu = "";
                                HSumQty = HSumQty - HMinQty;
                            }
                            else
                            {
                                if (HSumQty == HMinQty)
                                {
                                    WeiShu = "";
                                }
                                else
                                {
                                    WeiShu = "尾数";
                                }
                                HMinQty = HSumQty;
                            }
 
                            HBarCodeList barcode = new HBarCodeList();
                            barcode.HBarCode2 = HBarCode_Temp;
                            barcode.HBarCodeType2 = "唯一条码";
                            barcode.HBarCodeSubType2 = "包条码";
                            barcode.HEntryID2 = ClsPub.isStrNull(i + 1);
                            barcode.HMaterID2 = ordrlist[i].HMaterID;
                            barcode.HMaterNumber2 = ordrlist[i].HMaterNumber;
                            barcode.HMaterName2 = ordrlist[i].HMaterName;
                            barcode.HMaterModel2 = ordrlist[i].HMaterModel;
                            barcode.HPinfan2 = ordrlist[i].HPinfan;
                            barcode.HPinfanBarCode2 = ordrlist[i].HPinfanBarCode;
                            barcode.HAuxPropID2 = ordrlist[i].HAuxPropID;
                            barcode.HAuxPropNumber2 = ordrlist[i].HAuxPropNumber;
                            barcode.HAuxPropName2 = ordrlist[i].HAuxPropName;
                            barcode.HUnitID2 = ordrlist[i].HUnitID;
                            barcode.HUnitNumber2 = ordrlist[i].HUnitNumber;
                            barcode.HUnitName2 = ordrlist[i].HUnitName;
                            barcode.HQty2 = ClsPub.isStrNull(HMinQty);
                            barcode.HBatchNo2 = ordrlist[i].HBatchNo;
                            barcode.HSourceInterID2 = ordrlist[i].HMainID;
                            barcode.HSourceEntryID2 = ordrlist[i].HSubID;
                            barcode.HSourceBillNo2 = ordrlist[i].HBillNo;
                            barcode.HSourceBillType2 = ordrlist[i].HBillType;
                            barcode.HPrint = "0";
                            barcode.HWei = WeiShu;
                            barcode.HBarcodeNo = ClsPub.isStrNull(n + 1);
                            barcode.HBarcodeQtys = ordrlist[i].HBQty;
                            barcode.HSupID2 = ordrlist[i].HSupID;
                            barcode.HSupNumber2 = ordrlist[i].HSupNumber;
                            barcode.HSupName2 = ordrlist[i].HSupName;
                            barcode.HDeptID2 = ordrlist[i].HDeptID;
                            barcode.HDeptNumber2 = ordrlist[i].HDeptNumber;
                            barcode.HDeptName2 = ordrlist[i].HDeptName;
                            barcode.HRemark2 = ordrlist[i].HRemark;
                            barcode.HDate2 = ordrlist[i].HDate;
                            barcode.HShowDate2 = ordrlist[i].HShowDate;
                            barcode.HWhID2 = ordrlist[i].HWhID;
                            barcode.HWhNumber2 = ordrlist[i].HWhNumber;
                            barcode.HWhName2 = ordrlist[i].HWhName;
                            barcode.HSPID2 = ordrlist[i].HSPID;
                            barcode.HSPNumber2 = ordrlist[i].HSPNumber;
                            barcode.HSPName2 = ordrlist[i].HSPName;
                            barcode.HMTONo2 = ordrlist[i].HMTONo;
                            barcode.HCusID2 = ordrlist[i].HCusID;
                            barcode.HCusNumber2 = ordrlist[i].HCusNumber;
                            barcode.HCusName2 = ordrlist[i].HCusName;
                            barcode.HCusType2 = ordrlist[i].HCusType;
                            barcode.HSourceID2 = ordrlist[i].HSourceID;
                            barcode.HSourceNumber2 = ordrlist[i].HSourceNumber;
                            barcode.HSourceName2 = ordrlist[i].HSourceName;
                            barcode.HEndDate2 = ordrlist[i].HEndDate;
                            barcode.HSeOrderBillNo2 = ordrlist[i].HSeOrderBillNo;
                            barcode.HInnerBillNo2 = ordrlist[i].HInnerBillNo;
                            barcode.HMaker2 = ordrlist[i].HMaker;
                            barcode.HGiveAwayFlag2 = ordrlist[i].HGiveAwayFlag;
                            barcode.HCoilNO = ordrlist[i].HCoilNO;
                            barcode.HFurnaceNO = ordrlist[i].HFurnaceNO;
                            barcode.HFactory = ordrlist[i].HFactory;
                            barcode.HAuxQty = ordrlist[i].HAuxQty;
                            barcode.HheatNO = ordrlist[i].HheatNO;
                            barcode.HGroupID2 = ordrlist[i].HGroupID;
                            barcode.HEmpID2 = ordrlist[i].HEmpID;
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            ListRows.Add(barcode);
 
                            n += 1;                                                             //更新同批生成的条码数
                            oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");           //更新最大流水号
                        }
                    }
                    else if(HSelectBarCodeType == "BarCode_Box")
                    {
                        int HBQty = ClsPub.isInt(ordrlist[i].HBQty);                            //箱数
 
                        for (int j = 0; j < HBQty; j++)
                        {
                            string HBarCode_Temp = "";                                                  //条码
                            string sTMNumber = "";                                                      //条码前缀
                            string LSH = "";                                                            //最大流水号
                            int HLen = 4;                                                               //流水号长度
 
                            //条码拼接所需字段
                            string HSupNumber = DBUtility.ClsPub.isStrNull(ordrlist[i].HSupNumber).Replace(".", "");             //供应商代码(去掉分隔符)
                            string sDateStr = sDate.ToString("yyMMdd");                                                         //启动日期(YYMMDD)
 
                            if (HSupNumber.Trim() == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "供应商代码不能为空,不能生成条码!";
                                return objJsonResult;
                            }
 
                            //条码前缀 = R+供应商代码(去掉分隔符)+启动日期(YYMMDD)+四位流水号
                            sTMNumber = "B" + HSupNumber + sDateStr;
 
                            //根据条码前缀获取最大流水号
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");
                            LSH = String.Format("{0:D" + HLen + "}", ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1);
 
                            //拼接条码
                            HBarCode_Temp = sTMNumber + LSH;
 
                            HBarCodeList barcode = new HBarCodeList();
                            barcode.HBarCode2 = HBarCode_Temp;
                            barcode.HBarCodeType2 = "托盘条码";
                            barcode.HBarCodeSubType2 = "箱条码";
                            barcode.HEntryID2 = ClsPub.isStrNull(i + 1);
                            barcode.HMaterID2 = ordrlist[i].HMaterID;
                            barcode.HMaterNumber2 = ordrlist[i].HMaterNumber;
                            barcode.HMaterName2 = ordrlist[i].HMaterName;
                            barcode.HMaterModel2 = ordrlist[i].HMaterModel;
                            barcode.HPinfan2 = ordrlist[i].HPinfan;
                            barcode.HPinfanBarCode2 = ordrlist[i].HPinfanBarCode;
                            barcode.HAuxPropID2 = ordrlist[i].HAuxPropID;
                            barcode.HAuxPropNumber2 = ordrlist[i].HAuxPropNumber;
                            barcode.HAuxPropName2 = ordrlist[i].HAuxPropName;
                            barcode.HUnitID2 = ordrlist[i].HUnitID;
                            barcode.HUnitNumber2 = ordrlist[i].HUnitNumber;
                            barcode.HUnitName2 = ordrlist[i].HUnitName;
                            barcode.HQty2 = ClsPub.isStrNull(0);
                            barcode.HBatchNo2 = ordrlist[i].HBatchNo;
                            barcode.HSourceInterID2 = ordrlist[i].HMainID;
                            barcode.HSourceEntryID2 = ordrlist[i].HSubID;
                            barcode.HSourceBillNo2 = ordrlist[i].HBillNo;
                            barcode.HSourceBillType2 = ordrlist[i].HBillType;
                            barcode.HPrint = "0";
                            barcode.HWei = "";
                            barcode.HBarcodeNo = ClsPub.isStrNull(n + 1);
                            barcode.HBarcodeQtys = ordrlist[i].HBQty;
                            barcode.HSupID2 = ordrlist[i].HSupID;
                            barcode.HSupNumber2 = ordrlist[i].HSupNumber;
                            barcode.HSupName2 = ordrlist[i].HSupName;
                            barcode.HDeptID2 = ordrlist[i].HDeptID;
                            barcode.HDeptNumber2 = ordrlist[i].HDeptNumber;
                            barcode.HDeptName2 = ordrlist[i].HDeptName;
                            barcode.HRemark2 = ordrlist[i].HRemark;
                            barcode.HDate2 = ordrlist[i].HDate;
                            barcode.HShowDate2 = ordrlist[i].HShowDate;
                            barcode.HWhID2 = ordrlist[i].HWhID;
                            barcode.HWhNumber2 = ordrlist[i].HWhNumber;
                            barcode.HWhName2 = ordrlist[i].HWhName;
                            barcode.HSPID2 = ordrlist[i].HSPID;
                            barcode.HSPNumber2 = ordrlist[i].HSPNumber;
                            barcode.HSPName2 = ordrlist[i].HSPName;
                            barcode.HMTONo2 = ordrlist[i].HMTONo;
                            barcode.HCusID2 = ordrlist[i].HCusID;
                            barcode.HCusNumber2 = ordrlist[i].HCusNumber;
                            barcode.HCusName2 = ordrlist[i].HCusName;
                            barcode.HCusType2 = ordrlist[i].HCusType;
                            barcode.HSourceID2 = ordrlist[i].HSourceID;
                            barcode.HSourceNumber2 = ordrlist[i].HSourceNumber;
                            barcode.HSourceName2 = ordrlist[i].HSourceName;
                            barcode.HEndDate2 = ordrlist[i].HEndDate;
                            barcode.HSeOrderBillNo2 = ordrlist[i].HSeOrderBillNo;
                            barcode.HInnerBillNo2 = ordrlist[i].HInnerBillNo;
                            barcode.HMaker2 = ordrlist[i].HMaker;
                            barcode.HGiveAwayFlag2 = ordrlist[i].HGiveAwayFlag;
                            barcode.HCoilNO = ordrlist[i].HCoilNO;
                            barcode.HFurnaceNO = ordrlist[i].HFurnaceNO;
                            barcode.HFactory = ordrlist[i].HFactory;
                            barcode.HAuxQty = ordrlist[i].HAuxQty;
                            barcode.HheatNO = ordrlist[i].HheatNO;
                            barcode.HGroupID2 = ordrlist[i].HGroupID;
                            barcode.HEmpID2 = ordrlist[i].HEmpID;
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            ListRows.Add(barcode);
 
                            n += 1;                                                             //更新同批生成的条码数
                            oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");           //更新最大流水号
                        }
                    }
                    else if (HSelectBarCodeType == "BarCode_Pack")
                    {
                        int HBQty = ClsPub.isInt(ordrlist[i].HBQty);                            //箱数
 
                        for (int j = 0; j < HBQty; j++)
                        {
                            string HBarCode_Temp = "";                                                  //条码
                            string sTMNumber = "";                                                      //条码前缀
                            string LSH = "";                                                            //最大流水号
                            int HLen = 4;                                                               //流水号长度
 
                            //条码拼接所需字段
                            string HSupNumber = DBUtility.ClsPub.isStrNull(ordrlist[i].HSupNumber).Replace(".", "");             //供应商代码(去掉分隔符)
                            string sDateStr = sDate.ToString("yyMMdd");                                                         //启动日期(YYMMDD)
 
                            if (HSupNumber.Trim() == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "供应商代码不能为空,不能生成条码!";
                                return objJsonResult;
                            }
 
                            //条码前缀 = R+供应商代码(去掉分隔符)+启动日期(YYMMDD)+四位流水号
                            sTMNumber = "P" + HSupNumber + sDateStr;
 
                            //根据条码前缀获取最大流水号
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");
                            LSH = String.Format("{0:D" + HLen + "}", ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1);
 
                            //拼接条码
                            HBarCode_Temp = sTMNumber + LSH;
 
                            HBarCodeList barcode = new HBarCodeList();
                            barcode.HBarCode2 = HBarCode_Temp;
                            barcode.HBarCodeType2 = "托盘条码";
                            barcode.HBarCodeSubType2 = "托条码";
                            barcode.HEntryID2 = ClsPub.isStrNull(i + 1);
                            barcode.HMaterID2 = ordrlist[i].HMaterID;
                            barcode.HMaterNumber2 = ordrlist[i].HMaterNumber;
                            barcode.HMaterName2 = ordrlist[i].HMaterName;
                            barcode.HMaterModel2 = ordrlist[i].HMaterModel;
                            barcode.HPinfan2 = ordrlist[i].HPinfan;
                            barcode.HPinfanBarCode2 = ordrlist[i].HPinfanBarCode;
                            barcode.HAuxPropID2 = ordrlist[i].HAuxPropID;
                            barcode.HAuxPropNumber2 = ordrlist[i].HAuxPropNumber;
                            barcode.HAuxPropName2 = ordrlist[i].HAuxPropName;
                            barcode.HUnitID2 = ordrlist[i].HUnitID;
                            barcode.HUnitNumber2 = ordrlist[i].HUnitNumber;
                            barcode.HUnitName2 = ordrlist[i].HUnitName;
                            barcode.HQty2 = ClsPub.isStrNull(0);
                            barcode.HBatchNo2 = ordrlist[i].HBatchNo;
                            barcode.HSourceInterID2 = ordrlist[i].HMainID;
                            barcode.HSourceEntryID2 = ordrlist[i].HSubID;
                            barcode.HSourceBillNo2 = ordrlist[i].HBillNo;
                            barcode.HSourceBillType2 = ordrlist[i].HBillType;
                            barcode.HPrint = "0";
                            barcode.HWei = "";
                            barcode.HBarcodeNo = ClsPub.isStrNull(n + 1);
                            barcode.HBarcodeQtys = ordrlist[i].HBQty;
                            barcode.HSupID2 = ordrlist[i].HSupID;
                            barcode.HSupNumber2 = ordrlist[i].HSupNumber;
                            barcode.HSupName2 = ordrlist[i].HSupName;
                            barcode.HDeptID2 = ordrlist[i].HDeptID;
                            barcode.HDeptNumber2 = ordrlist[i].HDeptNumber;
                            barcode.HDeptName2 = ordrlist[i].HDeptName;
                            barcode.HRemark2 = ordrlist[i].HRemark;
                            barcode.HDate2 = ordrlist[i].HDate;
                            barcode.HShowDate2 = ordrlist[i].HShowDate;
                            barcode.HWhID2 = ordrlist[i].HWhID;
                            barcode.HWhNumber2 = ordrlist[i].HWhNumber;
                            barcode.HWhName2 = ordrlist[i].HWhName;
                            barcode.HSPID2 = ordrlist[i].HSPID;
                            barcode.HSPNumber2 = ordrlist[i].HSPNumber;
                            barcode.HSPName2 = ordrlist[i].HSPName;
                            barcode.HMTONo2 = ordrlist[i].HMTONo;
                            barcode.HCusID2 = ordrlist[i].HCusID;
                            barcode.HCusNumber2 = ordrlist[i].HCusNumber;
                            barcode.HCusName2 = ordrlist[i].HCusName;
                            barcode.HCusType2 = ordrlist[i].HCusType;
                            barcode.HSourceID2 = ordrlist[i].HSourceID;
                            barcode.HSourceNumber2 = ordrlist[i].HSourceNumber;
                            barcode.HSourceName2 = ordrlist[i].HSourceName;
                            barcode.HEndDate2 = ordrlist[i].HEndDate;
                            barcode.HSeOrderBillNo2 = ordrlist[i].HSeOrderBillNo;
                            barcode.HInnerBillNo2 = ordrlist[i].HInnerBillNo;
                            barcode.HMaker2 = ordrlist[i].HMaker;
                            barcode.HGiveAwayFlag2 = ordrlist[i].HGiveAwayFlag;
                            barcode.HCoilNO = ordrlist[i].HCoilNO;
                            barcode.HFurnaceNO = ordrlist[i].HFurnaceNO;
                            barcode.HFactory = ordrlist[i].HFactory;
                            barcode.HAuxQty = ordrlist[i].HAuxQty;
                            barcode.HheatNO = ordrlist[i].HheatNO;
                            barcode.HGroupID2 = ordrlist[i].HGroupID;
                            barcode.HEmpID2 = ordrlist[i].HEmpID;
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            ListRows.Add(barcode);
 
                            n += 1;                                                             //更新同批生成的条码数
                            oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");           //更新最大流水号
                        }
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "错误的条码类型,不能生成条码!";
                        return objJsonResult;
                    }
                }
            }
 
 
            try
            {
                oCN.BeginTran();
                for (int i = 0; i < ListRows.Count; i++)
                {
                    if (ClsPub.isLong(ListRows[i].HMaterID2) != 0)
                    {
                        string HBarCode = ClsPub.isStrNull(ListRows[i].HBarCode2);
                        string HBarCodeType = ClsPub.isStrNull(ListRows[i].HBarCodeType2);
                        string HBarCodeSubType = ClsPub.isStrNull(ListRows[i].HBarCodeSubType2);
                        Int64 HMaterID = ClsPub.isLong(ListRows[i].HMaterID2);
                        Int64 HEntryID = ClsPub.isLong(ListRows[i].HEntryID2);
                        Int64 HAuxPropID = ClsPub.isLong(ListRows[i].HAuxPropID2);
                        Int64 HUnitID = ClsPub.isLong(ListRows[i].HUnitID2);
                        double HQty2 = ClsPub.isDoule(ListRows[i].HQty2);
                        string HWei = ClsPub.isStrNull(ListRows[i].HWei);
                        string HBatchNo2 = ClsPub.isStrNull(ListRows[i].HBatchNo2);
                        Int64 HSourceInterID = ClsPub.isLong(ListRows[i].HSourceInterID2);
                        Int64 HSourceEntryID = ClsPub.isLong(ListRows[i].HSourceEntryID2);
                        string HSourceBillNo = ClsPub.isStrNull(ListRows[i].HSourceBillNo2);
                        string HSourceBillType = ClsPub.isStrNull(ListRows[i].HSourceBillType2);
                        Int64 HBarcodeQtys = ClsPub.isLong(ListRows[i].HBarcodeQtys);
                        Int64 HBarcodeNo = ClsPub.isLong(ListRows[i].HBarcodeNo);
                        Int64 HSupID = ClsPub.isLong(ListRows[i].HSupID2);
                        Int64 HDeptID = ClsPub.isLong(ListRows[i].HDeptID2);
                        Int64 HWhID = ClsPub.isLong(ListRows[i].HWhID2);
                        Int64 HSPID = ClsPub.isLong(ListRows[i].HSPID2);
                        string HRemark = ClsPub.isStrNull(ListRows[i].HRemark2);
                        string HMaterName = ClsPub.isStrNull(ListRows[i].HMaterName2);
                        string HMaterModel = ClsPub.isStrNull(ListRows[i].HMaterModel2);
                        string HPinfan = ClsPub.isStrNull(ListRows[i].HPinfan2);
                        string HMTONo = ClsPub.isStrNull(ListRows[i].HMTONo2);
                        Int64 HCusID = ClsPub.isLong(ListRows[i].HCusID2);
                        string HCusType = ClsPub.isStrNull(ListRows[i].HCusType2);
                        DateTime HEndDate = ClsPub.isDate(ListRows[i].HEndDate2);
                        string HWorkLineName = ClsPub.isStrNull(ListRows[i].HSourceName2);
                        string HSeOrderBillNo = ClsPub.isStrNull(ListRows[i].HSeOrderBillNo2);
                        string HInnerBillNo = ClsPub.isStrNull(ListRows[i].HInnerBillNo2);
                        bool HGiveAwayFlag = ClsPub.isBool(ListRows[i].HGiveAwayFlag2);
                        int HPrintQty = ClsPub.isInt(ListRows[i].HPrint);
 
                        string HCoilNO2 = ClsPub.isStrNull(ListRows[i].HCoilNO);
                        string HFurnaceNO2 = ClsPub.isStrNull(ListRows[i].HFurnaceNO);
                        string HFactory2 = ClsPub.isStrNull(ListRows[i].HFactory);
                        Int64 HAuxQty2 = ClsPub.isLong(ListRows[i].HAuxQty);
                        string HheatNO2 = ClsPub.isStrNull(ListRows[i].HheatNO);
                        DateTime HProduceDate = ClsPub.isDate(ListRows[i].HProduceDate);
                        DateTime HExpiryDate = ClsPub.isDate(ListRows[i].HExpiryDate);
                        int HGroupID2 = ClsPub.isInt(ListRows[i].HGroupID2);
                        Int64 HEmpID2 = ClsPub.isLong(ListRows[i].HEmpID2);
                        string HCusModel2 = ClsPub.isStrNull(ListRows[i].HCusModel2);
                        string HCusMaterName2 = ClsPub.isStrNull(ListRows[i].HCusMaterName2);
                        string HCheckEmpName2 = ClsPub.isStrNull(ListRows[i].HCheckEmpName2);
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HBarCodeSubType,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,HEmpID,HCusModel,HCusMaterName,HCheckEmpName " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "','" + HBarCodeSubType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID2.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 + "'," + HEmpID2.ToString() + ",'" + HCusModel2 + "','" + HCusMaterName2 + "','" + HCheckEmpName2 + "'" + ")");
 
                    }
                }
                //增加 条码超过未生成功能控制
 
                //
 
                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 = "[0000-1-037]获取资源绑定数据成功!";
                    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 = "[0000-2-020]没有返回任何结果,条码不存在!";
                    objJsonResult.data = null;
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + e.Message;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}