duhe
2024-04-23 88d14b74edc9430c061c10fee97746566ddaf85d
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
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
using Pub_Class;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using System.Drawing.Printing;
using System.IO;
using System.Management;
 
namespace WarM
{
    public partial class Gy_BarCodeBill_automaticallyByPLC_New : Form
    {
        public Gy_BarCodeBill_automaticallyByPLC_New()
        {
            InitializeComponent();
        }
        //定义
        public const Int16 HTagCol = 0;
        public const Int16 HSnoCol = 1;
        public const Int16 HMainIDCol = 2;
        public const Int16 HSubIDCol = 3;
        public const Int16 HBillNoCol = 4;
        public const Int16 HBillTypeCol = 5;
        public const Int16 HMaterIDCol = 6;
        public const Int16 HMaterNumberCol = 7;
        public const Int16 HMaterNameCol = 8;
        public const Int16 HPinfanCol = 9;//
        public const Int16 HMaterModelCol = 10;//
        public const Int16 HModelCol = 11;
        public const Int16 HAuxPropIDCol = 12;
        public const Int16 HAuxPropNumberCol = 13;
        public const Int16 HAuxPropNameCol = 14;
        public const Int16 HUnitIDCol = 15;
        public const Int16 HUnitNumberCol = 16;
        public const Int16 HUnitNameCol = 17;
        public const Int16 HBarCodeTypeCol = 18;
        public const Int16 HBatchManagerCol = 19;
        public const Int16 HBatchNoCol = 20;
        public const Int16 HGiveAwayFlagCol = 21;
        public const Int16 HQtyCol = 22;
        public const Int16 HMinQtyCol = 23;
        public const Int16 HBQtyCol = 24;
        public const Int16 HPackQtyCol = 25;
        public const Int16 HProduceDateCol = 26;
        public const Int16 HExpiryDateCol = 27;
        public const Int16 HDeptIDCol = 28;
        public const Int16 HDeptNumberCol = 29;
        public const Int16 HDeptNameCol = 30;
        public const Int16 HSourceIDCol = 31;
        public const Int16 HSourceNumberCol = 32;
        public const Int16 HSourceNameCol = 33;
        public const Int16 HDateCol = 34;
        public const Int16 HEndDateCol = 35;
        public const Int16 HSupIDCol = 36;
        public const Int16 HSupNumberCol = 37;
        public const Int16 HSupNameCol = 38;
        public const Int16 HCusIDCol = 39;
        public const Int16 HCusNumberCol = 40;
        public const Int16 HCusNameCol = 41;
        public const Int16 HCusTypeCol = 42;
        public const Int16 HSourceInterIDCol = 43;
        public const Int16 HSourceEntryIDCol = 44;
        public const Int16 HSourceBillNoCol = 45;
        public const Int16 HSourceBillTypeCol = 46;
        public const Int16 HInstructIDCol = 47;
        public const Int16 HInstructNoCol = 48;
        public const Int16 HSeOrderBillIDCol = 49;
        public const Int16 HSeOrderBillNoCol = 50;
        public const Int16 HSeOrderSEQCol = 51;
        public const Int16 HWhIDCol = 52;
        public const Int16 HWhNumberCol = 53;
        public const Int16 HWhNameCol = 54;
        public const Int16 HSPIDCol = 55;
        public const Int16 HSPNumberCol = 56;
        public const Int16 HSPNameCol = 57;
        public const Int16 HinitQtyCol = 58;
        public const Int16 HRemarkCol = 59;
        public const Int16 HPinfanBarCodeCol = 60;
        public const Int16 HMTONoCol = 61;
        public const Int16 HShowDateCol = 62;
        public const Int16 HInnerBillNoCol = 63;
        public const Int16 HMakerCol = 64;
        public const Int16 HISKFPERIODCol = 65;
        public const Int16 HEXPUNITCol = 66;
        public const Int16 HEXPPERIODCol = 67;
 
        public Int16 HSelectCol = 0;
        public Int16 HSno2Col = 1;
        public Int16 HTMCol = 2;
        public Int16 HBarCodeType2Col = 3;
        public Int16 HMaterID2Col = 4;
        public Int16 HMaterNumber2Col = 5;
        public Int16 HMaterName2Col = 6;
        public Int16 HPinfan2Col = 7;
        public Int16 HMaterModel2Col = 8;
        public Int16 HModel2Col = 9;
        public Int16 HAuxPropID2Col = 10;
        public Int16 HAuxPropNumber2Col = 11;
        public Int16 HAuxPropName2Col = 12;
        public Int16 HBatchNo2Col = 13;
        public Int16 HGiveAwayFlag2Col = 14;
        public Int16 HUnitID2Col = 15;
        public Int16 HUnitNumber2Col = 16;
        public Int16 HUnitName2Col = 17;
        public Int16 HQty2Col = 18;
        public Int16 HWeiCol = 19;
        public Int16 HPrintCol = 20;
        public Int16 HDeptID2Col = 21;
        public Int16 HDeptNumber2Col = 22;
        public Int16 HDeptName2Col = 23;
        public Int16 HSourceID2Col = 24;
        public Int16 HSourceNumber2Col = 25;
        public Int16 HSourceName2Col = 26;
        public Int16 HDate2Col = 27;
        public Int16 HEndDate2Col = 28;
        public Int16 HBarcodeNoCol = 29;
        public Int16 HBarcodeQtysCol = 30;
        public Int16 HSupID2Col = 31;
        public Int16 HSupNumber2Col = 32;
        public Int16 HSupName2Col = 33;
        public Int16 HCusID2Col = 34;
        public Int16 HCusNumber2Col = 35;
        public Int16 HCusName2Col = 36;
        public Int16 HCusType2Col = 37;
        public Int16 HSourceInterID2Col = 38;
        public Int16 HSourceEntryID2Col = 39;
        public Int16 HSourceBillNo2Col = 40;
        public Int16 HSourceBillType2Col = 41;
        public Int16 HInstructID2Col = 42;
        public Int16 HInstructNo2Col = 43;
        public Int16 HSeOrderBillID2Col = 44;
        public Int16 HSeOrderBillNo2Col = 45;
        public Int16 HSeOrderSEQ2Col = 46;
        public Int16 HWhID2Col = 47;
        public Int16 HWhNumber2Col = 48;
        public Int16 HWhName2Col = 49;
        public Int16 HSPID2Col = 50;
        public Int16 HSPNumber2Col = 51;
        public Int16 HSPName2Col = 52;
        public Int16 HRemark2Col = 53;
        public Int16 HPinfanBarCode2Col = 54;
        public Int16 HMTONo2Col = 55;
        public Int16 HShowDate2Col = 56;
        public Int16 HInnerBillNo2Col = 57;
        public Int16 HMaker2Col = 58;
        public Int16 HEntryID2Col = 59;
        public Int16 HProduceDate2Col = 60;
        public Int16 HExpiryDate2Col = 61;
        public Int16 HISKFPERIOD2Col = 62;
        public Int16 HEXPUNIT2Col = 63;
        public Int16 HEXPPERIOD2Col = 64;
        //
        public string ModName = "85";
        public string ModCaption = "条码生成";
        public const string ModRightName = "Gy_BarCodeBill";
        public const string ModRightNameSourceQty = ModRightName + "_SourceQty"; //超源单数量控制
        public bool BillChange;   //
 
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DBUtility.ClsXt_BaseBill BaseBill;
        //public WarM.WMSWeb.WebService1 oWeb = new WarM.WMSWeb.WebService1();
        public Int64 KeyID;
        public bool grdStatus;
        //public DAL.ClsGy_BarCodeBill BillNew =new  DAL.ClsGy_BarCodeBill();
        //public DAL.ClsGy_BarCodeBill BillOld = new DAL.ClsGy_BarCodeBill();
        public DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public int selectRow = 0;
        public int selectRow2 = 0;
        public Int64 HInterID = 0;      //内码
        public Int64 HOrgID = -1;
        public string HOrgNumber = "";
        public string ERPMode = ""; //ERP模式(WISE、CLOUD)
        public string CampanyName = ""; //客户定制化名称
        public string SourceQtyCtl = ""; //超源单数量控制
        public long PrintQty = 0;               //允许条码打印次数
        public string PrintQtyCtl = "";         //条码打印次数控制
        public string UpdatePrintQtyCtl = "";   //条码打印次数更新
                                                //-------------------------------------------------------------------------
 
        //
        //Socket通讯
        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        long produceQty = 0;         //接收通讯,需要生成几个条码
 
 
        #region 固定代码
 
        //清空界面
        public void Sub_ClearBill()
        {
            ////表体清空
            //grdMain.Rows.Clear();
            //grdSub.Rows.Clear();
            cmbHBarCodeType.Items.Clear();
            cmbSourceBillType.Items.Clear();
 
            //根据系统参数获取对应的条码类型(夏宝电器、博日   以后使用条码规则表)
            ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
            string sCapName = oClsXt_SystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
            if (sCapName == "夏宝电器")
            {
                cmbHBarCodeType.Items.Add("内销机条码");
                cmbHBarCodeType.Items.Add("外销机条码");
                cmbHBarCodeType.Items.Add("半成品条码");
            }
            else if (sCapName == "博日科技")
            {
                cmbHBarCodeType.Items.Add("仪器外购件条码普通规则");
                cmbHBarCodeType.Items.Add("仪器外购件条码容器规则");
                cmbHBarCodeType.Items.Add("仪器成品条码规则");
                cmbHBarCodeType.Items.Add("试剂成品条码规则");
            }
            else if (sCapName == "中控")
            {
                cmbHBarCodeType.Items.Add("唯一条码");
            }
            else
            {
                //
                cmbHBarCodeType.Items.Add("唯一条码");
                cmbHBarCodeType.Items.Add("品种条码");
                cmbHBarCodeType.Items.Add("批次条码");
                //cmbHBarCodeType.Items.Add("托盘条码");
            }
 
            //源单类型
            if (sCapName == "中控")
            {
                cmbSourceBillType.Items.Add("生产汇报单");
                cmbSourceBillType.Items.Add("收料通知单");
            }
            else
            {
                cmbSourceBillType.Items.Add("生产订单");
                cmbSourceBillType.Items.Add("生产汇报单");
                cmbSourceBillType.Items.Add("采购订单");
                cmbSourceBillType.Items.Add("收料通知单");
                cmbSourceBillType.Items.Add("委外订单");
                cmbSourceBillType.Items.Add("工序汇报单");
                cmbSourceBillType.Items.Add("工序流转卡");
                cmbSourceBillType.Items.Add("退货通知单");
                cmbSourceBillType.Items.Add("其他入库单");
                cmbSourceBillType.Items.Add("直接调拨单");
                cmbSourceBillType.Items.Add("采购退料单");
                cmbSourceBillType.Items.Add("生产退料单");
                cmbSourceBillType.Items.Add("组装拆卸单");
            }
            //
            DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
            //组织下拉列表
            DataSet Ds1 = oCn.RunProcReturn("select * from Xt_ORGANIZATIONS with(nolock) where HItemID=" + ClsPub.HOrgID, "Xt_ORGANIZATIONS", ref DBUtility.ClsPub.sExeReturnInfo);
            if (Ds1.Tables[0].Rows.Count != 0)
            {
                cmbHOrgID.Text = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HName"]);
            }
 
            //打印机下拉列表
            PrintDocument fPrintDocument = new PrintDocument();
            string defaultPrinter = fPrintDocument.PrinterSettings.PrinterName;
            comboBox_PrinterParams.Items.Clear();
            for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
            {
                string tmp = PrinterSettings.InstalledPrinters[i];
                if (tmp == defaultPrinter)
                {
                    tmp = tmp + "(默认)";
                }
                comboBox_PrinterParams.Items.Add(tmp);
            }
 
 
            //产线下拉列表
            DataSet DsSource = oCn.RunProcReturn("select * from Gy_Source where HUSEORGID =" + ClsPub.HOrgID, "Gy_Source");
            if (DsSource != null)
            {
                comboBox_SourceNameParams.Items.Clear();
                for (int i = 0; i < DsSource.Tables[0].Rows.Count; i++)
                {
                    comboBox_SourceNameParams.Items.Add(DsSource.Tables[0].Rows[i]["HName"]);
                }
            }
 
 
            //读取配置文件设置配置
            readParams();
            //设置工单信息
            textBox_SourceName.Text = comboBox_SourceNameParams.Text;
 
            txtHMaker.Text = ClsPub.CurUserName;
            txtHMakeDate.Text = "";
            txtHChecker.Text = "";
            txtHCheckDate.Text = "";
            txtHCloseMan.Text = "";
            txtHCloseDate.Text = "";
            txtHDeleteMan.Text = "";
            txtHDeleteDate.Text = "";
            txtHUpDater.Text = "";
            txtHUpDateDate.Text = "";
            initGrid();
            grdList.DataSource = null;
            grdBillBarCodeList.DataSource = null;
 
            tabControl1.SelectedIndex = 3;
        }
 
        //保存列宽
        private void bclk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.SaveGrid(grdSub, this.Name + "grdSub");
            DBUtility.Xt_BaseBillFun.SaveGrid(grdList, this.Name + "grdList");
        }
 
        //默认列宽
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdSub, this.Name + "grdSub");
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdList, this.Name + "grdList");
        }
 
        //增行按钮  
        private void AddRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
        }
 
        //删行按纽  
        private void DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
 
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
            this.Sub_SaveBill();
            Display();
 
            Display4();
        }
 
        //重置按纽
        private void cz_Click(object sender, EventArgs e)
        {
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew || BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
            {
                if (MessageBox.Show("确定要清空当前界面信息,重置界面?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    this.Sub_AddBill();
                }
            }
            grdMain.Columns[HBillNoCol].ReadOnly = false;
            tabControl1.SelectedIndex = 3;
        }
 
        //新增单据
        private void Sub_AddBill()
        {
            this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            this.Sub_OperStatus();//设置TOOLBAR
            this.Sub_ClearBill();//清空界面
        }
 
        //退出按钮
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        //离开单元格
        private void grdMain_LeaveCell(object sender, EventArgs e)
        {
            oSumGrid.LeaveCell();
        }
 
        //网格单元格变化事件
        private void grdMain_RowColChange(object sender, EventArgs e)
        {
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            //if (oSumGrid.Changelock)
            //    return;
            //if(oSumGrid.EditStatus)
            //{
            if (!CheckGridRow(oSumGrid.OldCell.Row))
                return;
            //}
        }
 
        private void Gy_BarCodeBill_Paint(object sender, PaintEventArgs e)//画线
        {
            Graphics g = this.panel2.CreateGraphics();
            Pen p = new Pen(Color.Gray);
            p.Width = 1;
            g.DrawLine(p, new Point(txtHMaker.Left, txtHMaker.Top + txtHMaker.Height), new Point(txtHMaker.Left + txtHMaker.Width, txtHMaker.Top + txtHMaker.Height));
            g.DrawLine(p, new Point(txtHMakeDate.Left, txtHMakeDate.Top + txtHMakeDate.Height), new Point(txtHMakeDate.Left + txtHMakeDate.Width, txtHMakeDate.Top + txtHMakeDate.Height));
            //
            g.DrawLine(p, new Point(txtHChecker.Left, txtHChecker.Top + txtHChecker.Height), new Point(txtHChecker.Left + txtHChecker.Width, txtHChecker.Top + txtHChecker.Height));
            g.DrawLine(p, new Point(txtHCheckDate.Left, txtHCheckDate.Top + txtHCheckDate.Height), new Point(txtHCheckDate.Left + txtHCheckDate.Width, txtHCheckDate.Top + txtHCheckDate.Height));
            //
            g.DrawLine(p, new Point(txtHCloseMan.Left, txtHCloseMan.Top + txtHCloseMan.Height), new Point(txtHCloseMan.Left + txtHCloseMan.Width, txtHCloseMan.Top + txtHCloseMan.Height));
            g.DrawLine(p, new Point(txtHCloseDate.Left, txtHCloseDate.Top + txtHCloseDate.Height), new Point(txtHCloseDate.Left + txtHCloseDate.Width, txtHCloseDate.Top + txtHCloseDate.Height));
            //
            g.DrawLine(p, new Point(this.txtHDeleteMan.Left, txtHDeleteMan.Top + txtHDeleteMan.Height), new Point(txtHDeleteMan.Left + txtHDeleteMan.Width, txtHDeleteMan.Top + txtHDeleteMan.Height));
            g.DrawLine(p, new Point(txtHDeleteDate.Left, txtHDeleteDate.Top + txtHDeleteDate.Height), new Point(txtHDeleteDate.Left + txtHDeleteDate.Width, txtHDeleteDate.Top + txtHDeleteDate.Height));
            //
            g.DrawLine(p, new Point(this.txtHUpDater.Left, txtHUpDater.Top + txtHUpDater.Height), new Point(txtHUpDater.Left + txtHUpDater.Width, txtHUpDater.Top + txtHUpDater.Height));
            g.DrawLine(p, new Point(txtHUpDateDate.Left, txtHUpDateDate.Top + txtHUpDateDate.Height), new Point(txtHUpDateDate.Left + txtHUpDateDate.Width, txtHUpDateDate.Top + txtHUpDateDate.Height));
            //控件位置设置
 
        }
 
        //控件位置
        private void Sub_ControlLocation()
        {
            //gbUp.Width = P1.Width - 20;
            //gbUp.Left = 10;
            //gbUp.Height = P1.Height - 35;
            //gbUp.Top = 30;
        }
 
        //窗体加载
        private void Gy_BarCodeBill_Load(object sender, EventArgs e)
        {
            //打印初始化   
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            this.Text = ModCaption;
            this.lblCaption.Text = ModCaption;
            //加载组织信息
            Sub_AddOrdList();
            //加载工厂代码信息
            Sub_AddWorksNumberList();
        }
 
        //加载组织信息
        private void Sub_AddOrdList()
        {
            DataSet ds;
            DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
            ds = oClsGy_ORGANIZATIONS_View.GetList();
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("获取组织失败");
                return;
            }
            cmbHOrgID.Items.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                cmbHOrgID.Items.Add(DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HName"]));
            }
        }
 
        //加载工厂代码信息
        private void Sub_AddWorksNumberList()
        {
            //获取系统参数
            ClsXt_SystemParameter oSystemParameter = new ClsXt_SystemParameter();
            if (oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo) == false)
            {
                MessageBox.Show("获取系统参数失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示");
                return;
            }
            else
            {
                ERPMode = oSystemParameter.omodel.WMS_WMSStockCtl_ERPMode;
                CampanyName = oSystemParameter.omodel.WMS_CampanyName;
                SourceQtyCtl = oSystemParameter.omodel.BarCode_SourceQtyCtl;
                PrintQty = oSystemParameter.omodel.BarCode_PrintQty;
                PrintQtyCtl = oSystemParameter.omodel.BarCode_PrintQtyCtl;
                UpdatePrintQtyCtl = oSystemParameter.omodel.BarCode_UpdatePrintQtyCtl;
            }
            //系统参数,有源单生成条码,生成条码数量可否超源单数量控制(N为不可超源单数量)
            if (SourceQtyCtl == "N")
            {
                //系统参数为不可超源单数量时,再次判断用户权限是否可超源单数量
                //判断权限
                if (ClsPub.Security_Log(ModRightNameSourceQty, 3, false, ClsPub.CurUserName))
                {
                    SourceQtyCtl = "Y";
                }
            }
 
            cmbHWorksNumber.Items.Clear();
            if (CampanyName == "飞龙") //系统参数  客户定制化名称
            {
                cmbHWorksNumber.Items.Add("ZL");
                cmbHWorksNumber.Items.Add("ST");
                cmbHWorksNumber.Items.Add("SQ");
                cmbHWorksNumber.Items.Add("MQ");
            }
            else
            {
                cmbHWorksNumber.Items.Add("");
            }
        }
 
        //窗体尺寸变化时
        private void Gy_BarCodeBill_Resize(object sender, EventArgs e)
        {
            //Sub_ControlLocation();
        }
 
        //根据编辑状态 设置 控件是否允许录入    
        private void Sub_LrtextStatus(bool TextEnabled)
        {
            if (TextEnabled == true)
            {
                //控件全部有效
                gbUp.Enabled = true;
                grdMain.BackColor = ClsPub.EditColor;
            }
            else
            {   //控件全部无效
                gbUp.Enabled = false;
                grdMain.BackColor = ClsPub.ViewColor;
            }
        }
 
        //timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            Sub_ControlLocation();
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            {
                //this.Sub_ShowBill();
            }
            else
            {
                this.Sub_AddBill();
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        //窗体卸载
        private void Gy_BarCodeBill_FormClosing(object sender, FormClosingEventArgs e)
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        //TOOLBAR状态  按钮是否灰度
        public void Sub_OperStatus()
        {
            switch (BillStatus)
            {
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_View:
                    //浏览状态
                    yl.Enabled = true;
                    AddRow.Enabled = false;
                    DelRow.Enabled = false;
                    bc.Enabled = false;
                    cz.Enabled = false;
                    tc.Enabled = true;
                    //未审核
                    if (txtHChecker.Text.Trim() == "")
                    {
                        //未审核
                        pic1.Visible = false;
                        pic1.Image = null;
                        //
                    }
                    else if (txtHCloseMan.Text.Trim() == "" && txtHChecker.Text.Trim() != "")//审核未关闭
                    {
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Checked.jpg");
                        //
                    }
                    else//已关闭
                    {
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Closed.jpg");
                        //
                    }
                    if (txtHDeleteMan.Text.Trim() == "")
                    {
                    }
                    else //已作废
                    {
                        AddRow.Enabled = false;
                        DelRow.Enabled = false;
                        bc.Enabled = false;
                        cz.Enabled = false;
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Deleted.jpg");
                        //
                    }
                    Sub_LrtextStatus(false);
                    grdStatus = false;
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew:
                    //新增状态
                    yl.Enabled = true;
                    AddRow.Enabled = true;
                    DelRow.Enabled = true;
                    bc.Enabled = true;
                    cz.Enabled = true;
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify:
                    //修改状态
                    yl.Enabled = true;
                    AddRow.Enabled = true;
                    DelRow.Enabled = true;
                    bc.Enabled = true;
                    cz.Enabled = true;
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
            }
 
        }
 
        #endregion 
 
        #region  读写类
 
        //单据完整性判断          未完成
        private bool Sub_AllowSave()
        {
            //明细表是否为零行
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (!IsNullRow(i))
                {
                    b = true;
                    break;
                }
            }
            if (b == false)
            {
                MessageBox.Show("明细行不存在!", "提示");
                return false;
            }
 
            string sHRemark = "";
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                long HSno = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HSnoCol].Value);                  // 序号
                string HBarCodeType = cmbHBarCodeType.Text;                                                  // 条码类型
                string HSourceBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillNoCol].Value); // 源单单号
                long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);          // 物料内码
                string HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);     // 批号
                long HAuxPropID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HAuxPropIDCol].Value);      // 辅助属性ID
                double HSourceQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[HinitQtyCol].Value);     // 源单数量
                double HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);               // 数量
                double HMinQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);          // 最小包装数
 
                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)
                    {
                        MessageBox.Show("条码生成完整性判断错误!");
                        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"]);
                    }
                    else if (DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HExpiryDateCol].Value) == "")
                    {
                        if (DBUtility.ClsPub.isBool(oDsCheck.Tables[0].Rows[0]["HISKFPERIOD"]))
                        {
                            DateTime HProduceDate;  //生产日期
                            string HEXPUNIT;        //保质期单位
                            int HEXPPERIOD;         //保质期
 
                            HProduceDate = dtpHDate.Value;
                            HEXPUNIT = DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HEXPUNIT"]);
                            HEXPPERIOD = DBUtility.ClsPub.isInt(oDsCheck.Tables[0].Rows[0]["HEXPPERIOD"]);
 
                            grdMain.Rows[j].Cells[HISKFPERIODCol].Value = 1;
                            grdMain.Rows[j].Cells[HEXPUNITCol].Value = HEXPUNIT;
                            grdMain.Rows[j].Cells[HEXPPERIODCol].Value = HEXPPERIOD.ToString();
                            grdMain.Rows[j].Cells[HProduceDateCol].Value = HProduceDate.ToShortDateString();
 
                            if (HEXPUNIT == "Y")
                            {
                                grdMain.Rows[j].Cells[HExpiryDateCol].Value = HProduceDate.AddYears(HEXPPERIOD).ToShortDateString();
                            }
                            else if (HEXPUNIT == "M")
                            {
                                grdMain.Rows[j].Cells[HExpiryDateCol].Value = HProduceDate.AddMonths(HEXPPERIOD).ToShortDateString();
                            }
                            else
                            {
                                grdMain.Rows[j].Cells[HExpiryDateCol].Value = HProduceDate.AddDays(HEXPPERIOD).ToShortDateString();
                            }
                        }
                        else
                        {
                            grdMain.Rows[j].Cells[HISKFPERIODCol].Value = 0;
                            grdMain.Rows[j].Cells[HEXPUNITCol].Value = "";
                            grdMain.Rows[j].Cells[HEXPPERIODCol].Value = 0;
                            grdMain.Rows[j].Cells[HProduceDateCol].Value = "";
                            grdMain.Rows[j].Cells[HExpiryDateCol].Value = "";
                        }
                    }
                }
            }
            if (sHRemark != "")
            {
                MessageBox.Show(sHRemark);
                return false;
            }
            return true;
        }
 
        //保存单据
        private bool Sub_SaveBill()
        {
            //获取内码
            HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            ////若MAINDI重复则重新获取
            //if (BaseBill.IsExistMainID(ref DBUtility.ClsPub.sExeReturnInfo, HInterID, Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew))
            //{
            //    HInterID = DBUtility.ClsPub.CreateBillID(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            //}
            // 
            DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
            HOrgNumber = "";
            if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
            {
                HOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
                HOrgNumber = DBUtility.ClsPub.isStrNull(oClsGy_ORGANIZATIONS_View.omodel.HNumber);
            }
            if (HOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return false;
            }
            lblCaption.Focus();
            if (!Sub_AllowSave())//单据完整性判断
            {
                return false;
            }
            //bc.Enabled = false;
            if (cmbHBarCodeType.Text == "仪器成品条码规则")
            {
                SaveBarCode_bori(); //物料编码+序列号+生产日期
            }
            else
            {
                SaveBarCode();
            }
            return true;
        }
 
        //生成条码
        private void SaveBarCode()
        {
            grdSub.Rows.Clear();
            int LSHlen = 6;             //流水号长度
            int SumLen = 10;            //总长度
            string TM = "";             //条码
            string HNumber = "";        //物料内码
            string HMaterNumber = "";   //物料代码
            double HSumQty = 0;         //产品数量
            double HMinQty = 0;         //最小包装数
            Int64 HBQty = 0;              //箱数
            double HQty = 0;            //数量
            string WeiShu = "";         //尾数
            Int64 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;
            Int64 n = 0;                  //同一批生成条码中的第几条
            string sTMNumber = "";      //条码自定义前缀
            string sSourceBillNo = "";       //源单号
            string sSourceEntryID = "";       //行号(源单子ID)
            DataSet Ds;
            //Ds = oCn.RunProcReturn("exec GetLSH '" + ClsPub.GetServerDate(0) + "'", "GetLSH");
            //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                {
                    HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
                    HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                    //日期获取方式
                    sDate = dtpHDate.Value.ToShortDateString();
                    //
                    if (cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则") //单据日期(收料通知单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                    }
                    else if (cmbHBarCodeType.Text == "试剂成品条码规则")// 失效日期(生产订单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
                    }
                    else if (CampanyName == "夏宝电器")// 日期:生产订单 条码日期
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                    }
                    HYasuoji = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanCol].Value); //压缩机代码(夏宝电器)
                    HModelName = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusTypeCol].Value); //机型(夏宝电器)
                    HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillNoCol].Value); //生产订单号(夏宝电器)
                    HBarCodeBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value); //条码批次号(夏宝电器)
                    HBarCodeDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSupNumberCol].Value); //条码日期(夏宝电器)
                    //
                    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 (cmbHBarCodeType.Text == "唯一条码")
                    {
                        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.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                        else if (CampanyName == "飞龙")
                        {
                            string HWorksNumber = "";
                            HWorksNumber = cmbHWorksNumber.Text;
                            if (HWorksNumber == "")
                            {
                                MessageBox.Show("工厂代码不能为空!");
                                return;
                            }
                            //条码前缀 = 工厂代码 + 物料内码 + 日期
                            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.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                        else if (CampanyName == "中控")
                        {
                            sSourceBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillNoCol].Value);
                            sSourceEntryID = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSubIDCol].Value);
                            if (sSourceBillNo == "")
                            {
                                //条码前缀 = 组织代码 + 物料代码 + 年 + 月 + 日
                                sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
                                Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                            }
                            else
                            {
                                //条码 = 源单单号 + 物料ID + 行号
                                sTMNumber = sSourceBillNo + HNumber + sSourceEntryID;
                            }
                        }
                        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.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                    }
                    else if (cmbHBarCodeType.Text == "品种条码")
                    {
                        if (CampanyName == "五云") //系统参数  客户定制化名称
                        {
                            TM = HNumber + ";" + DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMTONoCol].Value);
                        }
                        else
                        {
                            TM = HOrgNumber + HNumber;
                        }
                    }
                    else if (cmbHBarCodeType.Text == "批次条码")
                    {
                        TM = HOrgNumber + HNumber + HBatchNo;
                    }//博日特殊处理
                    else if (cmbHBarCodeType.Text == "序列码")
                    {
                        //条码规则: GX+物料内码+年年月月日日+5位流水号
                        LSHlen = 5;
                        //条码前缀 = GX+物料内码+年年月月日日
                        sTMNumber = "GX" + HNumber + sYear + sPeriod + sDay;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                    }
                    else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则")
                    {
                        //物料编码+单据日期(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.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                    }
                    else if (cmbHBarCodeType.Text == "仪器成品条码规则") //另外处理了
                    {
                        //物料编码+序列号+生产日期
                        //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.isLong(Ds.Tables[0].Rows[0][0]);
                    }
                    else if (cmbHBarCodeType.Text == "试剂成品条码规则")
                    {
                        //物料编码+生产批号+流水号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.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 6;
                    }
                    else if (cmbHBarCodeType.Text == "内销机条码")
                    {
                        //制造本部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.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                        if (sTMNumber.Length != 16 && sTMNumber.Length != 15)
                        {
                            MessageBox.Show("条码长度不够15或16位,是否数据不全!制造本部1位:[0] + 机型代码5位:[" + HModelName + "] + 年月日4或5位:[" + HBarCodeDate + "] + 批次号2位:[" + HBarCodeBatchNo + "]+ 压缩机1位:[" + HYasuoji + "]+00 ; ");
                            return;
                        }
                    }
                    else if (cmbHBarCodeType.Text == "外销机条码")
                    {
                        //物料代码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.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                        if (sTMNumber.Length != 18 && sTMNumber.Length != 17)
                        {
                            MessageBox.Show("条码长度不够17或18位,是否数据不全!物料代码11位:[" + HMaterNumber.Replace(".", "") + "]+年月日4或5位:[" + HBarCodeDate + "]+批次号2位:[" + HBarCodeBatchNo + "];");
                            return;
                        }
                    }
                    else if (cmbHBarCodeType.Text == "半成品条码")
                    {
                        //生产订单号+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.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                    }
                    //else if (cmbHBarCodeType.Text == "托盘条码")
                    //{
                    //    TM = HOrgNumber + HNumber + LSH2;
                    //}
                    else
                    {
                        MessageBox.Show("错误的条码类型,不能生成条码!");
                        return;
                    }
 
                    Int64 HBQty2 = 0;              //箱数
                    HBQty2 = ClsPub.isLong(grdMain.Rows[j].Cells[HBQtyCol].Value);
                    HBQty = HBQty + ClsPub.isLong(grdMain.Rows[j].Cells[HBQtyCol].Value);
                    HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);
                    HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
                    n = 0;
                    int nn = 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 (cmbHBarCodeType.Text == "唯一条码")
                        {
                            if (CampanyName == "中控")
                            {
                                if (sSourceBillNo == "")
                                {
                                    //条码编号 = 条码前缀 + 流水号
                                    TM = sTMNumber + LSH2;
                                }
                                else
                                {
                                    if (HBQty2 > 1)
                                    {
                                        MessageBox.Show("生产汇报单、收料通知单生成条码时,箱数不能大于1!");
                                        bc.Enabled = true;
                                        return;
                                    }
                                    //条码编号 = 条码前缀
                                    TM = sTMNumber;
                                }
                            }
                            else
                            {
                                //条码编号 = 条码前缀 + 流水号
                                TM = sTMNumber + LSH2;
                            }
                        }
                        else if (cmbHBarCodeType.Text == "序列码")
                        {
                            //条码编号 = 条码前缀 + 流水号
                            TM = sTMNumber + LSH2;
                        }
                        else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则" || cmbHBarCodeType.Text == "试剂成品条码规则"
                            || cmbHBarCodeType.Text == "半成品条码" || cmbHBarCodeType.Text == "外销机条码")
                        {
                            TM = sTMNumber + LSH2;
 
                        }
                        else if (cmbHBarCodeType.Text == "内销机条码")
                        {
                            TM = sTMNumber + LSH2 + "0";
                        }
                        //
                        if (i + 1 > grdSub.Rows.Count)
                        {
                            grdSub.RowCount = grdSub.RowCount + 1;
                        }
                        grdSub.Rows[i].Cells[HSno2Col].Value = ClsPub.isStrNull(i + 1);
                        if (TM.Trim() == "")
                        {
                            MessageBox.Show("条形码不能为空,不能生成条码!");
                            return;
                        }
                        grdSub.Rows[i].Cells[HTMCol].Value = TM;
                        grdSub.Rows[i].Cells[HEntryID2Col].Value = j + 1;
                        grdSub.Rows[i].Cells[HMaterID2Col].Value = grdMain.Rows[j].Cells[HMaterIDCol].Value;
                        grdSub.Rows[i].Cells[HMaterNumber2Col].Value = grdMain.Rows[j].Cells[HMaterNumberCol].Value;
                        grdSub.Rows[i].Cells[HMaterName2Col].Value = grdMain.Rows[j].Cells[HMaterNameCol].Value;
                        grdSub.Rows[i].Cells[HMaterModel2Col].Value = grdMain.Rows[j].Cells[HMaterModelCol].Value;
                        grdSub.Rows[i].Cells[HPinfan2Col].Value = grdMain.Rows[j].Cells[HPinfanCol].Value;
                        grdSub.Rows[i].Cells[HPinfanBarCode2Col].Value = grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value;
 
                        grdSub.Rows[i].Cells[HAuxPropID2Col].Value = grdMain.Rows[j].Cells[HAuxPropIDCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropNumber2Col].Value = grdMain.Rows[j].Cells[HAuxPropNumberCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropName2Col].Value = grdMain.Rows[j].Cells[HAuxPropNameCol].Value;
 
                        grdSub.Rows[i].Cells[HUnitID2Col].Value = grdMain.Rows[j].Cells[HUnitIDCol].Value;
                        grdSub.Rows[i].Cells[HUnitNumber2Col].Value = grdMain.Rows[j].Cells[HUnitNumberCol].Value;
                        grdSub.Rows[i].Cells[HUnitName2Col].Value = grdMain.Rows[j].Cells[HUnitNameCol].Value;
 
                        grdSub.Rows[i].Cells[HQty2Col].Value = HMinQty;
                        grdSub.Rows[i].Cells[HBatchNo2Col].Value = grdMain.Rows[j].Cells[HBatchNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceInterID2Col].Value = grdMain.Rows[j].Cells[HMainIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceEntryID2Col].Value = grdMain.Rows[j].Cells[HSubIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillNo2Col].Value = grdMain.Rows[j].Cells[HBillNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillType2Col].Value = grdMain.Rows[j].Cells[HBillTypeCol].Value;
                        grdSub.Rows[i].Cells[HPrintCol].Value = "0";
                        grdSub.Rows[i].Cells[HWeiCol].Value = WeiShu;
                        grdSub.Rows[i].Cells[HBarcodeNoCol].Value = n + 1;
                        grdSub.Rows[i].Cells[HBarcodeQtysCol].Value = grdMain.Rows[j].Cells[HBQtyCol].Value;
                        grdSub.Rows[i].Cells[HSupID2Col].Value = grdMain.Rows[j].Cells[HSupIDCol].Value;
                        grdSub.Rows[i].Cells[HSupNumber2Col].Value = grdMain.Rows[j].Cells[HSupNumberCol].Value;
                        grdSub.Rows[i].Cells[HSupName2Col].Value = grdMain.Rows[j].Cells[HSupNameCol].Value;
                        grdSub.Rows[i].Cells[HDeptID2Col].Value = grdMain.Rows[j].Cells[HDeptIDCol].Value;
                        grdSub.Rows[i].Cells[HDeptNumber2Col].Value = grdMain.Rows[j].Cells[HDeptNumberCol].Value;
                        grdSub.Rows[i].Cells[HDeptName2Col].Value = grdMain.Rows[j].Cells[HDeptNameCol].Value;
                        grdSub.Rows[i].Cells[HRemark2Col].Value = grdMain.Rows[j].Cells[HRemarkCol].Value;
                        grdSub.Rows[i].Cells[HDate2Col].Value = grdMain.Rows[j].Cells[HDateCol].Value;
                        grdSub.Rows[i].Cells[HShowDate2Col].Value = grdMain.Rows[j].Cells[HShowDateCol].Value;
                        grdSub.Rows[i].Cells[HWhID2Col].Value = grdMain.Rows[j].Cells[HWhIDCol].Value;
                        grdSub.Rows[i].Cells[HWhNumber2Col].Value = grdMain.Rows[j].Cells[HWhNumberCol].Value;
                        grdSub.Rows[i].Cells[HWhName2Col].Value = grdMain.Rows[j].Cells[HWhNameCol].Value;
                        grdSub.Rows[i].Cells[HSPID2Col].Value = grdMain.Rows[j].Cells[HSPIDCol].Value;
                        grdSub.Rows[i].Cells[HSPNumber2Col].Value = grdMain.Rows[j].Cells[HSPNumberCol].Value;
                        grdSub.Rows[i].Cells[HSPName2Col].Value = grdMain.Rows[j].Cells[HSPNameCol].Value;
                        grdSub.Rows[i].Cells[HMTONo2Col].Value = grdMain.Rows[j].Cells[HMTONoCol].Value;
                        grdSub.Rows[i].Cells[HCusID2Col].Value = grdMain.Rows[j].Cells[HCusIDCol].Value;
                        grdSub.Rows[i].Cells[HCusNumber2Col].Value = grdMain.Rows[j].Cells[HCusNumberCol].Value;
                        grdSub.Rows[i].Cells[HCusName2Col].Value = grdMain.Rows[j].Cells[HCusNameCol].Value;
                        grdSub.Rows[i].Cells[HCusType2Col].Value = grdMain.Rows[j].Cells[HCusTypeCol].Value;
                        grdSub.Rows[i].Cells[HSourceID2Col].Value = grdMain.Rows[j].Cells[HSourceIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceNumber2Col].Value = grdMain.Rows[j].Cells[HSourceNumberCol].Value;
                        grdSub.Rows[i].Cells[HSourceName2Col].Value = grdMain.Rows[j].Cells[HSourceNameCol].Value;
                        grdSub.Rows[i].Cells[HEndDate2Col].Value = grdMain.Rows[j].Cells[HEndDateCol].Value;
                        grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value = grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value;
                        grdSub.Rows[i].Cells[HSeOrderSEQ2Col].Value = grdMain.Rows[j].Cells[HSeOrderSEQCol].Value;
                        grdSub.Rows[i].Cells[HInnerBillNo2Col].Value = grdMain.Rows[j].Cells[HInnerBillNoCol].Value;
                        grdSub.Rows[i].Cells[HMaker2Col].Value = grdMain.Rows[j].Cells[HMakerCol].Value;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value = grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value;
                        grdSub.Rows[i].Cells[HProduceDate2Col].Value = grdMain.Rows[j].Cells[HProduceDateCol].Value;
                        grdSub.Rows[i].Cells[HExpiryDate2Col].Value = grdMain.Rows[j].Cells[HExpiryDateCol].Value;
                        grdSub.Rows[i].Cells[HISKFPERIOD2Col].Value = grdMain.Rows[j].Cells[HISKFPERIODCol].Value;
                        grdSub.Rows[i].Cells[HEXPUNIT2Col].Value = grdMain.Rows[j].Cells[HEXPUNITCol].Value;
                        grdSub.Rows[i].Cells[HEXPPERIOD2Col].Value = grdMain.Rows[j].Cells[HEXPPERIODCol].Value;
                        //网格打勾
                        //是否赠品
                        DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                        oCell.ThreeState = false;
                        oCell.Value = grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value;
                        oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
                        //是否启用保质期
                        DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell();
                        oCell2.ThreeState = false;
                        oCell2.Value = grdSub.Rows[i].Cells[HISKFPERIOD2Col].Value;
                        oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        grdSub.Rows[i].Cells[HISKFPERIOD2Col] = oCell2;
                        k = k + 1;
                        n = n + 1;
                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        nn = nn + 1;
                    }
                    //后台批量执行语句
                    oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + nn.ToString() + " ");
                }
            }
            string HWei = "";      //尾数
            string HBarCode = "";
            string HBarCodeType = "";
            Int64 HMaterID = 0;
            Int64 HAuxPropID = 0;
            Int64 HUnitID = 0;
            double HQty2 = 0;
            string HBatchNo2 = "";
            Int64 HSupID = 0;
            Int64 HGroupID = 0;
            int HPrintQty = 0;
            Int64 HSourceInterID = 0;
            Int64 HSourceEntryID = 0;
            string HSourceBillNo = "";
            string HSourceBillType = "";
            Int64 HBarcodeNo = 0;       //托号
            Int64 HBarcodeQtys = 0;     //总托数
            Int64 HDeptID = 0;
            Int64 HWhID = 0;
            Int64 HSPID = 0;
            string HRemark = "";
            string HMaterName = "";
            string HMaterModel = "";
            string HPinfan = "";
            string HMTONo = "";
            Int64 HCusID = 0;
            string HCusType = "";
            DateTime HEndDate;
            string HWorkLineName = "";
            string HSeOrderBillNo = "";
            Int64 HSeOrderSEQ = 0;
            string HInnerBillNo = "";
            bool HGiveAwayFlag = false;
            Int64 HEntryID = 0;
            string HProduceDate;
            string HExpiryDate;
            bool HISKFPERIOD = false;
            string HEXPUNIT = "";
            double HEXPPERIOD = 0;
            try
            {
                oCn.BeginTran();
                for (int i = 0; i < grdSub.Rows.Count; i++)
                {
                    if (ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value) != 0)
                    {
                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                        //
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        if (CampanyName == "博日科技" || CampanyName == "夏宝电器")
                        {
                            HBarCodeType = "唯一条码";
                        }
                        //
                        HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        HEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HEntryID2Col].Value);
                        HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                        HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
                        HQty2 = ClsPub.isDoule(grdSub.Rows[i].Cells[HQty2Col].Value);
                        HBatchNo2 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBatchNo2Col].Value);
                        HSourceInterID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceInterID2Col].Value);
                        HSourceEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceEntryID2Col].Value);
                        HSourceBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillNo2Col].Value);
                        HSourceBillType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillType2Col].Value);
                        HBarcodeQtys = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeQtysCol].Value);
                        HBarcodeNo = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeNoCol].Value);
                        HSupID = ClsPub.isLong(grdSub.Rows[i].Cells[HSupID2Col].Value);
                        HDeptID = ClsPub.isLong(grdSub.Rows[i].Cells[HDeptID2Col].Value);
                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
                        HMTONo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMTONo2Col].Value);
                        HCusID = ClsPub.isLong(grdSub.Rows[i].Cells[HCusID2Col].Value);
                        HCusType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusType2Col].Value);
                        HEndDate = ClsPub.isDate(grdSub.Rows[i].Cells[HEndDate2Col].Value);
                        HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceName2Col].Value);
                        HSeOrderBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value);
                        HSeOrderSEQ = ClsPub.isLong(grdSub.Rows[i].Cells[HSeOrderSEQ2Col].Value);
                        HInnerBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HInnerBillNo2Col].Value);
                        HGiveAwayFlag = ClsPub.isBool(grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value);
                        if (ClsPub.isDate(grdSub.Rows[i].Cells[HProduceDate2Col].Value) < Convert.ToDateTime("1950-01-01"))
                        {
                            HProduceDate = "";
                        }
                        else
                        {
                            HProduceDate = ClsPub.isStrNull(grdSub.Rows[i].Cells[HProduceDate2Col].Value);
                        }
                        if (ClsPub.isDate(grdSub.Rows[i].Cells[HExpiryDate2Col].Value) < Convert.ToDateTime("1950-01-01"))
                        {
                            HExpiryDate = "";
                        }
                        else
                        {
                            HExpiryDate = ClsPub.isStrNull(grdSub.Rows[i].Cells[HExpiryDate2Col].Value);
                        }
                        HISKFPERIOD = ClsPub.isBool(grdSub.Rows[i].Cells[HISKFPERIOD2Col].Value);
                        HEXPUNIT = ClsPub.isStrNull(grdSub.Rows[i].Cells[HEXPUNIT2Col].Value);
                        HEXPPERIOD = ClsPub.isDoule(grdSub.Rows[i].Cells[HEXPPERIOD2Col].Value);
 
                        if (radioButton_HIsUsingBatchNo.Checked)
                        {
                            HBatchNo2 = getBatchNo();
                        }
 
 
                        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,HSeOrderSEQ,HInitSourceEntryID " +
                                    ",HProduceDate,HExpiryDate " +
                                    ",HISKFPERIOD,HEXPUNIT,HEXPPERIOD " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
                                    + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                    + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                    + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + "," + HEntryID.ToString()
                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag) + "," + HSeOrderSEQ.ToString() + "," + HSourceEntryID.ToString()
                                    + ", " + (HProduceDate == "" ? "NULL" : "'" + HProduceDate + "'") + "," + (HExpiryDate == "" ? "NULL" : "'" + HExpiryDate + "'")
                                    + ", " + DBUtility.ClsPub.BoolToString(HISKFPERIOD) + ",'" + HEXPUNIT + "'," + HEXPPERIOD.ToString()
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
 
 
                        //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 + "'");
                    }
                }
                //增加 条码超过未生成功能控制
 
                //
                oCn.Commit();
                //MessageBox.Show("条码生成完毕!");
                //grdSub.RowCount = 0;
                tabControl1.SelectedIndex = 3;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                MessageBox.Show("条码生成失败!" + e.Message);
                grdSub.RowCount = 0;
            }
        }
 
        private string getBatchNo()
        {
            string HBatchNo = "";
 
            if (radioButton_HIsUsingBatchNo.Checked)
            {
                //日期获取方式
                string sDate = dtpHDate.Value.ToShortDateString();                                                                                   //
                string sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                string sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                string sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                sDay = sDay.Substring(sDay.Length - 2, 2);
 
                string HDate = "20" + sYear + "-" + sPeriod + "-" + sDay;
 
                //获取流水号:四位,该物料当天生成的条码数
                string LIU = "";
                int LEN = 4;
                DataSet ds;
                string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "' order by 批号 desc";
                ds = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
                if (ds != null)
                {
                    long count = ClsPub.isLong(ds.Tables[0].Rows[0]["批号"].ToString().Replace(sYear + sPeriod + sDay, ""));
 
                    LIU += count + 1;
                    while (LIU.Length < LEN)  //如果流水号小于6位数前面补0
                    {
                        LIU = "0" + LIU;
                    }
                }
                else
                {
                    return "";
                }
 
                //拼接批号
                HBatchNo = sYear + sPeriod + sDay + LIU;
            }
 
 
            return HBatchNo;
        }
 
        //生成条码 博日 
        //物料编码+序列号+生产日期
        private void SaveBarCode_bori()
        {
            grdSub.Rows.Clear();
            int LSHlen = 6;             //流水号长度
            int SumLen = 10;            //总长度
            string TM = "";             //条码
            string HNumber = "";        //物料内码
            string HMaterNumber = "";   //物料代码
            double HSumQty = 0;         //产品数量
            double HMinQty = 0;         //最小包装数
            Int64 HBQty = 0;              //箱数
            double HQty = 0;            //数量
            string WeiShu = "";         //尾数
            //int LSH = 0;                //流水号
            string LSH2 = "";           //流水号转换成字符
            string sDate = "";          //日期
            string sYear = "";          //年
            string sPeriod = "";        //月
            string sDay = "";           //日
            string HBatchNo = "";       //批次
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string sTMNumber = "";      //条码自定义前缀
            DataSet Ds;
            //Ds = oCn.RunProcReturn("exec GetLSH '" + ClsPub.GetServerDate(0) + "'", "GetLSH");
            //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                {
                    HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
                    HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                    //日期获取方式
                    sDate = dtpHDate.Value.ToShortDateString();
                    //
                    if (cmbHBarCodeType.Text == "试剂成品条码规则")// 失效日期(生产订单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
                    }
                    //
                    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 (cmbHBarCodeType.Text == "试剂成品条码规则")
                    //{ 
                    //    //条码前缀 = 组织代码 + 物料代码 + 年 + 月 + 日
                    //sTMNumber = HMaterNumber + 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
                    //{
                    //    MessageBox.Show("错误的条码类型,不能生成条码!");
                    //    return;
                    //}
 
                    HBQty = HBQty + ClsPub.isLong(grdMain.Rows[j].Cells[HBQtyCol].Value);
                    HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);
                    HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
                    n = 0;
                    //从金蝶序列号表获取序列号
                    DataSet DSet = oCn.RunProcReturn("exec h_p_CLD_GetBarCodeSno  " + ClsPub.isStrNull(grdMain.Rows[j].Cells[HMainIDCol].Value) + "," + ClsPub.isStrNull(grdMain.Rows[j].Cells[HSubIDCol].Value) + "  ", "h_p_CLD_GetBarCodeSno", ref DBUtility.ClsPub.sExeReturnInfo);
                    //生成首行标题
                    if (DSet == null)
                    {
                        MessageBox.Show("没有返回任何结果,金蝶云序列号不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                        continue;
                    }
                    //
 
                    for (int i = k; i < DSet.Tables[0].Rows.Count; i++)
                    //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 = DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[n]["SHNO"]);
                        //while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                        //{
                        //    LSH2 = "0" + LSH2;
                        //}
                        //if (cmbHBarCodeType.Text == "唯一条码")
                        //{
                        //条码编号 = 条码前缀 + 流水号
                        //T/*M*/ = HMaterNumber + LSH2 + sYear + sPeriod + sDay;
                        TM = LSH2 + sYear + sPeriod + sDay;
                        //}
 
                        if (i + 1 > grdSub.Rows.Count)
                        {
                            grdSub.RowCount = grdSub.RowCount + 1;
                        }
                        grdSub.Rows[i].Cells[HSno2Col].Value = ClsPub.isStrNull(i + 1);
                        if (TM.Trim() == "")
                        {
                            MessageBox.Show("条形码不能为空,不能生成条码!");
                            return;
                        }
                        grdSub.Rows[i].Cells[HTMCol].Value = TM;
                        grdSub.Rows[i].Cells[HMaterID2Col].Value = grdMain.Rows[j].Cells[HMaterIDCol].Value;
                        grdSub.Rows[i].Cells[HMaterNumber2Col].Value = grdMain.Rows[j].Cells[HMaterNumberCol].Value;
                        grdSub.Rows[i].Cells[HMaterName2Col].Value = grdMain.Rows[j].Cells[HMaterNameCol].Value;
                        grdSub.Rows[i].Cells[HMaterModel2Col].Value = grdMain.Rows[j].Cells[HMaterModelCol].Value;
                        grdSub.Rows[i].Cells[HPinfan2Col].Value = grdMain.Rows[j].Cells[HPinfanCol].Value;
                        grdSub.Rows[i].Cells[HPinfanBarCode2Col].Value = grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value;
 
                        grdSub.Rows[i].Cells[HAuxPropID2Col].Value = grdMain.Rows[j].Cells[HAuxPropIDCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropNumber2Col].Value = grdMain.Rows[j].Cells[HAuxPropNumberCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropName2Col].Value = grdMain.Rows[j].Cells[HAuxPropNameCol].Value;
 
                        grdSub.Rows[i].Cells[HUnitID2Col].Value = grdMain.Rows[j].Cells[HUnitIDCol].Value;
                        grdSub.Rows[i].Cells[HUnitNumber2Col].Value = grdMain.Rows[j].Cells[HUnitNumberCol].Value;
                        grdSub.Rows[i].Cells[HUnitName2Col].Value = grdMain.Rows[j].Cells[HUnitNameCol].Value;
 
                        grdSub.Rows[i].Cells[HQty2Col].Value = HMinQty;
                        grdSub.Rows[i].Cells[HBatchNo2Col].Value = grdMain.Rows[j].Cells[HBatchNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceInterID2Col].Value = grdMain.Rows[j].Cells[HMainIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceEntryID2Col].Value = grdMain.Rows[j].Cells[HSubIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillNo2Col].Value = grdMain.Rows[j].Cells[HBillNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillType2Col].Value = grdMain.Rows[j].Cells[HBillTypeCol].Value;
                        grdSub.Rows[i].Cells[HPrintCol].Value = "0";
                        grdSub.Rows[i].Cells[HWeiCol].Value = WeiShu;
                        grdSub.Rows[i].Cells[HBarcodeNoCol].Value = n + 1;
                        grdSub.Rows[i].Cells[HBarcodeQtysCol].Value = grdMain.Rows[j].Cells[HBQtyCol].Value;
                        grdSub.Rows[i].Cells[HSupID2Col].Value = grdMain.Rows[j].Cells[HSupIDCol].Value;
                        grdSub.Rows[i].Cells[HSupNumber2Col].Value = grdMain.Rows[j].Cells[HSupNumberCol].Value;
                        grdSub.Rows[i].Cells[HSupName2Col].Value = grdMain.Rows[j].Cells[HSupNameCol].Value;
                        grdSub.Rows[i].Cells[HDeptID2Col].Value = grdMain.Rows[j].Cells[HDeptIDCol].Value;
                        grdSub.Rows[i].Cells[HDeptNumber2Col].Value = grdMain.Rows[j].Cells[HDeptNumberCol].Value;
                        grdSub.Rows[i].Cells[HDeptName2Col].Value = grdMain.Rows[j].Cells[HDeptNameCol].Value;
                        grdSub.Rows[i].Cells[HRemark2Col].Value = grdMain.Rows[j].Cells[HRemarkCol].Value;
                        grdSub.Rows[i].Cells[HDate2Col].Value = grdMain.Rows[j].Cells[HDateCol].Value;
                        grdSub.Rows[i].Cells[HShowDate2Col].Value = grdMain.Rows[j].Cells[HShowDateCol].Value;
                        grdSub.Rows[i].Cells[HWhID2Col].Value = grdMain.Rows[j].Cells[HWhIDCol].Value;
                        grdSub.Rows[i].Cells[HWhNumber2Col].Value = grdMain.Rows[j].Cells[HWhNumberCol].Value;
                        grdSub.Rows[i].Cells[HWhName2Col].Value = grdMain.Rows[j].Cells[HWhNameCol].Value;
                        grdSub.Rows[i].Cells[HSPID2Col].Value = grdMain.Rows[j].Cells[HSPIDCol].Value;
                        grdSub.Rows[i].Cells[HSPNumber2Col].Value = grdMain.Rows[j].Cells[HSPNumberCol].Value;
                        grdSub.Rows[i].Cells[HSPName2Col].Value = grdMain.Rows[j].Cells[HSPNameCol].Value;
                        grdSub.Rows[i].Cells[HMTONo2Col].Value = grdMain.Rows[j].Cells[HMTONoCol].Value;
                        grdSub.Rows[i].Cells[HCusID2Col].Value = grdMain.Rows[j].Cells[HCusIDCol].Value;
                        grdSub.Rows[i].Cells[HCusNumber2Col].Value = grdMain.Rows[j].Cells[HCusNumberCol].Value;
                        grdSub.Rows[i].Cells[HCusName2Col].Value = grdMain.Rows[j].Cells[HCusNameCol].Value;
                        grdSub.Rows[i].Cells[HCusType2Col].Value = grdMain.Rows[j].Cells[HCusTypeCol].Value;
                        grdSub.Rows[i].Cells[HSourceID2Col].Value = grdMain.Rows[j].Cells[HSourceIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceNumber2Col].Value = grdMain.Rows[j].Cells[HSourceNumberCol].Value;
                        grdSub.Rows[i].Cells[HSourceName2Col].Value = grdMain.Rows[j].Cells[HSourceNameCol].Value;
                        grdSub.Rows[i].Cells[HEndDate2Col].Value = grdMain.Rows[j].Cells[HEndDateCol].Value;
                        grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value = grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value;
                        grdSub.Rows[i].Cells[HInnerBillNo2Col].Value = grdMain.Rows[j].Cells[HInnerBillNoCol].Value;
                        grdSub.Rows[i].Cells[HMaker2Col].Value = grdMain.Rows[j].Cells[HMakerCol].Value;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value = grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value;
                        //网格打勾
                        DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                        oCell.ThreeState = false;
                        oCell.Value = grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value;
                        oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
                        k = k + 1;
                        n = n + 1;
                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    }
                }
            }
            string HWei = "";      //尾数
            string HBarCode = "";
            string HBarCodeType = "";
            Int64 HMaterID = 0;
            Int64 HAuxPropID = 0;
            Int64 HUnitID = 0;
            double HQty2 = 0;
            string HBatchNo2 = "";
            Int64 HSupID = 0;
            Int64 HGroupID = 0;
            int HPrintQty = 0;
            Int64 HSourceInterID = 0;
            Int64 HSourceEntryID = 0;
            string HSourceBillNo = "";
            string HSourceBillType = "";
            Int64 HBarcodeNo = 0;       //托号
            Int64 HBarcodeQtys = 0;     //总托数
            Int64 HDeptID = 0;
            Int64 HWhID = 0;
            Int64 HSPID = 0;
            string HRemark = "";
            string HMaterName = "";
            string HMaterModel = "";
            string HPinfan = "";
            string HMTONo = "";
            Int64 HCusID = 0;
            string HCusType = "";
            DateTime HEndDate;
            string HWorkLineName = "";
            string HSeOrderBillNo = "";
            string HInnerBillNo = "";
            bool HGiveAwayFlag = false;
            try
            {
                oCn.BeginTran();
                for (int i = 0; i < grdSub.Rows.Count; i++)
                {
                    if (ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value) != 0)
                    {
                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                        //
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        if (CampanyName == "博日科技" || CampanyName == "夏宝电器")
                        {
                            HBarCodeType = "唯一条码";
                        }
                        //
                        HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                        HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
                        HQty2 = ClsPub.isDoule(grdSub.Rows[i].Cells[HQty2Col].Value);
                        HBatchNo2 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBatchNo2Col].Value);
                        HSourceInterID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceInterID2Col].Value);
                        HSourceEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceEntryID2Col].Value);
                        HSourceBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillNo2Col].Value);
                        HSourceBillType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillType2Col].Value);
                        HBarcodeQtys = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeQtysCol].Value);
                        HBarcodeNo = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeNoCol].Value);
                        HSupID = ClsPub.isLong(grdSub.Rows[i].Cells[HSupID2Col].Value);
                        HDeptID = ClsPub.isLong(grdSub.Rows[i].Cells[HDeptID2Col].Value);
                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
                        HMTONo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMTONo2Col].Value);
                        HCusID = ClsPub.isLong(grdSub.Rows[i].Cells[HCusID2Col].Value);
                        HCusType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusType2Col].Value);
                        HEndDate = ClsPub.isDate(grdSub.Rows[i].Cells[HEndDate2Col].Value);
                        HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceName2Col].Value);
                        HSeOrderBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value);
                        HInnerBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HInnerBillNo2Col].Value);
                        HGiveAwayFlag = ClsPub.isBool(grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value);
 
                        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 " +
                                    ",HGiveAwayFlag " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
                                    + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                    + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                    + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
 
 
                        //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 + "'");
                    }
                }
                //增加 条码超过未生成功能控制
 
                //
                oCn.Commit();
                MessageBox.Show("条码生成完毕!");
                //grdSub.RowCount = 0;
                tabControl1.SelectedIndex = 3;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                MessageBox.Show("条码生成失败!" + e.Message);
                grdSub.RowCount = 0;
            }
        }
 
        #endregion 
 
 
        #region 窗体处理方法
        //初始化GRID
        private void initGrid()
        {
            //
            grdMain.RowCount = 0;
            grdSub.RowCount = 0;
            grdMain.ColumnCount = 68;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
            grdMain.Columns[HSnoCol].HeaderText = "序号";
            grdMain.Columns[HMainIDCol].HeaderText = "源单主ID";
            grdMain.Columns[HSubIDCol].HeaderText = "源单子ID";
            grdMain.Columns[HBillNoCol].HeaderText = "源单单号";
            grdMain.Columns[HBillTypeCol].HeaderText = "单据类型";
            grdMain.Columns[HMaterIDCol].HeaderText = "物料ID";
            grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码";
            grdMain.Columns[HMaterNameCol].HeaderText = "物料名称";
            grdMain.Columns[HMaterModelCol].HeaderText = "规格型号";
            grdMain.Columns[HModelCol].HeaderText = "自定义规格";
            grdMain.Columns[HPinfanCol].HeaderText = "品番";
            grdMain.Columns[HPinfanBarCodeCol].HeaderText = "HPinfanBarCode";
            grdMain.Columns[HAuxPropIDCol].HeaderText = "辅助属性ID";
            grdMain.Columns[HAuxPropNumberCol].HeaderText = "辅助属性代码";
            grdMain.Columns[HAuxPropNameCol].HeaderText = "辅助属性名称";
            grdMain.Columns[HUnitIDCol].HeaderText = "计量单位ID";
            grdMain.Columns[HUnitNumberCol].HeaderText = "计量单位代码";
            grdMain.Columns[HUnitNameCol].HeaderText = "计量单位名称";
            grdMain.Columns[HBarCodeTypeCol].HeaderText = "条码类型";
            grdMain.Columns[HBatchManagerCol].HeaderText = "是否启用批次";
            grdMain.Columns[HBatchNoCol].HeaderText = "批号";
            grdMain.Columns[HGiveAwayFlagCol].HeaderText = "是否赠品";
            grdMain.Columns[HQtyCol].HeaderText = "数量";
            grdMain.Columns[HMinQtyCol].HeaderText = "最小包装数";
            grdMain.Columns[HPackQtyCol].HeaderText = "外箱数";
            grdMain.Columns[HBQtyCol].HeaderText = "箱数";
            grdMain.Columns[HSupIDCol].HeaderText = "供应商ID";
            grdMain.Columns[HSupNumberCol].HeaderText = "供应商代码";
            grdMain.Columns[HSupNameCol].HeaderText = "供应商";
            grdMain.Columns[HDeptIDCol].HeaderText = "车间ID";
            grdMain.Columns[HDeptNumberCol].HeaderText = "车间代码";
            grdMain.Columns[HDeptNameCol].HeaderText = "车间";
            grdMain.Columns[HWhIDCol].HeaderText = "仓库ID";
            grdMain.Columns[HWhNumberCol].HeaderText = "仓库代码";
            grdMain.Columns[HWhNameCol].HeaderText = "仓库";
            grdMain.Columns[HSPIDCol].HeaderText = "仓位ID";
            grdMain.Columns[HSPNumberCol].HeaderText = "仓位代码";
            grdMain.Columns[HSPNameCol].HeaderText = "仓位";
            grdMain.Columns[HInstructNoCol].HeaderText = "指令单号";
            grdMain.Columns[HSeOrderBillNoCol].HeaderText = "销售订单号";
            grdMain.Columns[HSeOrderSEQCol].HeaderText = "销售订单行号";
            grdMain.Columns[HDateCol].HeaderText = "进料日期";
            grdMain.Columns[HRemarkCol].HeaderText = "备注";
            grdMain.Columns[HMTONoCol].HeaderText = "计划跟踪号";
            grdMain.Columns[HCusIDCol].HeaderText = "客户ID";
            grdMain.Columns[HCusNumberCol].HeaderText = "客户代码";
            grdMain.Columns[HCusNameCol].HeaderText = "客户";
            grdMain.Columns[HCusTypeCol].HeaderText = "客户型号";
            grdMain.Columns[HEndDateCol].HeaderText = "计划完工日期";
            grdMain.Columns[HSourceIDCol].HeaderText = "生产线ID";
            grdMain.Columns[HSourceNumberCol].HeaderText = "生产线代码";
            grdMain.Columns[HSourceNameCol].HeaderText = "生产线";
            grdMain.Columns[HShowDateCol].HeaderText = "日期";
            grdMain.Columns[HInnerBillNoCol].HeaderText = "内部采购订单号";
            grdMain.Columns[HMakerCol].HeaderText = "制单人";
            grdMain.Columns[HProduceDateCol].HeaderText = "生产日期";
            grdMain.Columns[HExpiryDateCol].HeaderText = "有效期至";
            grdMain.Columns[HISKFPERIODCol].HeaderText = "是否启用保质期";
            grdMain.Columns[HEXPUNITCol].HeaderText = "保质期单位";
            grdMain.Columns[HEXPPERIODCol].HeaderText = "保质期";
            ////
            //格式化 
            grdMain.Columns[HTagCol].Visible = false;                           //隐藏列
            grdMain.Columns[HMainIDCol].Visible = false;
            grdMain.Columns[HSubIDCol].Visible = false;
            grdMain.Columns[HBillTypeCol].Visible = false;
            grdMain.Columns[HMaterIDCol].Visible = false;
            grdMain.Columns[HModelCol].Visible = false;
            //grdMain.Columns[HBatchNoCol].Visible = false;
            grdMain.Columns[HAuxPropIDCol].Visible = false;
            //grdMain.Columns[HAuxPropNumberCol].Visible = false;
            //grdMain.Columns[HAuxPropNameCol].Visible = false;
            grdMain.Columns[HUnitIDCol].Visible = false;
            grdMain.Columns[HinitQtyCol].Visible = false;
            grdMain.Columns[HSupIDCol].Visible = false;
            grdMain.Columns[HSupNumberCol].Visible = false;
            grdMain.Columns[HSupNameCol].Visible = false;
            grdMain.Columns[HDeptIDCol].Visible = false;
            grdMain.Columns[HDeptNumberCol].Visible = false;
            grdMain.Columns[HDeptNameCol].Visible = false;
            grdMain.Columns[HWhIDCol].Visible = false;
            grdMain.Columns[HWhNumberCol].Visible = false;
            grdMain.Columns[HWhNameCol].Visible = false;
            grdMain.Columns[HSPIDCol].Visible = false;
            grdMain.Columns[HSPNumberCol].Visible = false;
            grdMain.Columns[HSPNameCol].Visible = false;
            grdMain.Columns[HSourceInterIDCol].Visible = false;
            grdMain.Columns[HSourceEntryIDCol].Visible = false;
            grdMain.Columns[HSourceBillNoCol].Visible = false;
            grdMain.Columns[HSourceBillTypeCol].Visible = false;
            grdMain.Columns[HInstructIDCol].Visible = false;
            grdMain.Columns[HInstructNoCol].Visible = false;
            grdMain.Columns[HSeOrderBillIDCol].Visible = false;
            //grdMain.Columns[HSeOrderBillNoCol].Visible = false;
            grdMain.Columns[HBarCodeTypeCol].Visible = false;
            grdMain.Columns[HBatchManagerCol].Visible = false;
            //grdMain.Columns[HDateCol].Visible = false;
            grdMain.Columns[HPinfanCol].Visible = false;
            grdMain.Columns[HPinfanBarCodeCol].Visible = false;
            grdMain.Columns[HCusIDCol].Visible = false;
            //grdMain.Columns[HCusNumberCol].Visible = false;
            //grdMain.Columns[HCusNameCol].Visible = false;
            grdMain.Columns[HCusTypeCol].Visible = false;
            grdMain.Columns[HEndDateCol].Visible = false;
            grdMain.Columns[HSourceIDCol].Visible = false;
            grdMain.Columns[HSourceNumberCol].Visible = false;
            grdMain.Columns[HSourceNameCol].Visible = false;
            //grdMain.Columns[HProduceDateCol].Visible = false;
            //grdMain.Columns[HExpiryDateCol].Visible = false;
            grdMain.Columns[HISKFPERIODCol].Visible = false;
            grdMain.Columns[HEXPUNITCol].Visible = false;
            grdMain.Columns[HEXPPERIODCol].Visible = false;
 
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HMinQtyCol.ToString() +
                                "," + HMaterNumberCol.ToString() +
                                "," + HAuxPropNumberCol.ToString() +
                                "," + HUnitNumberCol.ToString() +
                                "," + HSeOrderBillNoCol.ToString() +
                                "," + HBatchNoCol.ToString() +
                                "," + HCusNumberCol.ToString() +
                                "," + HPackQtyCol.ToString() +
                                "," + HRemarkCol.ToString();
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
 
            //设置特殊列
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                //网格打勾
                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                oCell.ThreeState = false;
                oCell.Value = 0;
                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grdMain.Rows[i].Cells[HGiveAwayFlagCol] = oCell;
            }
            //
 
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            //----------------------------
 
            grdSub.ColumnCount = 65;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdSub, this.Name);
            grdSub.Columns[HSelectCol].HeaderText = "选择";
            grdSub.Columns[HTMCol].HeaderText = "条码编号";
            grdSub.Columns[HBarCodeType2Col].HeaderText = "条码类型";
            grdSub.Columns[HSno2Col].HeaderText = "序号";
            grdSub.Columns[HMaterID2Col].HeaderText = "物料ID";
            grdSub.Columns[HMaterNumber2Col].HeaderText = "物料代码";
            grdSub.Columns[HMaterName2Col].HeaderText = "物料名称";
            grdSub.Columns[HMaterModel2Col].HeaderText = "规格型号";
            grdSub.Columns[HModel2Col].HeaderText = "自定义规格";
            grdSub.Columns[HAuxPropID2Col].HeaderText = "辅助属性ID";
            grdSub.Columns[HAuxPropNumber2Col].HeaderText = "辅助属性代码";
            grdSub.Columns[HAuxPropName2Col].HeaderText = "辅助属性";
            grdSub.Columns[HPinfan2Col].HeaderText = "品番";
            grdSub.Columns[HPinfanBarCode2Col].HeaderText = "HPinfanBarCode";
            grdSub.Columns[HBatchNo2Col].HeaderText = "批号";
            grdSub.Columns[HGiveAwayFlag2Col].HeaderText = "是否赠品";
            grdSub.Columns[HUnitID2Col].HeaderText = "计量单位ID";
            grdSub.Columns[HUnitNumber2Col].HeaderText = "计量单位代码";
            grdSub.Columns[HUnitName2Col].HeaderText = "计量单位";
            grdSub.Columns[HQty2Col].HeaderText = "数量";
            grdSub.Columns[HWeiCol].HeaderText = "尾数";
            grdSub.Columns[HPrintCol].HeaderText = "打印次数";
            grdSub.Columns[HSourceInterID2Col].HeaderText = "源单主ID";
            grdSub.Columns[HSourceEntryID2Col].HeaderText = "源单子ID";
            grdSub.Columns[HSourceBillNo2Col].HeaderText = "源单单号";
            grdSub.Columns[HSourceBillType2Col].HeaderText = "源单类型";
            grdSub.Columns[HSeOrderBillNo2Col].HeaderText = "销售订单号";
            grdSub.Columns[HSeOrderSEQ2Col].HeaderText = "销售订单行号";
            grdSub.Columns[HBarcodeNoCol].HeaderText = "托号";
            grdSub.Columns[HBarcodeQtysCol].HeaderText = "总托数";
            grdSub.Columns[HSupID2Col].HeaderText = "供应商ID";
            grdSub.Columns[HSupNumber2Col].HeaderText = "供应商代码";
            grdSub.Columns[HSupName2Col].HeaderText = "供应商";
            grdSub.Columns[HDeptID2Col].HeaderText = "车间ID";
            grdSub.Columns[HDeptNumber2Col].HeaderText = "车间代码";
            grdSub.Columns[HDeptName2Col].HeaderText = "车间";
            grdSub.Columns[HWhID2Col].HeaderText = "仓库ID";
            grdSub.Columns[HWhNumber2Col].HeaderText = "仓库代码";
            grdSub.Columns[HWhName2Col].HeaderText = "仓库";
            grdSub.Columns[HSPID2Col].HeaderText = "仓位ID";
            grdSub.Columns[HSPNumber2Col].HeaderText = "仓位代码";
            grdSub.Columns[HSPName2Col].HeaderText = "仓位";
            grdSub.Columns[HInstructNo2Col].HeaderText = "指令单号";
            grdSub.Columns[HDate2Col].HeaderText = "进料日期";
            grdSub.Columns[HRemark2Col].HeaderText = "备注";
            grdSub.Columns[HMTONo2Col].HeaderText = "计划跟踪号";
            grdSub.Columns[HCusID2Col].HeaderText = "客户ID";
            grdSub.Columns[HCusNumber2Col].HeaderText = "客户代码";
            grdSub.Columns[HCusName2Col].HeaderText = "客户";
            grdSub.Columns[HCusType2Col].HeaderText = "客户型号";
            grdSub.Columns[HEndDate2Col].HeaderText = "计划完工日期";
            grdSub.Columns[HSourceID2Col].HeaderText = "生产线ID";
            grdSub.Columns[HSourceNumber2Col].HeaderText = "生产线代码";
            grdSub.Columns[HSourceName2Col].HeaderText = "生产线";
            grdSub.Columns[HShowDate2Col].HeaderText = "日期";
            grdSub.Columns[HInnerBillNo2Col].HeaderText = "内部采购订单号";
            grdSub.Columns[HMaker2Col].HeaderText = "制单人";
            grdSub.Columns[HEntryID2Col].HeaderText = "行号";
            grdSub.Columns[HProduceDate2Col].HeaderText = "生产日期";
            grdSub.Columns[HExpiryDate2Col].HeaderText = "有效期至";
            grdSub.Columns[HISKFPERIOD2Col].HeaderText = "是否启用保质期";
            grdSub.Columns[HEXPUNIT2Col].HeaderText = "保质期单位";
            grdSub.Columns[HEXPPERIOD2Col].HeaderText = "保质期";
            //格式化 
            grdSub.Columns[HMaterID2Col].Visible = false;
            grdSub.Columns[HModel2Col].Visible = false;
            grdSub.Columns[HAuxPropID2Col].Visible = false;
            //grdSub.Columns[HAuxPropNumber2Col].Visible = false;
            //grdSub.Columns[HAuxPropName2Col].Visible = false;
            grdSub.Columns[HUnitID2Col].Visible = false;
            grdSub.Columns[HPrintCol].Visible = false;
            grdSub.Columns[HSourceInterID2Col].Visible = false;
            grdSub.Columns[HSourceEntryID2Col].Visible = false;
            grdSub.Columns[HSourceBillType2Col].Visible = false;
            grdSub.Columns[HDeptID2Col].Visible = false;
            grdSub.Columns[HDeptNumber2Col].Visible = false;
            grdSub.Columns[HDeptName2Col].Visible = false;
            //grdSub.Columns[HDate2Col].Visible = false;
            grdSub.Columns[HBarCodeType2Col].Visible = false;
            //grdSub.Columns[HBatchNo2Col].Visible = false;
            grdSub.Columns[HWeiCol].Visible = false;
            grdSub.Columns[HBarcodeNoCol].Visible = false;
            grdSub.Columns[HBarcodeQtysCol].Visible = false;
            grdSub.Columns[HSupID2Col].Visible = false;
            grdSub.Columns[HSupNumber2Col].Visible = false;
            grdSub.Columns[HSupName2Col].Visible = false;
            grdSub.Columns[HWhID2Col].Visible = false;
            grdSub.Columns[HWhNumber2Col].Visible = false;
            grdSub.Columns[HWhName2Col].Visible = false;
            grdSub.Columns[HSPID2Col].Visible = false;
            grdSub.Columns[HSPNumber2Col].Visible = false;
            grdSub.Columns[HSPName2Col].Visible = false;
            grdSub.Columns[HInstructID2Col].Visible = false;
            grdSub.Columns[HInstructNo2Col].Visible = false;
            grdSub.Columns[HSeOrderBillID2Col].Visible = false;
            //grdSub.Columns[HSeOrderBillNo2Col].Visible = false;
            grdSub.Columns[HPinfan2Col].Visible = false;
            grdSub.Columns[HPinfanBarCode2Col].Visible = false;
            grdSub.Columns[HCusID2Col].Visible = false;
            //grdSub.Columns[HCusNumber2Col].Visible = false;
            //grdSub.Columns[HCusName2Col].Visible = false;
            grdSub.Columns[HCusType2Col].Visible = false;
            grdSub.Columns[HEndDate2Col].Visible = false;
            grdSub.Columns[HSourceID2Col].Visible = false;
            grdSub.Columns[HSourceNumber2Col].Visible = false;
            grdSub.Columns[HSourceName2Col].Visible = false;
 
            //设置特殊列
            for (int i = 0; i < grdSub.Rows.Count; i++)
            {
                //网格打勾
                //是否赠品
                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                oCell.ThreeState = false;
                oCell.Value = 0;
                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
                //是否启用保质期
                DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell();
                oCell2.ThreeState = false;
                oCell2.Value = 0;
                oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grdSub.Rows[i].Cells[HISKFPERIOD2Col] = oCell2;
            }
 
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.GetGrid(grdSub, this.Name + "grdSub");
            grdSub.SelectionMode = DataGridViewSelectionMode.FullRowSelect;                     //选行模式
 
            ////
            DBUtility.Xt_BaseBillFun.initGridList(grdList, this.Name + "grdList");
            DBUtility.Xt_BaseBillFun.initGridList(grdBillBarCodeList, this.Name + "grdBillBarCodeList");
            ////
        }
 
        //公式重算
        private void RowCount(int sRow, int sTag)
        {
            if (sTag == 0)
            {
                //箱数列=数量/最小包装数
                double sMoney = 0;
                if (ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value) == 0)
                {
                    sMoney = 0;
                }
                else
                {
                    sMoney = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) / ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value);
                }
                sMoney = Math.Ceiling(sMoney);
                grdMain.Rows[sRow].Cells[HBQtyCol].Value = sMoney;
            }
            else
            {
 
            }
            //if (ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) > ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value)
            //    && ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HBillNoCol].Value) != "")
            //{
            //    MessageBox.Show("所输入的产品总数量大于剩余可生成数量" + ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value) + ",请重新输入!");
            //    grdMain.Rows[sRow].Cells[HQtyCol].Value = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value);
            //    return;
            //}
        }
 
        //核对选择的内容
        public bool CheckGridCell(Cell oCell)
        {
            int Row;
            int Col;
            Row = oCell.Row;
            Col = oCell.Col;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //grdMain.Redraw = VSFlex7.RedrawSettings.flexRDNone;
            //判断选中列
            if (Col == HMaterNumberCol)  //物料代码列
            {
                //ClsGy_MaterialHlp oMate = new ClsGy_MaterialHlp();
                //if (oMate.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HMaterIDCol].Value)))
                //{
                //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = oMate.HItemID.ToString();
                //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = oMate.HNumber;
                //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = oMate.HName;
                //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = oMate.HModel;
                //}
                //else
                //{
                //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = "";
                //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = "";
                //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = "";
                //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = "";
                return false;
                //}
            }
            else if (Col == HUnitIDCol)  //单位ID列
            {
                //ClsGy_UnitHlp oUn = new ClsGy_UnitHlp();
                //if (oUn.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HUnitIDCol])))
                //{
                //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = oUn.HItemID.ToString();
                //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = oUn.HName;
                //}
                //else
                //{
                //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = "";
                //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = "";
                return false;
                //}
            }
            else //其他列
            {
            }
            // 
            //
            grdMain.Rows[Row].Cells[HTagCol].Value = "*";
            oSumGrid.EditStatus = false;
            return true;
        }
        //是否是空行
        private bool IsNullRow(int Row)
        {
            return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HMaterIDCol, grdMain);
        }
        //'判断网格行的录入是否正确
        private bool CheckGridRow(int Row)
        {
            Cell oCell = new Cell();
            int c = 0;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //
            for (c = 0; c < grdMain.ColumnCount; c++)
            {
                oCell.Row = Row;
                oCell.Col = c;
                //if (!CheckGridCell(oCell))
                //    return false;
 
            }
            return true;
        }
        //帮助函数
        private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit)
        {
            DataSet oDs = new DataSet();
            DataSet oDs2 = new DataSet();
            long sHMaterID = 0;
            long sHAuxPropID = 0;
            long sHOrgID = -1;
            string sWhere = "";
 
            DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
            if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
            {
                sHOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
            }
            if (sHOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
            DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View();//物料
            DAL.ClsIF_Unit_View oUnit = new DAL.ClsIF_Unit_View();//计量单位
            DAL.ClsIF_Property_View oProperty = new DAL.ClsIF_Property_View();//辅助属性
            if (!grdStatus)
            {
                return;
            }
            //if (oSumGrid.FindAllowEditCol(sCol))
            //{
            oSumGrid.EditStatus = true;
            //}
            //else
            //{
            //    return;
            //}
            switch (sKeyCode)
            {
                case 118:          //F7
                    {
                        switch (sCol)
                        {
                            case HMaterNumberCol:
                                oMater.WherePart = "";
                                sWhere = " and HUSEORGID = " + sHOrgID;
                                if (oMater.RefreshViewForBig(sWhere))
                                {
                                    if (oMater.GetInfoByID(oMater.oModel.HItemID))
                                    {
                                        grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString();
                                        grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber;
                                        grdMain.Rows[sRow].Cells[HMaterNameCol].Value = oMater.omodel.HName;
                                        grdMain.Rows[sRow].Cells[HMaterModelCol].Value = oMater.omodel.HModel;
                                        grdMain.Rows[sRow].Cells[HMinQtyCol].Value = oMater.omodel.HQtyMin;
                                        grdMain.Rows[sRow].Cells[HDateCol].Value = dtpHDate.Value.ToShortDateString();
                                        grdMain.Rows[sRow].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
                                        grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = "";
                                        if (oUnit.GetInfoByID(oMater.omodel.HUnitID))
                                        {
                                            grdMain.Rows[sRow].Cells[HUnitIDCol].Value = oUnit.omodel.HItemID.ToString();
                                            grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = oUnit.omodel.HNumber;
                                            grdMain.Rows[sRow].Cells[HUnitNameCol].Value = oUnit.omodel.HName;
                                        }
                                        else
                                        {
                                            grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0;
                                            grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = "";
                                            grdMain.Rows[sRow].Cells[HUnitNameCol].Value = "";
                                        }
                                        if (CampanyName == "中控")
                                        {
                                            grdMain.Rows[sRow].Cells[HQtyCol].Value = oMater.omodel.HQtyMin;
                                            grdMain.Rows[sRow].Cells[HBQtyCol].Value = 1;
                                        }
                                        oEdit.Text = oMater.omodel.HNumber;
                                    }
                                    else
                                    {
                                        grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HUnitNameCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = "";
                                    }
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HUnitNameCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = "";
                                }
                                break;
 
                            case HUnitNumberCol:
                                oUnit.WherePart = "";
                                if (oUnit.RefreshView())
                                {
                                    grdMain.Rows[sRow].Cells[HUnitIDCol].Value = oUnit.oModel.HItemID.ToString();
                                    grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = oUnit.oModel.HNumber;
                                    grdMain.Rows[sRow].Cells[HUnitNameCol].Value = oUnit.oModel.HName;
                                    EditingControl.Text = oUnit.oModel.HNumber;
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HUnitNameCol].Value = "";
                                }
                                break;
 
                            case HDeptNumberCol:
                                BLL.ClsBaseSelect_InterFace.SetGridByDept(grdMain, sRow, HDeptIDCol, HDeptNumberCol, HDeptNameCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HDeptNumberCol].Value);
                                break;
 
                            case HCusNumberCol:
                                BLL.ClsBaseSelect_InterFace.SetGridByCus(grdMain, sRow, HCusIDCol, HCusNumberCol, HCusNameCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HCusNumberCol].Value);
                                break;
 
                            case HDateCol:
                                BLL.ClsPub_BLL.Sub_SelectDate(grdMain, sRow, HDateCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HDateCol].Value);
                                break;
 
                            case HAuxPropNumberCol:
                                oProperty.WherePart = "";
                                if (ERPMode == "CLOUD")
                                {
                                    sWhere = " and HMaterNumber = '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[HMaterNumberCol].Value) + "'";
                                }
                                else
                                {
                                    sWhere = "";
                                }
                                if (oProperty.RefreshView(sWhere))
                                {
                                    grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = oProperty.oModel.HItemID.ToString();
                                    grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = oProperty.oModel.HNumber;
                                    grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = oProperty.oModel.HName;
                                    oEdit.Text = oProperty.oModel.HNumber;
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = "";
                                }
                                break;
 
 
                            default:
                                break;
                        }
                        bc.Enabled = true;
                        break;
                    }
                case 117:  //F6
                    {
                        switch (sCol)
                        {
 
 
                            default:
                                break;
                        }
                        break;
                    }
                default:
                    break;
            }
        }
 
        //选原单
        private void cmdSourceBillNo_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
            if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
            {
                HOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
            }
            if (HOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
 
            if (cmbSourceBillType.Text.Trim() == "生产订单")
            {
                string sWhere = "";
                //系统参数,生成条码数量可否超源单数量控制(N为不可超源单数量)
                if (SourceQtyCtl == "N")
                {
                    sWhere = " and HOrgID =" + HOrgID.ToString() + " and 任务数量>0";
                }
                else
                {
                    sWhere = " and HOrgID =" + HOrgID.ToString();
                }
 
                DAL.Cls_S_IFCLD_ICMOList oIFCLD_ICMOList = new DAL.Cls_S_IFCLD_ICMOList();
                if (oIFCLD_ICMOList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "生产汇报单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_ICMOReportBillList oIF_ICMOReportBillList = new DAL.Cls_S_IF_ICMOReportBillList();
                if (oIF_ICMOReportBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "收料通知单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_POInStockBillList oIF_POInStockBillList = new DAL.Cls_S_IF_POInStockBillList();
                if (oIF_POInStockBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POInStockBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "采购订单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_POOrderBillList oIF_POOrderBillList = new DAL.Cls_S_IF_POOrderBillList();
                if (oIF_POOrderBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POOrderBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "委外订单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_EntrustOrderBillList oIF_EntrustOrderBillList = new DAL.Cls_S_IF_EntrustOrderBillList();
                if (oIF_EntrustOrderBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_EntrustOrderBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "采购入库单")
            {
                string sWhere = "";
                DAL.Cls_S_IF_POStockInBillList oIF_POStockInBillList = new DAL.Cls_S_IF_POStockInBillList();
                if (oIF_POStockInBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POStockInBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "倒箱单")
            {
                string sWhere = "";
                DAL.Cls_S_IF_ChangeBoxBillList oIF_ChangeBoxBillList = new DAL.Cls_S_IF_ChangeBoxBillList();
                if (oIF_ChangeBoxBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ChangeBoxBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "退货通知单")
            {
                string sWhere = "";
                DAL.Cls_S_IF_SeOutStockBackBillList oIF_SeOutStockBackBillList = new DAL.Cls_S_IF_SeOutStockBackBillList();
                if (oIF_SeOutStockBackBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_SeOutStockBackBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "其他入库单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_OtherInBillList oIF_OtherInBillList = new DAL.Cls_S_IF_OtherInBillList();
                if (oIF_OtherInBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_OtherInBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "直接调拨单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_MoveStockBillList oIF_MoveStockBillList = new DAL.Cls_S_IF_MoveStockBillList();
                if (oIF_MoveStockBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_MoveStockBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "采购退料单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_POStockInBackBillList oIF_POStockInBackBillList = new DAL.Cls_S_IF_POStockInBackBillList();
                if (oIF_POStockInBackBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POStockInBackBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "生产退料单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_MateOutBackBillList oIF_MateOutBackBillList = new DAL.Cls_S_IF_MateOutBackBillList();
                if (oIF_MateOutBackBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_MateOutBackBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "组装拆卸单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_PackageDismantleBillList oIF_PackageDismantleBillList = new DAL.Cls_S_IF_PackageDismantleBillList();
                if (oIF_PackageDismantleBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_PackageDismantleBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "工序流转卡")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_ProcessExchangeBillList oIF_ProcessExchangeBillList = new DAL.Cls_S_IF_ProcessExchangeBillList();
                if (oIF_ProcessExchangeBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ProcessExchangeBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "工序汇报单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_ProcessReportBillList oIF_ProcessReportBillList = new DAL.Cls_S_IF_ProcessReportBillList();
                if (oIF_ProcessReportBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ProcessReportBillList.oBillSelectColl);
                }
            }
            else
            {
 
            }
 
            //选择源单后,加载该源单记录物料在当前日期的条码列表
            Display4();
        }
        //
        private void FillSelectData(List<DBUtility.BillSelect> oList)
        {
            if (oList.Count != 1)
            {
                MessageBox.Show("请选择一条数据!");
                return;
            }
 
 
            DataSet Ds;
            oSumGrid.Changelock = true;
            initGrid();
            int i = -1;
            foreach (DBUtility.BillSelect oSelectRow in oList)
            {
                i = i + 1;
                //生产订单
                if (oSelectRow.BillType == "3710")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("exec h_p_Gy_BarCodeBill_ICMOBillList " + oSelectRow.BillMainID.ToString() + "," + oSelectRow.BillSubID.ToString() + ",'" + SourceQtyCtl + "'", "h_p_Gy_BarCodeBill_ICMOBillList");
                    //Ds = oCn.RunProcReturn("select * from h_v_IFCLD_ICMOList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IFCLD_ICMOList");
                    //写入信息
                    Sub_WriteInForm(Ds.Tables[0], i);
                }
                //生产汇报单
                if (oSelectRow.BillType == "3711")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_ICMOReportList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ICMOReportList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //收料通知单
                if (oSelectRow.BillType == "1103")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_POInStockList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POInStockList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //采购订单
                if (oSelectRow.BillType == "1102")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_POOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POOrderList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //委外订单
                if (oSelectRow.BillType == "1601")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_EntrustOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_EntrustOrderList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //采购入库单
                if (oSelectRow.BillType == "1201")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_POStockInBillList_Source where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POStockInBillList_Source");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //倒箱单
                if (oSelectRow.BillType == "1240")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_ChangeBoxList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ChangeBoxList");
                    //写入信息
                    Sub_WriteInForm3(Ds.Tables[0], i);
                }
                //退货通知单
                if (oSelectRow.BillType == "1403")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_SeOutStockBackList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_SeOutStockBackList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //其他入库单
                if (oSelectRow.BillType == "1203")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_OtherInList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_OtherInList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //直接调拨单
                if (oSelectRow.BillType == "1207")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_MoveStockList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_MoveStockList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //采购退料单
                if (oSelectRow.BillType == "1239")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_POStockInBackList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POStockInBackList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //生产退料单
                if (oSelectRow.BillType == "1244")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_MateOutBackList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_MateOutBackList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //组装拆卸单
                if (oSelectRow.BillType == "1255")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_PackageDismantleList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_PackageDismantleList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //工序流转卡
                if (oSelectRow.BillType == "3772")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_ProcessExchangeList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ProcessExchangeList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //工序汇报单
                if (oSelectRow.BillType == "3714")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_IF_ProcessReportList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ProcessReportList");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                }
                //即时库存
                if (oSelectRow.BillType == "JSKC")
                {
                    grdMain.Rows.Add();
                    Application.DoEvents();
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_KF_ICInventoryList_IF where hmaterid=" + oSelectRow.BillMainID + " and hwhid=" + oSelectRow.BillSubID + " and hspid=" + oSelectRow.SPID + " and HAuxPropID=" + oSelectRow.HAuxPropID + " and 批次='" + oSelectRow.BatchNo + "' and 计划跟踪号='" + oSelectRow.BillNo + "' and 生产日期='" + oSelectRow.HProduceDate + "' and 有效期至='" + oSelectRow.HExpiryDate + "'", "h_v_KF_ICInventoryList_IF");
                    //写入信息
                    Sub_WriteInForm2(Ds.Tables[0], i);
                }
            }
            //
            oSumGrid.Changelock = false;
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
 
            if (grdMain.Rows.Count > 0)
            {
                //根据源单设置表头
                textBox_HMaterNumber.Text = grdMain.Rows[0].Cells[HMaterNumberCol].Value.ToString();
                textBox_HMaterName.Text = grdMain.Rows[0].Cells[HMaterNameCol].Value.ToString();
                textBox_HMaterModel.Text = grdMain.Rows[0].Cells[HMaterModelCol].Value.ToString();
                long HMaterID = ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value.ToString());
                Ds = oCn.RunProcReturn("select * from Gy_Material where HItemID = " + HMaterID + " and HUSEORGID =" + HOrgID, "Gy_Material");
                if (Ds != null && Ds.Tables[0].Rows.Count > 0)
                {
                    string HBatchManager = Ds.Tables[0].Rows[0]["HBatchManager"].ToString();
                    if (HBatchManager == "False")
                    {
                        radioButton_HIsUsingBatchNo.Checked = false;
                    }
                    else
                    {
                        radioButton_HIsUsingBatchNo.Checked = true;
                    }
                }
                //设置批号
                if (radioButton_HIsUsingBatchNo.Checked)
                {
                    grdMain.Rows[0].Cells[HBatchNoCol].Value = getBatchNo();
                }
            }
        }
        //根据TABLE写入界面(生产任务单) 
        private void Sub_WriteInForm(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            grdMain.Rows[i].Cells[HTagCol].Value = "*";
            grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //
            grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); //博日 收料单据日期
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
            grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
            grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString();
            grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            //grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[0]["是否启用批次"].ToString();
            grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            grdMain.Rows[i].Cells[HCusIDCol].Value = oTable.Rows[0]["HCusID"].ToString();
            grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["客户代码"].ToString();
            grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["客户"].ToString();
            grdMain.Rows[i].Cells[HCusTypeCol].Value = oTable.Rows[0]["客户型号"].ToString();
            grdMain.Rows[i].Cells[HPinfanBarCodeCol].Value = oTable.Rows[0]["HPinfanBarCode"].ToString();
            grdMain.Rows[i].Cells[HPinfanCol].Value = oTable.Rows[0]["HPinfan"].ToString();
            //grdMain.Rows[i].Cells[HSourceIDCol].Value = oTable.Rows[0]["HSourceID"].ToString();
            //grdMain.Rows[i].Cells[HSourceNumberCol].Value = oTable.Rows[0]["生产线代码"].ToString();
            grdMain.Rows[i].Cells[HSourceNameCol].Value = oTable.Rows[0]["生产线"].ToString();
            grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();//博日 生产订单 失效日期
            if (cmbHBarCodeType.Text == "仪器外购件条码容器规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            }
            else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则"
                || cmbHBarCodeType.Text == "仪器成品条码规则"
                || cmbHBarCodeType.Text == "试剂成品条码规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
            }
            else
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
            }
            grdMain.Rows[i].Cells[HProduceDateCol].Value = oTable.Rows[0]["HProduceDate"].ToString();
            grdMain.Rows[i].Cells[HExpiryDateCol].Value = oTable.Rows[0]["HExpiryDate"].ToString();
            grdMain.Rows[i].Cells[HISKFPERIODCol].Value = oTable.Rows[0]["HISKFPERIOD"].ToString();
            grdMain.Rows[i].Cells[HEXPUNITCol].Value = oTable.Rows[0]["HEXPUNIT"].ToString();
            grdMain.Rows[i].Cells[HEXPPERIODCol].Value = oTable.Rows[0]["HEXPPERIOD"].ToString();
 
 
            //自动生成-设置数量、最小包装数、箱数为1
            grdMain.Rows[i].Cells[HQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HMinQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HBQtyCol].Value = 1;
 
 
 
 
            //--
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HMinQtyCol.ToString() +
                                "," + HAuxPropNumberCol.ToString() +
                                "," + HBatchNoCol.ToString() +
                                "," + HPackQtyCol.ToString() +
                                "," + HRemarkCol.ToString();
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 3;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
 
        //根据TABLE写入界面
        private void Sub_WriteInForm1(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            grdMain.Rows[i].Cells[HTagCol].Value = "*";
            grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //
            grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); //博日 单据日期
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
            grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString();
            grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            //grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[0]["是否启用批次"].ToString();
            grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            grdMain.Rows[i].Cells[HProduceDateCol].Value = oTable.Rows[0]["生产日期"].ToString();
            grdMain.Rows[i].Cells[HExpiryDateCol].Value = oTable.Rows[0]["有效期至"].ToString();
            grdMain.Rows[i].Cells[HISKFPERIODCol].Value = oTable.Rows[0]["HISKFPERIOD"].ToString();
            grdMain.Rows[i].Cells[HEXPUNITCol].Value = oTable.Rows[0]["HEXPUNIT"].ToString();
            grdMain.Rows[i].Cells[HEXPPERIODCol].Value = oTable.Rows[0]["HEXPPERIOD"].ToString();
            if (cmbHBarCodeType.Text == "仪器外购件条码容器规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            }
            else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
            }
            else
            {
                if (CampanyName == "中控")
                {
                    grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
                }
                else
                {
                    grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
                }
            }
            grdMain.Rows[i].Cells[HMakerCol].Value = ClsPub.CurUserName;
            if (cmbSourceBillType.Text.Trim() == "收料通知单" || cmbSourceBillType.Text.Trim() == "采购订单"
                || cmbSourceBillType.Text.Trim() == "委外订单" || cmbSourceBillType.Text.Trim() == "采购入库单")
            {
                grdMain.Rows[i].Cells[HInnerBillNoCol].Value = oTable.Rows[0]["内部采购订单号"].ToString();
                grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
                grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
                grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
                if (cmbSourceBillType.Text.Trim() == "收料通知单")
                {
                    if (oTable.Rows[0]["是否赠品"].ToString() == "是")
                    {
                        grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value = 1;
                    }
                    else
                    {
                        grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value = 0;
                    }
                    grdMain.Rows[i].Cells[HSeOrderBillNoCol].Value = oTable.Rows[0]["销售订单号"].ToString();
                    grdMain.Rows[i].Cells[HSeOrderSEQCol].Value = oTable.Rows[0]["销售订单行号"].ToString();
                }
 
            }
            if (cmbSourceBillType.Text.Trim() == "退货通知单")
            {
                grdMain.Rows[i].Cells[HCusIDCol].Value = oTable.Rows[0]["HCusID"].ToString();
                grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["客户代码"].ToString();
                grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["客户"].ToString();
            }
            if (cmbSourceBillType.Text.Trim() == "其他入库单")
            {
                grdMain.Rows[i].Cells[HWhIDCol].Value = oTable.Rows[0]["HWhID"].ToString();
                grdMain.Rows[i].Cells[HWhNumberCol].Value = oTable.Rows[0]["仓库代码"].ToString();
                grdMain.Rows[i].Cells[HWhNameCol].Value = oTable.Rows[0]["仓库"].ToString();
                grdMain.Rows[i].Cells[HSPIDCol].Value = oTable.Rows[0]["HSPID"].ToString();
                grdMain.Rows[i].Cells[HSPNumberCol].Value = oTable.Rows[0]["仓位代码"].ToString();
                grdMain.Rows[i].Cells[HSPNameCol].Value = oTable.Rows[0]["仓位"].ToString();
            }
 
            //自动生成-设置数量、最小包装数、箱数为1
            grdMain.Rows[i].Cells[HQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HMinQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HBQtyCol].Value = 1;
 
 
            //--
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HMinQtyCol.ToString() +
                                "," + HAuxPropNumberCol.ToString() +
                                "," + HBatchNoCol.ToString() +
                                "," + HRemarkCol.ToString();
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 3;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
 
        //根据TABLE写入界面(K3即时库存)
        private void Sub_WriteInForm2(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            grdMain.Rows[i].Cells[HTagCol].Value = "*";
            grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["数量"]);
            grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["数量"]);
            //
            //grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            //grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["任务单号"].ToString();
            //grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            grdMain.Rows[i].Cells[HAuxPropIDCol].Value = oTable.Rows[0]["HAuxPropID"].ToString();
            grdMain.Rows[i].Cells[HAuxPropNumberCol].Value = oTable.Rows[0]["辅助属性代码"].ToString();
            grdMain.Rows[i].Cells[HAuxPropNameCol].Value = oTable.Rows[0]["辅助属性名称"].ToString();
            grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["HSupplyID"].ToString();
            grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            grdMain.Rows[i].Cells[HWhIDCol].Value = oTable.Rows[0]["HWhID"].ToString();
            grdMain.Rows[i].Cells[HWhNumberCol].Value = oTable.Rows[0]["仓库代码"].ToString();
            grdMain.Rows[i].Cells[HWhNameCol].Value = oTable.Rows[0]["仓库"].ToString();
            grdMain.Rows[i].Cells[HSPIDCol].Value = oTable.Rows[0]["HSPID"].ToString();
            grdMain.Rows[i].Cells[HSPNumberCol].Value = oTable.Rows[0]["仓位代码"].ToString();
            grdMain.Rows[i].Cells[HSPNameCol].Value = oTable.Rows[0]["仓位"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = ClsPub.GetServerDate(0);
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HRemarkCol].Value = "按库存生成";
            grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            grdMain.Rows[i].Cells[HProduceDateCol].Value = oTable.Rows[0]["生产日期"].ToString();
            grdMain.Rows[i].Cells[HExpiryDateCol].Value = oTable.Rows[0]["有效期至"].ToString();
            grdMain.Rows[i].Cells[HISKFPERIODCol].Value = oTable.Rows[0]["HISKFPERIOD"].ToString();
            grdMain.Rows[i].Cells[HEXPUNITCol].Value = oTable.Rows[0]["HEXPUNIT"].ToString();
            grdMain.Rows[i].Cells[HEXPPERIODCol].Value = oTable.Rows[0]["HEXPPERIOD"].ToString();
            if (CampanyName == "中控")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["数量"]);
            }
 
            //自动生成-设置数量、最小包装数、箱数为1
            grdMain.Rows[i].Cells[HQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HMinQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HBQtyCol].Value = 1;
 
 
            //--
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HRemarkCol.ToString() +
                                "," + HMinQtyCol.ToString();
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 3;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
 
        //根据TABLE写入界面(倒箱单)
        private void Sub_WriteInForm3(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            grdMain.Rows[i].Cells[HTagCol].Value = "*";
            grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["可生成条码数量"]);
            grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["可生成条码数量"]);
            //
            grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString();
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
            grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString();
            grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            grdMain.Rows[i].Cells[HPinfanCol].Value = oTable.Rows[0]["品番"].ToString();
            grdMain.Rows[i].Cells[HPinfanBarCodeCol].Value = oTable.Rows[0]["HPinfanBarCode"].ToString();
            grdMain.Rows[i].Cells[HAuxPropIDCol].Value = oTable.Rows[0]["HAuxPropID"].ToString();
            grdMain.Rows[i].Cells[HAuxPropNumberCol].Value = oTable.Rows[0]["辅助属性代码"].ToString();
            grdMain.Rows[i].Cells[HAuxPropNameCol].Value = oTable.Rows[0]["辅助属性名称"].ToString();
            grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批号"].ToString();
            grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            //获取最新最小包装数
            DataSet oDs = new DataSet();
            oDs = oCn.RunProcReturn("exec h_p_Gy_StdPack " + oTable.Rows[0]["HMaterID"].ToString() + "," + oTable.Rows[0]["HAuxPropID"].ToString(), "h_p_Gy_StdPack");
            //
            if (oDs != null && oDs.Tables[0].Rows.Count > 0)
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = DBUtility.ClsPub.isSingle(oDs.Tables[0].Rows[0]["HMinPack"]);
            }
 
            //自动生成-设置数量、最小包装数、箱数为1
            grdMain.Rows[i].Cells[HQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HMinQtyCol].Value = 1;
            grdMain.Rows[i].Cells[HBQtyCol].Value = 1;
 
 
            //--
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HRemarkCol.ToString() +
                                "," + HMaterNameCol.ToString() +
                                "," + HMaterModelCol.ToString() +
                                "," + HPinfanCol.ToString() +
                                "," + HMinQtyCol.ToString();
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 3;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
 
        //网格编辑前判断
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            {
                e.Cancel = true;
            }
        }
 
        //网格编辑后处理
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            if (e.ColumnIndex == HMinQtyCol)
            {
                RowCount(e.RowIndex, 0);  //
            }
            else if (e.ColumnIndex == HQtyCol)
            {
                RowCount(e.RowIndex, 0);  //
            }
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
        DataGridViewTextBoxEditingControl EditingControl;
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            //
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            //if (oSumGrid.Changelock)
            //    return;
            //if(oSumGrid.EditStatus)
            //{
            if (!CheckGridRow(oSumGrid.OldCell.Row))
                return;
            //}
        }
 
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdMain.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //增加委托处理 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
            }
        }
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //业务处理 
            Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl);
        }
        private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            oSumGrid.DisplayCurRow();
        }
 
        #endregion
 
 
        #region  //打印设置
 
        GridppReport Report;
        int CurRows = 0;
        string sBarCodeItemID = ""; //条码自增列
 
        //预览
        private void yl_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再预览!");
                return;
            }
 
            //打印前判断条码是否已打印过
            if (ReportPrintBegin())
            {
                return;
            }
 
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
 
        //打印
        private void dy_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再打印!");
                return;
            }
 
            //打印前判断条码是否已打印过
            if (ReportPrintBegin())
            {
                return;
            }
 
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                //循环选中行
                Sub_SetReport(oFrm.sOpenTmp);
                Report.Print(true);
                Thread.Sleep(1000);
            }
        }
 
        ////打印前判断条码是否已打印过
        //private bool ReportPrintBegin()
        //{
        //    string sRelQty = "";
 
        //    if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value), ref sRelQty))
        //    {
        //        MessageBox.Show("条码已经打印过,不可重复打印!");
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
 
        //打印前判断条码是否超过允许可打印次数
        private bool ReportPrintBegin()
        {
            string sHRemark = "";
            if (PrintQtyCtl == "Y")
            {
                if (oBar.Set_CheckPrintQty_SD(HInterID, PrintQty, ref sHRemark))
                {
                    MessageBox.Show(sHRemark);
                    return true;
                }
                return false;
            }
            else
            {
                return false;
            }
        }
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdList.Rows.Count; i++)
            {
                grdList.Rows[i].Cells[0].Value = "*";
            }
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
        }
 
        //填入单据表头信息
        private void ReportBeforePostRecord()// 
        {
            try
            {
                //Report.FieldByName("物料代码").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterNumber2Col].Value);
                //Report.FieldByName("物料名称").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterName2Col].Value);
                //Report.FieldByName("规格型号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterModel2Col].Value);
                ////Report.FieldByName("自定义规格").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HModel2Col].Value);
                //Report.FieldByName("条码编号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HTMCol].Value);
                //Report.FieldByName("数量").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HQty2Col].Value);
                //Report.FieldByName("源单单号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HSourceBillNoCol].Value);
                //Report.FieldByName("销售订单号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HSeOrderBillNo2Col].Value);
                //Report.FieldByName("生产车间").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HDeptName2Col].Value);
                //Report.FieldByName("备注").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HRemark2Col].Value);
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表头:" + e.Message);
            }
        }
 
        //填入单据表体信息
        private void ReportFetchRecordByDataTable()
        {
            try
            {
                DataTable ds = new DataTable();
                BLL.Utility.FillRecordToReport_Sel(Report, grdList, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表体:" + e.Message);
            }
        }
 
        ////打印结束后回填条码打印次数
        //private void ReportPrintEnd()
        //{
        //    try
        //    {
        //        oCn.RunProc("update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0)+1 where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
        //    }
        //    catch (Exception e)
        //    {
        //        MessageBox.Show("打印失败!打印结束 :" + e.Message);
        //    }
        //}
 
        //打印结束后回填条码打印次数
        private void ReportPrintEnd()
        {
            if (UpdatePrintQtyCtl == "Y")
            {
                oBar.Set_UpdatePrintQty_SD(HInterID);
            }
        }
 
        //试打印
        private void sdy_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再预览!");
                return;
            }
 
            //打印前判断条码是否已打印过
            if (ReportPrintBegin_SDY())
            {
                return;
            }
 
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReportView(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
 
        //打印前判断条码是否超过允许可打印次数
        private bool ReportPrintBegin_SDY()
        {
            string sHRemark = "";
            sBarCodeItemID = "";
            for (int i = 0; i < grdList.SelectedRows.Count; i++)
            {
                sBarCodeItemID = sBarCodeItemID + "," + DBUtility.ClsPub.isLong(grdList.Rows[grdList.SelectedRows[i].Index].Cells[Fun_GetCol("HItemID")].Value).ToString();
            }
            sBarCodeItemID = sBarCodeItemID.Remove(0, 1);
 
            if (PrintQtyCtl == "Y")
            {
                if (oBar.Set_CheckPrintQty(sBarCodeItemID, PrintQty, ref sHRemark))
                {
                    MessageBox.Show(sHRemark);
                    return true;
                }
                return false;
            }
            else
            {
                return false;
            }
        }
 
        private void Sub_SetReportView(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdList.Rows.Count; i++)
            {
                grdList.Rows[i].Cells[0].Value = "";
            }
            for (int i = 0; i < grdList.SelectedRows.Count; i++)
            {
                grdList.Rows[grdList.SelectedRows[i].Index].Cells[0].Value = "*";
            }
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd_SDY);
        }
 
        //打印结束后回填条码打印次数
        private void ReportPrintEnd_SDY()
        {
            if (UpdatePrintQtyCtl == "Y")
            {
                oBar.Set_UpdatePrintQty(sBarCodeItemID);
            }
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
        }
 
 
        #endregion
 
 
        private void grdSub_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdSub.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            {
                e.Cancel = true;
            }
        }
 
        private void grdSub_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            RowCount(e.RowIndex, 0);  //计算 金额 单价
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
 
        //按库存生成条码
        private void kc_Click(object sender, EventArgs e)
        {
            long sHOrgID = -1;
            string sWhere = "";
 
            DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
            if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
            {
                sHOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
            }
            if (sHOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
            sWhere = " and HOrgID =" + sHOrgID.ToString();
            BLL.Cls_S_KF_ICInventoryList_IF oadd = new BLL.Cls_S_KF_ICInventoryList_IF();
            if (oadd.Refresh(sWhere))  //选择原单
            //if (oadd.Refresh(" and HErpClsID in (1,2,3) "))  //选择原单
            {
                FillSelectData(oadd.oBillSelectColl);
            }
        }
 
 
        //获取本月的第几周
        private static int getWeekNumInMonth(DateTime daytime)
        {
            int dayInMonth = daytime.Day;
            //本月第一天
            DateTime firstDay = daytime.AddDays(1 - daytime.Day);
            //本月第一天是周几
            int weekday = (int)firstDay.DayOfWeek == 0 ? 7 : (int)firstDay.DayOfWeek;
            //本月第一周有几天
            int firstWeekEndDay = 7 - (weekday - 1);
            //当前日期和第一周之差
            int diffday = dayInMonth - firstWeekEndDay;
            diffday = diffday > 0 ? diffday : 1;
            //当前是第几周,如果整除7就减一天
            int WeekNumInMonth = ((diffday % 7) == 0
             ? (diffday / 7 - 1)
             : (diffday / 7)) + 1 + (dayInMonth > firstWeekEndDay ? 1 : 0);
            return WeekNumInMonth;
        }
 
        //同步基础资料信息
        private void tb_Click(object sender, EventArgs e)
        {
            try
            {
                oCn.RunProc("exec h_p_IF_ERPDataToLocal", ref DBUtility.ClsPub.sExeReturnInfo);
                MessageBox.Show("同步基础资料成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("同步基础资料失败!" + ex);
            }
        }
        public Frm_Split oDlg = new Frm_Split();
        private void spRow_Click(object sender, EventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
            oDlg.ShowDialog();
            if (oDlg.IsOk == 1)
            {
                grdMainData_CF(DBUtility.ClsPub.isInt(oDlg.txtHQ.Text));
            }
        }
 
 
        private void grdMainData_CF(int HQty)
        {
            double hq = 0;
            int Qty = HQty - 1;
            int row = grdMain.CurrentCell.RowIndex;
            grdMain.Rows.Insert(row + 1, Qty);
            hq = DBUtility.ClsPub.isDoule(grdMain.Rows[row].Cells[HQtyCol].Value) / HQty;
            grdMain.Rows[row].Cells[HQtyCol].Value = hq;
            for (int i = 0; i < Qty; i++)
            {
                int r = i + 1;
                grdMain.Rows[row + r].Cells[HMaterIDCol].Value = grdMain.Rows[row].Cells[HMaterIDCol].Value;
                grdMain.Rows[row + r].Cells[HMaterNumberCol].Value = grdMain.Rows[row].Cells[HMaterNumberCol].Value;
                grdMain.Rows[row + r].Cells[HMaterNameCol].Value = grdMain.Rows[row].Cells[HMaterNameCol].Value;
                grdMain.Rows[row + r].Cells[HMaterModelCol].Value = grdMain.Rows[row].Cells[HMaterModelCol].Value;
                grdMain.Rows[row + r].Cells[HUnitIDCol].Value = grdMain.Rows[row].Cells[HUnitIDCol].Value;
                grdMain.Rows[row + r].Cells[HUnitNameCol].Value = grdMain.Rows[row].Cells[HUnitNameCol].Value;
                grdMain.Rows[row + r].Cells[HSourceIDCol].Value = grdMain.Rows[row].Cells[HSourceIDCol].Value;
                grdMain.Rows[row + r].Cells[HSourceNumberCol].Value = grdMain.Rows[row].Cells[HSourceNumberCol].Value;
                grdMain.Rows[row + r].Cells[HSourceNameCol].Value = grdMain.Rows[row].Cells[HSourceNameCol].Value;
                grdMain.Rows[row + r].Cells[HQtyCol].Value = DBUtility.ClsPub.isDoule(hq, 4);
                grdMain.Rows[row + r].Cells[HinitQtyCol].Value = DBUtility.ClsPub.isDoule(hq, 4);
                grdMain.Rows[row + r].Cells[HMinQtyCol].Value = 0;
 
                grdMain.Rows[row + r].Cells[HTagCol].Value = grdMain.Rows[row].Cells[HTagCol].Value;
                grdMain.Rows[row + r].Cells[HMainIDCol].Value = grdMain.Rows[row].Cells[HMainIDCol].Value;
                grdMain.Rows[row + r].Cells[HSubIDCol].Value = grdMain.Rows[row].Cells[HSubIDCol].Value;
                grdMain.Rows[row + r].Cells[HBillNoCol].Value = grdMain.Rows[row].Cells[HBillNoCol].Value;
                grdMain.Rows[row + r].Cells[HBillTypeCol].Value = grdMain.Rows[row].Cells[HBillTypeCol].Value;
                grdMain.Rows[row + r].Cells[HDateCol].Value = grdMain.Rows[row].Cells[HDateCol].Value;
                grdMain.Rows[row + r].Cells[HShowDateCol].Value = grdMain.Rows[row].Cells[HShowDateCol].Value;
                grdMain.Rows[row + r].Cells[HEndDateCol].Value = grdMain.Rows[row].Cells[HEndDateCol].Value;
                grdMain.Rows[row + r].Cells[HSupIDCol].Value = grdMain.Rows[row].Cells[HSupIDCol].Value;
                grdMain.Rows[row + r].Cells[HSupNumberCol].Value = grdMain.Rows[row].Cells[HSupNumberCol].Value;
                grdMain.Rows[row + r].Cells[HSupNameCol].Value = grdMain.Rows[row].Cells[HSupNameCol].Value;
                grdMain.Rows[row + r].Cells[HDeptIDCol].Value = grdMain.Rows[row].Cells[HDeptIDCol].Value;
                grdMain.Rows[row + r].Cells[HDeptNumberCol].Value = grdMain.Rows[row].Cells[HDeptNumberCol].Value;
                grdMain.Rows[row + r].Cells[HDeptNameCol].Value = grdMain.Rows[row].Cells[HDeptNameCol].Value;
                grdMain.Rows[row + r].Cells[HBatchNoCol].Value = grdMain.Rows[row].Cells[HBatchNoCol].Value;
                grdMain.Rows[row + r].Cells[HAuxPropIDCol].Value = grdMain.Rows[row].Cells[HAuxPropIDCol].Value;
                grdMain.Rows[row + r].Cells[HAuxPropNumberCol].Value = grdMain.Rows[row].Cells[HAuxPropNumberCol].Value;
                grdMain.Rows[row + r].Cells[HAuxPropNameCol].Value = grdMain.Rows[row].Cells[HAuxPropNameCol].Value;
                grdMain.Rows[row + r].Cells[HRemarkCol].Value = grdMain.Rows[row].Cells[HRemarkCol].Value;
                grdMain.Rows[row + r].Cells[HMTONoCol].Value = grdMain.Rows[row].Cells[HMTONoCol].Value;
                grdMain.Rows[row + r].Cells[HInnerBillNoCol].Value = grdMain.Rows[row].Cells[HInnerBillNoCol].Value;
                grdMain.Rows[row + r].Cells[HMakerCol].Value = grdMain.Rows[row].Cells[HMakerCol].Value;
                //网格打勾
                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                oCell.ThreeState = false;
                oCell.Value = grdMain.Rows[row].Cells[HGiveAwayFlagCol].Value;
                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grdMain.Rows[row + r].Cells[HGiveAwayFlagCol] = oCell;
 
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdSub_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
 
        private void Display()
        {
            //设置档案列表选项卡表格数据
            DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " order by HItemID", "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdList.DataSource = DSet.Tables[0].DefaultView;
            //冻结
            int FrCol = 0;
            string s = "是";
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
            //画线
            //GraphLine();
        }
 
        // //设置工单条码选项卡表格数据
        private void Display4()
        {
            if (grdMain.Rows.Count > 0)
            {
                //日期获取方式
                string sDate = dtpHDate.Value.ToShortDateString();                                                                                     //
                string sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                string sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                string sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                sDay = sDay.Substring(sDay.Length - 2, 2);
 
                sDate = "20" + sYear + "-" + sPeriod + "-" + sDay;
 
                //设置工单条码选项卡表格数据
                string sql = "select * from h_v_IF_BarCodeBillList Where 源单单号 = '" + grdMain.Rows[0].Cells[HBillNoCol].Value + "' and HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + sDate + "' order by 条码编号";
                DataSet DSet1 = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo);
                //生成首行标题
                if (DSet1 == null)
                {
                    return;
                }
                //
                grdBillBarCodeList.DataSource = DSet1.Tables[0].DefaultView;
                //冻结
                int FrCol = 0;
                string s = "是";
                DBUtility.Xt_BaseBillFun.DisplayGrid(grdBillBarCodeList, this.Name + "grdBillBarCodeList", s, FrCol);
                //画线
                //GraphLine();
                // 
            }
        }
 
        //关联按钮
        private void gl_Click(object sender, EventArgs e)
        {
            try
            {
                long HInterID = DBUtility.ClsPub.isLong(grdList.Rows[0].Cells[Fun_GetCol("HInterID")].Value);
                string HBarCode = DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetCol("条码编号")].Value);
                string HBarCodeType = DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetCol("条码类型")].Value);
                string HSourceBillType = DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetCol("HSourceBillType")].Value);
 
                DataSet oDs = oCn.RunProcReturn("exec h_p_WMS_BarCodeToICStockBillSub_Insert " + HInterID.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "','" + HSourceBillType + "'", "h_p_WMS_BarCodeToICStockBillSub_Insert");
                //
                if (oDs == null && oDs.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("关联自动生成条码出入库记录失败!");
                }
                else
                {
                    MessageBox.Show(DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HRemark"]));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("关联自动生成条码出入库记录失败22!" + ex);
            }
        }
 
        //批次按钮
        private void BatchNo_Click(object sender, EventArgs e)
        {
            lblCaption.Focus();
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value);          // 物料内码
                string HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HBatchNoCol].Value);     // 批号
 
                if (HMaterID != 0)
                {
                    DataSet oDs = oCn.RunProcReturn("exec h_p_Gy_BarCodeBill_GetBatchNo " + HMaterID.ToString() + ",'" + HBatchNo + "','" + dtpHDate.Value.ToShortDateString() + "','" + CampanyName + "'", "h_p_Gy_BarCodeBill_GetBatchNo");
                    //
                    if (oDs == null && oDs.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("生成批次失败!");
                        return;
                    }
                    else if (DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0][0]) == "1")
                    {
                        grdMain.Rows[i].Cells[HBatchNoCol].Value = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HBatchNo"]);
                        b = true;
                    }
                }
            }
            //明细表是否为零行
            if (b == false)
            {
                MessageBox.Show("没有需要生成批次的明细行!", "提示");
                return;
            }
        }
 
        private void txtHSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)//回车带出源单信息
            {
                long sHOrgID = -1;
                DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
                if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
                {
                    sHOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
                }
 
                if (txtHSourceBillNo.Text.Length < 4)
                {
                    MessageBox.Show("请输入4位以上数据!");
                    return;
                }
                //根据源单类型 和源单号 获取信息
                if (cmbSourceBillType.Text.Trim() == "生产订单")
                {
                    DAL.Cls_S_IFCLD_ICMOList oIFCLD_ICMOList = new DAL.Cls_S_IFCLD_ICMOList();
                    //系统参数,生成条码数量可否超源单数量控制(N为不可超源单数量)
                    if (SourceQtyCtl == "N")
                    {
                        if (oIFCLD_ICMOList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + sHOrgID.ToString() + " and 任务数量>0"))  //选择原单
                        {
                            FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
                            txtHSourceBillNo.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                            return;
                        }
                    }
                    else
                    {
                        if (oIFCLD_ICMOList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + sHOrgID.ToString()))  //选择原单
                        {
                            FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
                            txtHSourceBillNo.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                            return;
                        }
                    }
                }
                else if (cmbSourceBillType.Text.Trim() == "生产汇报单")
                {
                    DAL.Cls_S_IF_ICMOReportBillList oIF_ICMOReportBillList = new DAL.Cls_S_IF_ICMOReportBillList();
                    if (oIF_ICMOReportBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
                    {
                        FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else if (cmbSourceBillType.Text.Trim() == "收料通知单")
                {
                    DAL.Cls_S_IF_POInStockBillList oIF_POInStockBillList = new DAL.Cls_S_IF_POInStockBillList();
                    if (oIF_POInStockBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
                    {
                        FillSelectData(oIF_POInStockBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else if (cmbSourceBillType.Text.Trim() == "采购订单")
                {
                    DAL.Cls_S_IF_POOrderBillList oIF_POOrderBillList = new DAL.Cls_S_IF_POOrderBillList();
                    if (oIF_POOrderBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
                    {
                        FillSelectData(oIF_POOrderBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else if (cmbSourceBillType.Text.Trim() == "委外订单")
                {
                    DAL.Cls_S_IF_EntrustOrderBillList oIF_EntrustOrderBillList = new DAL.Cls_S_IF_EntrustOrderBillList();
                    if (oIF_EntrustOrderBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
                    {
                        FillSelectData(oIF_EntrustOrderBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("所选源单类型,不支持此功能!");
                    return;
                }
 
            }
        }
 
 
        //生成外箱码
        private void wxm_Click(object sender, EventArgs e)
        {
            try
            {
                Int64 iInterID = 0;
                Int64 dPackQty = 0; //外箱数量
                Int64 dPackLeftQty = 0; //外箱剩余数量
                Int64 dLabelQty = 0; //小箱数量
                Int64 dQty = 0; //总数量
                Int64 dEntryID = 0; //行号
                string sPackBarCode = ""; //外箱码
                string sBarCode = ""; //唯一码
                Int64 LSH = 0;
                DataSet Ds;
                string sYear = DateTime.Today.Year.ToString().Substring(2, 2);
                string sPeriod = "0" + DateTime.Today.Month.ToString();
                sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                string sDay = "0" + DateTime.Today.Day.ToString();
                sDay = sDay.Substring(sDay.Length - 2, 2);
                //
                string sPackStr = "ZXM" + sYear + sPeriod + sDay; //外箱码 前缀
 
                //必须条码生成按钮是灰度才可以生成箱条码
                if (bc.Enabled != false)
                {
                    MessageBox.Show("请先生成条形码,再生成箱条码");
                    return;
                }
                //-------------------根据HINTERID生成箱条码
                //生成前判断,循环物料网格,判断 是否设置了合理的 外箱数量。 外箱数量 必须是 最小包装数的 倍数 并必须大于0和大于等于最小包装数量。
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0)
                    {
                        if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value) <= 0)
                        {
                            MessageBox.Show("请录入合理的外箱数量,第" + Convert.ToString(i + 1) + "行");
                            return;
                        }
                        if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value)
                            % DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMinQtyCol].Value) != 0
                            || DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value)
                            < DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMinQtyCol].Value))
                        {
                            MessageBox.Show("外箱数量必须是最小包装数的倍数,且大于等于最小包装数,第" + Convert.ToString(i + 1) + "行");
                            return;
                        }
                    }
                }
                //oCn.BeginTran();
                //从0行进行循环 物料网格,获取外箱数量
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0)
                    {
                        //获取总数量、外箱数量 
                        dPackQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
                        dQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HQtyCol].Value);
                        dEntryID = i + 1;
                        dPackLeftQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
                        //生成一个外箱码
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
                        sPackBarCode = sPackStr + LSH.ToString();
                        oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
                        //子循环 条码网格
                        for (int j = 0; j < grdSub.Rows.Count; j++)
                        {
                            if (dEntryID == DBUtility.ClsPub.isLong(grdSub.Rows[j].Cells[HEntryID2Col].Value))
                            {
                                if (dQty <= 0)
                                {
                                    continue;
                                }
                                if (dPackLeftQty > 0) //当剩余外箱数量小于等于0时,重新生成外箱码
                                {
                                }
                                else
                                {
                                    //生成一个外箱码
                                    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                                    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
                                    sPackBarCode = sPackStr + LSH.ToString();
                                    oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
                                    dPackLeftQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
                                }
                                sBarCode = DBUtility.ClsPub.isStrNull(grdSub.Rows[j].Cells[HTMCol].Value); // 条码
                                dLabelQty = DBUtility.ClsPub.isLong(grdSub.Rows[j].Cells[HQty2Col].Value); // 小箱数量
                                oCn.RunProc("update Gy_BarCodebill set HInnerBillNo= '" + sPackBarCode + "' Where HbarCode='" + sBarCode + "'");
                                dPackLeftQty = dPackLeftQty - dLabelQty;
                                dQty = dQty - dLabelQty;
                                if (dPackLeftQty <= 0)//当箱剩余数量小于等于0时 执行 组托单
                                {
                                    //获取组托单内码
                                    iInterID = DBUtility.ClsPub.CreateBillID("3783", ref DBUtility.ClsPub.sExeReturnInfo); ;//得到新单号; 
                                                                                                                            //根据外箱码 写入 组托单主表,组托单子表,SUM,外箱码档案,SUM档案
                                    oCn.RunProc("exec  h_p_WMS_PackUnionBill_AddNew  '" + sPackBarCode + "'," + iInterID.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 主表,子表 ,箱条码档案 
                                    oCn.RunProc("exec  h_p_WMS_PackUnionBill_SumSubBill  " + iInterID.ToString() + ",'" + sPackBarCode + "','3783','" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 SUM表,SUM条码档案
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                wxm.Enabled = false;
                //oCn.Commit();
                MessageBox.Show("生成箱码完毕!");
                //刷新数据
                Display();
            }
            catch (Exception e1)
            {
                //oCn.RollBack();
                MessageBox.Show("生成箱码失败!" + e1.Message);
            }
        }
 
        private void cmbSourceBillType_TextChanged(object sender, EventArgs e)
        {
            if (cmbSourceBillType.Text == "工序流转卡")
            {
                cmbHBarCodeType.Items.Clear();
                cmbHBarCodeType.Items.Add("序列码");
                this.cmbHBarCodeType.SelectedIndex = 0;
            }
            else
            {
                if (CampanyName == "夏宝电器")
                {
                    cmbHBarCodeType.Items.Clear();
                    cmbHBarCodeType.Items.Add("内销机条码");
                    cmbHBarCodeType.Items.Add("外销机条码");
                    cmbHBarCodeType.Items.Add("半成品条码");
                    this.cmbHBarCodeType.SelectedIndex = 0;
                }
                else if (CampanyName == "博日科技")
                {
                    cmbHBarCodeType.Items.Clear();
                    cmbHBarCodeType.Items.Add("仪器外购件条码普通规则");
                    cmbHBarCodeType.Items.Add("仪器外购件条码容器规则");
                    cmbHBarCodeType.Items.Add("仪器成品条码规则");
                    cmbHBarCodeType.Items.Add("试剂成品条码规则");
                    this.cmbHBarCodeType.SelectedIndex = 0;
                }
                else if (CampanyName == "中控")
                {
                    cmbHBarCodeType.Items.Clear();
                    cmbHBarCodeType.Items.Add("唯一条码");
                    this.cmbHBarCodeType.SelectedIndex = 0;
                }
                else
                {
                    cmbHBarCodeType.Items.Clear();
                    cmbHBarCodeType.Items.Add("唯一条码");
                    cmbHBarCodeType.Items.Add("品种条码");
                    cmbHBarCodeType.Items.Add("批次条码");
                    this.cmbHBarCodeType.SelectedIndex = 0;
                }
            }
        }
 
        private void cmdSourceBillNo_Click_1(object sender, EventArgs e)
        {
            cmdSourceBillNo_Click(sender, e);
        }
 
        private void button_startListen_Click(object sender, EventArgs e)
        {
            try
            {
                if (grdMain.Rows.Count == 0 || grdMain.Rows[0].Cells[HMaterIDCol].Value == null || grdMain.Rows[0].Cells[HMaterIDCol].Value.ToString() == "" || grdMain.Rows[0].Cells[HMaterIDCol].Value.ToString() == "0")
                {
                    MessageBox.Show("请选择源单!");
                    return;
                }
 
                if (textBox_IPParams.Text == "")
                {
                    MessageBox.Show("请设置IP地址!");
                    return;
                }
                if (textBox_PortParams.Text == "")
                {
                    MessageBox.Show("请设置端口号!");
                    return;
                }
 
                if (comboBox_PrinterParams.Text == "")
                {
                    MessageBox.Show("请选择打印机!");
                    return;
                }
 
                if (textBox_PrintModelParams.Text == "")
                {
                    MessageBox.Show("请设置打印模板!");
                    return;
                }
 
                if (!judgePrinterIsConnected())
                {
                    MessageBox.Show("打印机处于离线状态,请检查!");
                    return;
                }
 
                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress iPAddress = IPAddress.Parse(textBox_IPParams.Text);
                IPEndPoint point = new IPEndPoint(iPAddress, Convert.ToInt32(textBox_PortParams.Text));
                socket.Connect(point);
 
                Thread thread = new Thread(ReceiveMess);
                thread.Start();
                MessageBox.Show("连接成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        //socket通讯:客户端接收信息
        private void ReceiveMess()
        {
            try
            {
                while (true)
                {
                    byte[] buffer = new byte[1024 * 1024 * 5];
                    int length = socket.Receive(buffer);
                    if (length == 0)
                    {
                        break;
                    }
                    else
                    {
                        string RMess = Encoding.UTF8.GetString(buffer, 0, length);
                        produceQty = ClsPub.isLong(RMess);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("接口异常,已关闭连接:" + ex.Message);
                socket.Close();
            }
        }
 
        private void button_stopListen_Click(object sender, EventArgs e)
        {
            try
            {
                if (socket.Connected)
                {
                    socket.Close();
                }
                else
                {
                    MessageBox.Show("当前尚未连接");
                }
 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        private void button_resetParams_Click(object sender, EventArgs e)
        {
            //comboBox_SourceNameParams.Items.Clear();
            //comboBox_PrinterParams.Items.Clear();
 
            //DBUtility.Xt_BaseBillFun.Sub_ClearBill(groupBox_ParamsInfo);
        }
 
        //写入配置参数
        private void saveParams()
        {
            //判断文件是否存在   
            if (!File.Exists(Application.StartupPath + "//Gy_BarCodeBill_automaticallyByPLC.txt"))
            {
                FileStream fs1 = new FileStream(Application.StartupPath + "//Gy_BarCodeBill_automaticallyByPLC.txt", FileMode.Create, FileAccess.Write);//创建写入文件    
                StreamWriter sw = new StreamWriter(fs1);
                sw.WriteLine(textBox_IPParams.Text);//开始写入值   
                sw.WriteLine(textBox_PortParams.Text);
 
                sw.WriteLine(comboBox_SourceNameParams.Text);
 
                sw.WriteLine(comboBox_PrinterParams.Text.Replace("(默认)",""));
                sw.WriteLine(textBox_PrintModelParams.Text);
                sw.Close();
                fs1.Close();
            }
            else
            {
                FileStream fs1 = new FileStream(Application.StartupPath + "//Gy_BarCodeBill_automaticallyByPLC.txt", FileMode.Create, FileAccess.Write);//创建写入文件    
                StreamWriter sw = new StreamWriter(fs1);
                sw.WriteLine(textBox_IPParams.Text);//开始写入值   
                sw.WriteLine(textBox_PortParams.Text);
 
                sw.WriteLine(comboBox_SourceNameParams.Text);
 
                sw.WriteLine(comboBox_PrinterParams.Text);
                sw.WriteLine(textBox_PrintModelParams.Text);
                sw.Close();
                fs1.Close();
            }
 
            MessageBox.Show("保存成功!");
        }
 
        private void readParams()
        {
            if (File.Exists(Application.StartupPath + "//Gy_BarCodeBill_automaticallyByPLC.txt"))
            {
                //读取文件值并显示到窗体    
                FileStream fs = new FileStream(Application.StartupPath + "//Gy_BarCodeBill_automaticallyByPLC.txt", FileMode.Open, FileAccess.ReadWrite);
                StreamReader sr = new StreamReader(fs);
                string line = sr.ReadLine();
                int curLine = 0;
                while (line != null)
                {
                    if (++curLine == 1)
                    {
                        textBox_IPParams.Text = line;
                    }
                    else if (curLine == 2)
                    {
                        textBox_PortParams.Text = line;
                    }
                    else if (curLine == 3)
                    {
                        for (int i = 0; i < comboBox_SourceNameParams.Items.Count; i++)
                        {
                            if (comboBox_SourceNameParams.Items[i].ToString() == line)
                            {
                                comboBox_SourceNameParams.Text = line;
                            }
                        }
 
                        if (comboBox_SourceNameParams.Text == "")
                        {
                            comboBox_SourceNameParams.Items.Add(line);
                            comboBox_SourceNameParams.Text = line;
                        }
                    }
                    else if (curLine == 4)
                    {
                        for (int i = 0; i < comboBox_PrinterParams.Items.Count; i++)
                        {
                            if (comboBox_PrinterParams.Items[i].ToString() == line)
                            {
                                comboBox_PrinterParams.Text = line;
                            }
                        }
                    }
                    else if (curLine == 5)
                    {
                        textBox_PrintModelParams.Text = line;
                    }
                    else
                    {
 
                    }
                    line = sr.ReadLine();
                }
                sr.Close();
                fs.Close();
            }        
        }
 
        private void button_saveParams_Click(object sender, EventArgs e)
        {
            saveParams();
        }
 
        //判断打印机是否可用
        private bool judgePrinterIsConnected()
        {
            //获取电脑连接的打印机列表
            ManagementObjectSearcher searcher = new
            ManagementObjectSearcher("SELECT * FROM Win32_Printer");
 
            //匹配设置的打印机,并判断是否可用
            string printerName = "";
            foreach (ManagementObject printer in searcher.Get())
            {
                printerName = printer["Name"].ToString().ToLower();
                if (printerName.Equals(comboBox_PrinterParams.Text.Replace("(默认)","").ToLower()))
                {
                    string HPrinterName = printer.Properties["Name"].Value.ToString();                      //获取打印机名称
                    string HPrinterPort = printer.Properties["PortName"].Value.ToString();                  //获取打印机端口号
                    string HPrinterDefault =  printer.Properties["Default"].Value.ToString();               //获取打印机是否是默认打印机
                    string HPrinterWorkStatus = printer.Properties["PrinterStatus"].Value.ToString();       //获取打印机工作状态(1:其他,2:未知,3:空闲,4:打印,5:预热,6:停止打印,7:脱机)
                    string HIsOffOnline = printer.Properties["WorkOffline"].Value.ToString();               //获取打印机是否离线
 
 
                    string isConnected = printer["WorkOffline"].ToString().ToLower();
 
                    if (isConnected.Equals("true"))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            return false;
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < produceQty; i++)
            {
                //生成条码
                this.Sub_SaveBill();
 
                //获取需要打印的数据
                Display();
 
                //设置打印模板,打印
                grdList.Rows[0].Cells[0].Value = "*";
                Report = new GridppReport();
                Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
                Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
                Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
                Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
                if (comboBox_PrinterParams.Text != "")
                {
                    Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(默认)","");
                }
                Report.Print(false);
 
                if(i == produceQty - 1)
                {
                    //重新加载该物料当天生成的条码
                    Display4();
                }
            }
 
            produceQty = 0;
        }
    }
}