1
yangle
22 小时以前 6d0bfe2160e06a4502dc3052c43fab9813341db3
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
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;
 
namespace WarM
{
    public partial class Gy_CusBarCodeBill_KaiBei_LangChao : Form
    {
        public Gy_CusBarCodeBill_KaiBei_LangChao()
        {
            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 HMaterModelCol = 9;
        public const Int16 HCusModelNameCol = 10;
        public const Int16 HUnitIDCol = 11;
        public const Int16 HUnitNumberCol = 12;
        public const Int16 HUnitNameCol = 13;
        public const Int16 HAuxPropIDCol = 14;
        public const Int16 HAuxPropNumberCol = 15;
        public const Int16 HAuxPropNameCol = 16;
        public const Int16 HBatchManagerCol = 17;
        public const Int16 HBatchNoCol = 18;
        public const Int16 HGiveAwayFlagCol = 19;
        public const Int16 HCode1Col = 20;
        public const Int16 HCode2Col = 21;
        public const Int16 HCode3Col = 22;
        public const Int16 HInnerBillNoCol = 23;
        public const Int16 HQtyCol = 24;
        public const Int16 HMinQtyCol = 25;
        public const Int16 HBQtyCol = 26;
        public const Int16 HWMinQtyCol = 27;
        public const Int16 HWBQtyCol = 28;
        public const Int16 HProduceDateCol = 29;
        public const Int16 HExpiryDateCol = 30;
        public const Int16 HCusIDCol = 31;
        public const Int16 HCusNumberCol = 32;
        public const Int16 HCusNameCol = 33;
        public const Int16 HSourceInterIDCol = 34;
        public const Int16 HSourceEntryIDCol = 35;
        public const Int16 HSourceBillNoCol = 36;
        public const Int16 HSourceBillTypeCol = 37;
        public const Int16 HRemarkCol = 38;
        public const Int16 HInitQtyCol = 39;
        public const Int16 HMTONoCol = 40;
        public const Int16 HISKFPERIODCol = 41;
        public const Int16 HEXPUNITCol = 42;
        public const Int16 HEXPPERIODCol = 43;
        public const Int16 HLSHCol = 44;
        public const Int16 HBaNoCol = 45;
        //
        public  string ModName = "85";
        public  string ModCaption = "浪潮客户标签生成";
        public const string ModRightName = "Gy_CusBarCodeBill_KaiBei_LangChao";
 
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DBUtility.ClsXt_BaseBill BaseBill;
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public Frm_Split oDlg = new Frm_Split();
        public bool grdStatus;
        public int selectRow = 0;
        public Int64 HInterID = 0;      //内码
        public Int64 HOrgID = ClsPub.HOrgID;
        public string HCusModel = "Z";     //厂商代码
        public string sDate = "";          //日期
        public string sYear = "";          //年(2位)
        public string sYear4 = "";         //年(4位)
        public string sPeriod = "";        //月
        public string sPeriod2 = "";       //月(正常)
        public string sDay = "";           //日
 
 
        #region 固定代码
 
        //清空界面
        public void Sub_ClearBill()
        {
            cmbSourceBillType.Items.Clear();
            //源单类型
            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"]);
            }
 
            txtHMaker.Text = ClsPub.CurUserName;
            txtHMakeDate.Text = "";
            txtHChecker.Text = "";
            txtHCheckDate.Text = "";
            txtHCloseMan.Text = "";
            txtHCloseDate.Text = "";
            txtHDeleteMan.Text = "";
            txtHDeleteDate.Text = "";
            txtHUpDater.Text = "";
            txtHUpDateDate.Text = "";
            initGrid();
            grdSub.DataSource = null;
            grdList.DataSource = null;
        }
 
        //保存列宽
        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 DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
 
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
            this.Sub_SaveBill();
            Display();
        }
 
        //重置按纽
        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 = 0;
        }
 
        //新增单据
        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_CusBarCodeBill_KaiBei_LangChao_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_CusBarCodeBill_KaiBei_LangChao_Load(object sender, EventArgs e)
        {
            //打印初始化   
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            this.Text = ModCaption;
            this.lblCaption.Text = ModCaption;
            //加载组织信息
            Sub_AddOrdList();
            //加载客户信息
            Sub_AddHCusNameList();
        }
 
        //加载组织信息
        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.DataSource = null;
            cmbHOrgID.Items.Clear();
            cmbHOrgID.DataSource = ds.Tables[0];
            cmbHOrgID.DisplayMember = "HName";
            cmbHOrgID.ValueMember = "HItemID";
        }
 
        //加载客户信息
        private void Sub_AddHCusNameList()
        {
            DataSet ds = oCn.RunProcReturn("exec h_p_Gy_CusBarCodeBill_Cus " + HOrgID.ToString(), "h_p_Gy_CusBarCodeBill_Cus");
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                cmbHCusName.DataSource = null;
                cmbHCusName.Items.Clear();
                MessageBox.Show("获取客户信息失败");
                return;
            }
            cmbHCusName.DataSource = null;
            cmbHCusName.Items.Clear();
            cmbHCusName.DataSource = ds.Tables[0];
            cmbHCusName.DisplayMember = "HName";
            cmbHCusName.ValueMember = "HItemID";
        }
 
        //窗体尺寸变化时
        private void Gy_CusBarCodeBill_KaiBei_LangChao_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_CusBarCodeBill_KaiBei_LangChao_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:
                    //浏览状态
                    ylw.Enabled = true; 
                    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 //已作废
                    { 
                        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:
                    //新增状态
                    ylw.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:
                    //修改状态
                    ylw.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_SaveBill()
        {
            //获取内码
            HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
 
            lblCaption.Focus();
            //生成条码前控制
            if (!Sub_AllowSave())
            {
                return false;
            }
            bc.Enabled = false;
            SaveBarCode();
            return true;
        }
 
        #region  生成条码前控制
        private bool Sub_AllowSave()
        {
            string sHRemark = "";
            //明细表是否为零行
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (!IsNullRow(i))
                {
                    b = true;
                    break;
                }
            }
            if (b == false)
            {
                MessageBox.Show("明细行不存在!", "提示");
                return false;
            }
 
            //日期获取方式
            sDate = dtpHDate.Value.ToShortDateString();
            sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
            sYear4 = ClsPub.isDate(sDate).Year.ToString();
            sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
            sPeriod2 = sPeriod.Substring(sPeriod.Length - 2, 2);
            sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
            sDay = sDay.Substring(sDay.Length - 2, 2);
            //==================================
            switch (sYear)
            {
                case "22":
                    sYear = "N";
                    break;
                case "23":
                    sYear = "P";
                    break;
                case "24":
                    sYear = "Q";
                    break;
                case "25":
                    sYear = "R";
                    break;
                case "26":
                    sYear = "S";
                    break;
                case "27":
                    sYear = "T";
                    break;
                case "28":
                    sYear = "U";
                    break;
                case "29":
                    sYear = "V";
                    break;
                case "30":
                    sYear = "W";
                    break;
                case "31":
                    sYear = "X";
                    break;
                case "32":
                    sYear = "Y";
                    break;
                case "33":
                    sYear = "Z";
                    break;
                default:
                    sYear = "";
                    break;
            }
            if (sYear == "")
            {
                MessageBox.Show("错误的年份!");
                return false;
            }
 
            switch (sPeriod)
            {
                case "01":
                    sPeriod = "1";
                    break;
                case "02":
                    sPeriod = "2";
                    break;
                case "03":
                    sPeriod = "3";
                    break;
                case "04":
                    sPeriod = "4";
                    break;
                case "05":
                    sPeriod = "5";
                    break;
                case "06":
                    sPeriod = "6";
                    break;
                case "07":
                    sPeriod = "7";
                    break;
                case "08":
                    sPeriod = "8";
                    break;
                case "09":
                    sPeriod = "9";
                    break;
                case "10":
                    sPeriod = "A";
                    break;
                case "11":
                    sPeriod = "B";
                    break;
                case "12":
                    sPeriod = "C";
                    break;
                default:
                    sPeriod = "";
                    break;
            }
            if (sPeriod == "")
            {
                MessageBox.Show("错误的月份!");
                return false;
            }
 
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                long HSno = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HSnoCol].Value);                          // 序号
                string HSourceBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillNoCol].Value);         // 源单单号
                long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);                  // 物料内码
                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);                 // 内箱最小包装数
                double HWMinQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[HWMinQtyCol].Value);               // 外箱最小包装数
                string HCusModelName = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelNameCol].Value);   // 客户料号
                string HCode1 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode1Col].Value);                 // 物料类别
                string HCode2 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode2Col].Value);                 // 批次位
                HCode2 = HCode2.ToUpper();
                string HCode3 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value);                 // 版本号
                string HBatchNoNumber = HCode1 + sYear + sPeriod + sDay + HCusModel;                                // 批次生成前缀
                HBatchNoNumber = HBatchNoNumber.ToUpper();
                string HBarCodeType = "";                                                                           // 条码类型
                string HInnerBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HInnerBillNoCol].Value);     // 客户订单号
 
                if (HMaterID != 0)
                {
                    DataSet oDsCheck = oCn.RunProcReturn("exec h_p_Gy_CusBarCodeBill_KaiBeiLC_AddCheck " + HSno.ToString() + ",'" + HSourceBillNo + "'," + HMaterID.ToString() + "," + HSourceQty.ToString() + "," + HQty.ToString() + "," + HMinQty.ToString() + "," + HWMinQty.ToString() + ",'" + HCusModelName + "','" + HCode1 + "','" + HCode2 + "','" + HCode3 + "','" + HBatchNoNumber + "','" + HBarCodeType + "','" + HInnerBillNo + "'", "h_p_Gy_CusBarCodeBill_KaiBeiLC_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
                    {
                        //grdMain.Rows[j].Cells[HBaNoCol].Value = HCode2;
                        //grdMain.Rows[j].Cells[HBatchNoCol].Value = DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HBatchNo"]);
                        //grdMain.Rows[j].Cells[HCode2Col].Value = DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HCode2"]);
 
                        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;
        }
 
        #endregion
 
        #region  写入客户条码档案
        private void SaveBarCode()
        {
            try
            {
                string TM = "";             //条码
                int LSHlen = 4;             //流水号长度
                double HSumQty = 0;         //产品数量
                double HMinQty = 0;         //内箱最小包装数
                int HBQty = 0;              //内箱数
                double HWMinQty = 0;        //外箱最小包装数
                int HWBQty = 0;             //外箱数
                int LSH = 0;                //内箱流水号
                int LWSH = 0;               //外箱流水号
                string LSH2 = "";           //流水号转换成字符
                string HCode1 = "";         //物料类别
                string HCode2 = "";         //批次位
                string HCode3 = "";         //版本号
                string sTMNumber = "";      //外箱条码前缀
                DataSet Ds;
 
                Int64 HEntryID = 0;
                string HBarCode = "";       //条形码 
                string HBarCodeType = "";   //条码类型
                Int64 HMaterID = 0;         //物料ID
                Int64 HUnitID = 0;          //计量单位ID
                Int64 HAuxPropID = 0;       //辅助属性ID
                string HBatchNo = "";       //批次
                double HQty = 0;            //数量
                Int64 HCusID = 0;           //客户ID
                string HCusModelName = "";  //客户料号
                bool HGiveAwayFlag = false; //赠品标记
                string HProduceDate;        //生产日期(保质期用)
                string HExpiryDate;         //保质期至(保质期用)
                bool HISKFPERIOD = false;   //保质期启用标记
                Int64 HBarcodeQtys = 0;     //总托数
                Int64 HBarcodeNo = 0;       //当前托号
                Int64 HSourceInterID = 0;   //源单主ID 
                Int64 HSourceEntryID = 0;   //源单子ID
                string HSourceBillNo = "";  //源单单号 
                string HSourceBillType = "";//源单类型
                string HMTONo = "";         //MTO号
                string HRemark = "";        //备注
                string HInnerBillNo = "";   //客户订单号
                Int64 HSno = 0;             //批次序列号
                string HBoxNo = "";         //批次生成前缀
                string sHBaNo = "";         //界面上输入的批次位
                int HSumBQty = 0;           //同一批生成条码总箱数
                int n = 0;                  //同一批生成条码中的第几条
                pb1.Value = 0;
 
                oCn.BeginTran();
                Application.DoEvents();
                //获取同一批生成条码总箱数
                for (int j = 0; j < grdMain.Rows.Count; j++)
                {
                    if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                    {
                        HSumBQty = HSumBQty + ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value) + ClsPub.isInt(grdMain.Rows[j].Cells[HWBQtyCol].Value);
                        pb1.Maximum = HSumBQty;
                    }
                }
                //生成内箱条码
                for (int j = 0; j < grdMain.Rows.Count; j++)
                {
                    if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                    {
                        string sHSourceBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillNoCol].Value);         // 源单单号
                        long sHMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);                  // 物料内码
                        string sHMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);     // 物料代码
                        string sHCusModelName = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelNameCol].Value);   // 客户料号
                        string sHCode1 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode1Col].Value);                 // 物料类别
                        string sHCode2 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode2Col].Value);                 // 批次位
                        sHCode2 = sHCode2.ToUpper();
                        string HBatchNoNumber = sHCode1 + sYear + sPeriod + sDay + HCusModel;                                // 批次生成前缀
                        HBatchNoNumber = HBatchNoNumber.ToUpper();
 
                        DataSet oDsBatchNo = oCn.RunProcReturn("exec h_p_Gy_CusBarCodeBill_KaiBeiLC_GetBatchNo '" + sHSourceBillNo + "'," + sHMaterID.ToString() + ",'" + sHMaterNumber + "','" + sHCusModelName + "','" + sHCode2 + "','" + HBatchNoNumber + "'", "h_p_Gy_CusBarCodeBill_KaiBeiLC_GetBatchNo");
                        //
                        if (oDsBatchNo == null && oDsBatchNo.Tables[0].Rows.Count == 0)
                        {
                            MessageBox.Show("获取批次失败!");
                            bc.Enabled = true;
                            oCn.RollBack();
                            return;
                        }
                        else if (DBUtility.ClsPub.isStrNull(oDsBatchNo.Tables[0].Rows[0][0]) == "1")
                        {
                            MessageBox.Show(DBUtility.ClsPub.isStrNull(oDsBatchNo.Tables[0].Rows[0]["HRemark"]));
                            bc.Enabled = true;
                            oCn.RollBack();
                            return;
                        }
                        else
                        {
                            grdMain.Rows[j].Cells[HBaNoCol].Value = sHCode2;
                            grdMain.Rows[j].Cells[HBatchNoCol].Value = DBUtility.ClsPub.isStrNull(oDsBatchNo.Tables[0].Rows[0]["HBatchNo"]);
                            grdMain.Rows[j].Cells[HCode2Col].Value = DBUtility.ClsPub.isStrNull(oDsBatchNo.Tables[0].Rows[0]["HCode2"]);
                        }
 
                        HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                        HCode3 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value);
                        //获取最大流水号
                        LSH = 0;
                        Ds = oCn.RunProcReturn("select top 1 HSno from Gy_BarCodeBill_Cus where HBatchNo='" + HBatchNo + "' order by HSno desc", "Gy_BarCodeBill_Cus");
                        if (Ds != null && Ds.Tables[0].Rows.Count != 0)
                        {
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        }
 
                        HBQty = ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value);
                        HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);
                        HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
 
                        for (int i = 0; i < HBQty; i++)
                        {
                            if (HSumQty - HMinQty > 0)
                            {
                                HSumQty = HSumQty - HMinQty;
                            }
                            else
                            {
                                HMinQty = HSumQty;
                            }
                            //
                            LSH = LSH + 1;
                            LSH2 = LSH.ToString();
                            //LSH2 = ConvertToBase(LSH, 34);
                            while (LSH2.Length < LSHlen)  //如果流水号位数小于 LSHlen 前面补0
                            {
                                LSH2 = "0" + LSH2;
                            }
                            //条码编号 = 批次 + 流水号 + 版本号
                            TM = HBatchNo + LSH2 + HCode3;
 
                            HEntryID = j + 1;
                            HBarCode = TM.ToUpper();
                            HBarCodeType = "内箱码";
                            HMaterID = ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                            HUnitID = ClsPub.isLong(grdMain.Rows[j].Cells[HUnitIDCol].Value);
                            HAuxPropID = ClsPub.isLong(grdMain.Rows[j].Cells[HAuxPropIDCol].Value);
                            HQty = HMinQty;
                            HCusID = ClsPub.isLong(cmbHCusName.SelectedValue);
                            HCusModelName = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelNameCol].Value);
                            HGiveAwayFlag = ClsPub.isBool(grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value);
                            HISKFPERIOD = ClsPub.isBool(grdMain.Rows[j].Cells[HISKFPERIODCol].Value);
                            HProduceDate = ClsPub.isStrNull(grdMain.Rows[j].Cells[HProduceDateCol].Value);
                            HExpiryDate = ClsPub.isStrNull(grdMain.Rows[j].Cells[HExpiryDateCol].Value);
                            HBarcodeQtys = HBQty;
                            HBarcodeNo = i + 1;
                            HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[HSourceInterIDCol].Value);
                            HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[HSourceEntryIDCol].Value);
                            HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillNoCol].Value);
                            HSourceBillType = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillTypeCol].Value);
                            HRemark = ClsPub.isStrNull(grdMain.Rows[j].Cells[HRemarkCol].Value);
                            HMTONo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMTONoCol].Value);
                            HInnerBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HInnerBillNoCol].Value);
                            HCode1 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode1Col].Value).ToUpper();
                            HCode2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode2Col].Value).ToUpper();
                            HCode3 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value).ToUpper();
                            HSno = LSH;
                            HBoxNo = HCode1 + sYear + sPeriod + sDay + HCusModel;
                            HBoxNo = HBoxNo.ToUpper();
                            sHBaNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBaNoCol].Value);                        // 界面上输入的批次位
 
                            //客户料号HCusModelName、物料类别HCode1、批次位HCode2、版本号HCode3、批次序列号HSno、批次生成前缀HBoxNo、厂商代码HCusModel
                            //界面上输入的批次位HSupName、36进制批次序列号HSupNumber、客户订单号HInnerBillNo
                            oCn.RunProc("insert into Gy_BarCodeBill_Cus" +
                                    "(HInterID,HEntryID,HBillType,HBarCode,HBarCodeType" +
                                    ",HMaterID,HUnitID,HAuxPropID,HBatchNo,HQty" +
                                    ",HCusID,HCusModel,HCusModelName,HBarCodeDate,HBarCodeStatus" +
                                    ",HGiveAwayFlag,HISKFPERIOD,HEndQty" +
                                    ",HProduceDate,HExpiryDate" +
                                    ",HBarcodeQtys,HBarcodeNo,HPieceQty,HPrintQty" +
                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType " +
                                    ",HStopflag,HUseFlag,HRemark,HSTOCKORGID,HOWNERID" +
                                    ",HMaker,HMakeDate,HStopMan,HWorkLineName,HMTONo" +
                                    ",HKFPeriod,HKFDate,HKFDQDate,HInnerBillNo" +
                                    ",HStatus,HDeleteMan,HSupNumber,HSupName,HCode1" +
                                    ",HCode2,HCode3,HBackDataFlag,HSno,HBoxNo" +
                                    ") values (" + HInterID + "," + HEntryID + ",'','" + HBarCode + "','" + HBarCodeType + "'"
                                    + "," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HAuxPropID.ToString() + ",'" + HBatchNo + "'," + HQty.ToString()
                                    + "," + HCusID.ToString() + ",'" + HCusModel + "','" + HCusModelName + "','" + sDate + "',''"
                                    + "," + DBUtility.ClsPub.BoolToString(HGiveAwayFlag) + "," + DBUtility.ClsPub.BoolToString(HISKFPERIOD) + ",''"
                                    + "," + (HProduceDate == "" ? "NULL" : "'" + HProduceDate + "'") + "," + (HExpiryDate == "" ? "NULL" : "'" + HExpiryDate + "'")
                                    + "," + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + ",1,0"
                                    + "," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "'"
                                    + ",0,'','" + HRemark + "'," + HOrgID.ToString() + "," + HOrgID.ToString()
                                    + ",'" + ClsPub.CurUserName + "',getdate(),'','','" + HMTONo + "'"
                                    + ",0,'','','" + HInnerBillNo + "'"
                                    + ",'','','" + LSH2 + "','" + sHBaNo + "','" + HCode1 + "'"
                                    + ",'" + HCode2 + "','" + HCode3 + "',''," + HSno.ToString() + ",'" + HBoxNo + "')");
                            pb1.Value = n + 1;
                            n = n + 1;
                        }
                    }
                }
 
                //生成外箱条码
                for (int j = 0; j < grdMain.Rows.Count; j++)
                {
                    if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                    {
                        HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                        HCode3 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value);
                        //获取最大流水号
                        //条码前缀 = 供应商代码 + 年 + 月 + 日
                        sTMNumber = HCusModel + sYear4 + sPeriod2 + sDay;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        LWSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
 
                        HWBQty = ClsPub.isInt(grdMain.Rows[j].Cells[HWBQtyCol].Value);
                        HWMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HWMinQtyCol].Value);
                        HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
 
                        int nn = 0;     //本次流水号累计使用个数
                        for (int i = 0; i < HWBQty; i++)
                        {
                            if (HSumQty - HWMinQty > 0)
                            {
                                HSumQty = HSumQty - HWMinQty;
                            }
                            else
                            {
                                HWMinQty = HSumQty;
                            }
                            //
                            LWSH = LWSH + 1;
                            LSH2 = LWSH.ToString();
                            while (LSH2.Length < 5)  //如果流水号位数小于 5 前面补0
                            {
                                LSH2 = "0" + LSH2;
                            }
                            TM = sTMNumber + LSH2;
 
                            HEntryID = j + 1;
                            HBarCode = TM.ToUpper();
                            HBarCodeType = "外箱码";
                            HMaterID = ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                            HUnitID = ClsPub.isLong(grdMain.Rows[j].Cells[HUnitIDCol].Value);
                            HAuxPropID = ClsPub.isLong(grdMain.Rows[j].Cells[HAuxPropIDCol].Value);
                            HQty = HWMinQty;
                            HCusID = ClsPub.isLong(cmbHCusName.SelectedValue);
                            HCusModelName = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelNameCol].Value);
                            HGiveAwayFlag = ClsPub.isBool(grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value);
                            HISKFPERIOD = ClsPub.isBool(grdMain.Rows[j].Cells[HISKFPERIODCol].Value);
                            HProduceDate = ClsPub.isStrNull(grdMain.Rows[j].Cells[HProduceDateCol].Value);
                            HExpiryDate = ClsPub.isStrNull(grdMain.Rows[j].Cells[HExpiryDateCol].Value);
                            HBarcodeQtys = HWBQty;
                            HBarcodeNo = i + 1;
                            HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[HSourceInterIDCol].Value);
                            HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[HSourceEntryIDCol].Value);
                            HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillNoCol].Value);
                            HSourceBillType = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillTypeCol].Value);
                            HRemark = ClsPub.isStrNull(grdMain.Rows[j].Cells[HRemarkCol].Value);
                            HMTONo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMTONoCol].Value);
                            HInnerBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HInnerBillNoCol].Value);
                            HCode1 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode1Col].Value).ToUpper();
                            HCode2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode2Col].Value).ToUpper();
                            HCode3 = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value).ToUpper();
                            HSno = 0;
                            HBoxNo = HCode1 + sYear + sPeriod + sDay + HCusModel;
                            HBoxNo = HBoxNo.ToUpper();
                            sHBaNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBaNoCol].Value);                        // 界面上输入的批次位
 
                            //客户料号HCusModelName、物料类别HCode1、批次位HCode2、版本号HCode3、批次序列号HSno、批次生成前缀HBoxNo、厂商代码HCusModel
                            //界面上输入的批次位HSupName、36进制批次序列号HSupNumber、客户订单号HInnerBillNo
                            oCn.RunProc("insert into Gy_BarCodeBill_Cus" +
                                    "(HInterID,HEntryID,HBillType,HBarCode,HBarCodeType" +
                                    ",HMaterID,HUnitID,HAuxPropID,HBatchNo,HQty" +
                                    ",HCusID,HCusModel,HCusModelName,HBarCodeDate,HBarCodeStatus" +
                                    ",HGiveAwayFlag,HISKFPERIOD,HEndQty" +
                                    ",HProduceDate,HExpiryDate" +
                                    ",HBarcodeQtys,HBarcodeNo,HPieceQty,HPrintQty" +
                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType " +
                                    ",HStopflag,HUseFlag,HRemark,HSTOCKORGID,HOWNERID" +
                                    ",HMaker,HMakeDate,HStopMan,HWorkLineName,HMTONo" +
                                    ",HKFPeriod,HKFDate,HKFDQDate,HInnerBillNo" +
                                    ",HStatus,HDeleteMan,HSupNumber,HSupName,HCode1" +
                                    ",HCode2,HCode3,HBackDataFlag,HSno,HBoxNo" +
                                    ") values (" + HInterID + "," + HEntryID + ",'','" + HBarCode + "','" + HBarCodeType + "'"
                                    + "," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HAuxPropID.ToString() + ",'" + HBatchNo + "'," + HQty.ToString()
                                    + "," + HCusID.ToString() + ",'" + HCusModel + "','" + HCusModelName + "','" + sDate + "',''"
                                    + "," + DBUtility.ClsPub.BoolToString(HGiveAwayFlag) + "," + DBUtility.ClsPub.BoolToString(HISKFPERIOD) + ",''"
                                    + "," + (HProduceDate == "" ? "NULL" : "'" + HProduceDate + "'") + "," + (HExpiryDate == "" ? "NULL" : "'" + HExpiryDate + "'")
                                    + "," + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + ",1,0"
                                    + "," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "'"
                                    + ",0,'','" + HRemark + "'," + HOrgID.ToString() + "," + HOrgID.ToString()
                                    + ",'" + ClsPub.CurUserName + "',getdate(),'','','" + HMTONo + "'"
                                    + ",0,'','','" + HInnerBillNo + "'"
                                    + ",'','','" + LSH2 + "','" + sHBaNo + "','" + HCode1 + "'"
                                    + ",'" + HCode2 + "','" + HCode3 + "',''," + HSno.ToString() + ",'" + HBoxNo + "')");
                            pb1.Value = n + 1;
                            n = n + 1;
                            nn = nn + 1;
                        }
                        //回填流水号信息
                        oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + nn.ToString() + " ");
                    }
                }
                oCn.Commit();
                MessageBox.Show("客户标签生成完毕!");
                tabControl1.SelectedIndex = 1;
            }
            catch (Exception e)
            {
                bc.Enabled = true;
                oCn.RollBack();
                MessageBox.Show("客户标签生成失败!" + e.Message);
            }
        }
 
        #endregion
 
        #region  刷新条码列表
        private void Display()
        {
            //刷新内箱码列表
            DataSet DSet = oCn.RunProcReturn("select * from h_v_Gy_BarCodeBill_CusList where HInterID=" + HInterID.ToString() + " and 条码类型='内箱码' order by HItemID", "h_v_Gy_BarCodeBill_CusList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                //MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdSub.DataSource = DSet.Tables[0].DefaultView;
 
            //刷新外箱码列表
            DataSet DWSet = oCn.RunProcReturn("select * from h_v_Gy_BarCodeBill_CusList where HInterID=" + HInterID.ToString() + " and 条码类型='外箱码' order by HItemID", "h_v_Gy_BarCodeBill_CusList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DWSet == null)
            {
                //MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdList.DataSource = DWSet.Tables[0].DefaultView;
 
            //冻结
            int FrCol = 0;
            string s = "是";
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdSub, this.Name + "grdSub", s, FrCol);
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
            //画线
            GraphLine();
        }
        private void GraphLine()
        {
            int MainIDCol = Fun_GetCol("hmainid");
            int SubIDCol = Fun_GetCol("hsubid");
            int WMainIDCol = Fun_GetCol_w("hmainid");
            int WSubIDCol = Fun_GetCol_w("hsubid");
            string s = "是";
            long n = 0;
            DBUtility.Xt_BaseBillFun.GraphLine(grdSub, MainIDCol, SubIDCol, s, ref n);
            DBUtility.Xt_BaseBillFun.GraphLine(grdList, WMainIDCol, WSubIDCol, s, ref n);
        }
 
        #endregion
 
        #region  将十进制数值转成指定进制数值(num为要转换的十进行数值,nbase为指定进制)
        public string ConvertToBase(int num, int nbase)
        {
            string chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
            if (nbase < 2 || nbase > chars.Length)
                return "";
            int r;
            string newNumber = "";
            while (num >= nbase)
            {
                r = num % nbase;
                newNumber = chars[r] + newNumber;
                num = num / nbase;
            }
            newNumber = chars[num] + newNumber;
            return newNumber;
        }
 
        #endregion
 
        #endregion
 
 
        #region 窗体处理方法
        //初始化GRID
        private void initGrid()
        {
            grdMain.RowCount = 0;
            grdMain.ColumnCount = 46;                       //总列数
            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[HCusModelNameCol].HeaderText = "客户料号";
            grdMain.Columns[HUnitIDCol].HeaderText = "计量单位ID";
            grdMain.Columns[HUnitNumberCol].HeaderText = "计量单位代码";
            grdMain.Columns[HUnitNameCol].HeaderText = "计量单位名称";
            grdMain.Columns[HAuxPropIDCol].HeaderText = "辅助属性ID";
            grdMain.Columns[HAuxPropNumberCol].HeaderText = "辅助属性代码";
            grdMain.Columns[HAuxPropNameCol].HeaderText = "辅助属性名称";
            grdMain.Columns[HBatchManagerCol].HeaderText = "是否启用批次";
            grdMain.Columns[HBatchNoCol].HeaderText = "批号";
            grdMain.Columns[HGiveAwayFlagCol].HeaderText = "是否赠品";
            grdMain.Columns[HQtyCol].HeaderText = "数量";
            grdMain.Columns[HMinQtyCol].HeaderText = "内箱最小包装数";
            grdMain.Columns[HBQtyCol].HeaderText = "内箱箱数";
            grdMain.Columns[HWMinQtyCol].HeaderText = "外箱最小包装数";
            grdMain.Columns[HWBQtyCol].HeaderText = "外箱箱数";
            grdMain.Columns[HCusIDCol].HeaderText = "客户ID";
            grdMain.Columns[HCusNumberCol].HeaderText = "客户代码";
            grdMain.Columns[HCusNameCol].HeaderText = "客户";
            grdMain.Columns[HProduceDateCol].HeaderText = "生产日期";
            grdMain.Columns[HExpiryDateCol].HeaderText = "有效期至";
            grdMain.Columns[HISKFPERIODCol].HeaderText = "是否启用保质期";
            grdMain.Columns[HEXPUNITCol].HeaderText = "保质期单位";
            grdMain.Columns[HEXPPERIODCol].HeaderText = "保质期";
            grdMain.Columns[HRemarkCol].HeaderText = "备注";
            grdMain.Columns[HMTONoCol].HeaderText = "计划跟踪号";
            grdMain.Columns[HCode1Col].HeaderText = "物料类别";
            grdMain.Columns[HCode2Col].HeaderText = "批次位";
            grdMain.Columns[HCode3Col].HeaderText = "版本号";
            grdMain.Columns[HInnerBillNoCol].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[HUnitIDCol].Visible = false;
            grdMain.Columns[HUnitNumberCol].Visible = false;
            grdMain.Columns[HUnitNameCol].Visible = false;
            grdMain.Columns[HAuxPropIDCol].Visible = false;
            grdMain.Columns[HAuxPropNumberCol].Visible = false;
            grdMain.Columns[HAuxPropNameCol].Visible = false;
            grdMain.Columns[HBatchManagerCol].Visible = false;
            grdMain.Columns[HGiveAwayFlagCol].Visible = false;
            grdMain.Columns[HProduceDateCol].Visible = false;
            grdMain.Columns[HExpiryDateCol].Visible = false;
            grdMain.Columns[HCusIDCol].Visible = false;
            grdMain.Columns[HCusNumberCol].Visible = false;
            grdMain.Columns[HCusNameCol].Visible = false;
            grdMain.Columns[HSourceInterIDCol].Visible = false;
            grdMain.Columns[HSourceEntryIDCol].Visible = false;
            grdMain.Columns[HSourceBillNoCol].Visible = false;
            grdMain.Columns[HSourceBillTypeCol].Visible = false;
            grdMain.Columns[HInitQtyCol].Visible = false;
            grdMain.Columns[HMTONoCol].Visible = false;
            grdMain.Columns[HISKFPERIODCol].Visible = false;
            grdMain.Columns[HEXPUNITCol].Visible = false;
            grdMain.Columns[HEXPPERIODCol].Visible = false;
            grdMain.Columns[HLSHCol].Visible = false;
            grdMain.Columns[HBaNoCol].Visible = false;
 
            //设置可编辑列
            string sAllowCol =  HQtyCol.ToString()+
                                "," + HMinQtyCol.ToString() +
                                "," + HWMinQtyCol.ToString() +
                                //"," + HMaterNumberCol.ToString() +
                                "," + HAuxPropNumberCol.ToString() +
                                "," + HUnitNumberCol.ToString() +
                                //"," + HCode1Col.ToString() +
                                //"," + HCode2Col.ToString() +
                                //"," + HCode3Col.ToString() +
                                "," + HInnerBillNoCol.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);
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.initGridList(grdSub, this.Name + "grdSub");
            DBUtility.Xt_BaseBillFun.initGridList(grdList, this.Name + "grdList");
        }
 
        //公式重算
        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;
 
                //外箱数列=数量/外箱最小包装数
                double sWMoney = 0;
                if (ClsPub.isDoule(grdMain.Rows[sRow].Cells[HWMinQtyCol].Value) == 0)
                {
                    sWMoney = 0;
                }
                else
                {
                    sWMoney = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) / ClsPub.isDoule(grdMain.Rows[sRow].Cells[HWMinQtyCol].Value);
                }
                sWMoney = Math.Ceiling(sWMoney);
                grdMain.Rows[sRow].Cells[HWBQtyCol].Value = sWMoney;
            }
            else 
            {
 
            }
        }
 
        //是否是空行
        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)
        {
            string sWhere = "";
            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;
            }
            oSumGrid.EditStatus = true;
 
            switch (sKeyCode)
            {
                case 118:          //F7
                    {
                        switch (sCol)
                        {
                            case HMaterNumberCol:
                                oMater.WherePart = "";
                                sWhere = " and HUSEORGID = " + HOrgID;
                                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[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 = "";
                                        }
                                        GetCusMatNo(2);
                                        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 HCusNumberCol:
                                BLL.ClsBaseSelect_InterFace.SetGridByCus(grdMain, sRow, HCusIDCol, HCusNumberCol, HCusNameCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HCusNumberCol].Value);
                                break;
 
                            case HAuxPropNumberCol:
                                oProperty.WherePart = "";
                                sWhere = " and HMaterNumber = '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[HMaterNumberCol].Value) + "'";
 
                                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 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 == HWMinQtyCol)
            {
                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 选源单返回信息     按放大镜图标返回
 
        private void cmdSourceBillNo_Click(object sender, EventArgs e)
        {
            if (cmbSourceBillType.Text.Trim() == "生产订单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_ICMOBillList_CusBarCodeBill oIF_ICMOBillList = new DAL.Cls_S_IF_ICMOBillList_CusBarCodeBill();
                if (oIF_ICMOBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ICMOBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "生产汇报单")
            {
                string sWhere = " and HOrgID =" + HOrgID.ToString();
                DAL.Cls_S_IF_ICMOReportBillList_CusBarCodeBill oIF_ICMOReportBillList = new DAL.Cls_S_IF_ICMOReportBillList_CusBarCodeBill();
                if (oIF_ICMOReportBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
                }
            }
        }
 
        private void FillSelectData(List<DBUtility.BillSelect> oList)
        {
            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("select * from h_v_Sc_ICMOBillList_CusBarCodeBill where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_Sc_ICMOBillList_CusBarCodeBill");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                    GetCusMatNo(1);
                }
                //生产汇报单
                else if (oSelectRow.BillType == "3711")
                {
                    grdMain.Rows.Add();
                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_Sc_ICMOReportList_CusBarCodeBill where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_Sc_ICMOReportList_CusBarCodeBill");
                    //写入信息
                    Sub_WriteInForm1(Ds.Tables[0], i);
                    GetCusMatNo(1);
                }
            }
            //
            oSumGrid.Changelock = false;
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        //根据TABLE写入界面
        private void Sub_WriteInForm1(DataTable oTable, int i)
        {
            //加载表体
            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[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[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[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[HBatchManagerCol].Value = oTable.Rows[0]["备注"].ToString();
            grdMain.Rows[i].Cells[HCode1Col].Value = oTable.Rows[0]["物料类别"].ToString();
            grdMain.Rows[i].Cells[HCode3Col].Value = oTable.Rows[0]["版本号"].ToString();
            grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
            grdMain.Rows[i].Cells[HSourceInterIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            grdMain.Rows[i].Cells[HSourceEntryIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HSourceBillTypeCol].Value = oTable.Rows[0]["HBillType"].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();
            grdMain.Rows[i].Cells[HInnerBillNoCol].Value = oTable.Rows[0]["销售订单编号"].ToString();
            //--
            //设置可编辑列
            string sAllowCol = HQtyCol.ToString() +
                                "," + HMinQtyCol.ToString() +
                                "," + HWMinQtyCol.ToString() +
                                "," + HAuxPropNumberCol.ToString() +
                                //"," + HCode1Col.ToString() +
                                //"," + HCode2Col.ToString() +
                                //"," + HCode3Col.ToString() +
                                "," + HInnerBillNoCol.ToString() +
                                "," + HRemarkCol.ToString();
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 0;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
 
        #endregion
 
 
        #region 选源单返回信息     按回车键返回
        private void txtHSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)//回车带出源单信息
            {
                if (txtHSourceBillNo.Text.Length < 4)
                {
                    MessageBox.Show("请输入4位以上数据!");
                    return;
                }
                //根据源单类型 和源单号 获取信息
                if (cmbSourceBillType.Text.Trim() == "生产订单")
                {
                    DAL.Cls_S_IF_ICMOBillList_CusBarCodeBill oIF_ICMOBillList = new DAL.Cls_S_IF_ICMOBillList_CusBarCodeBill();
                    if (oIF_ICMOBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + HOrgID.ToString()))  //选择原单
                    {
                        FillSelectData(oIF_ICMOBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else if (cmbSourceBillType.Text.Trim() == "生产汇报单")
                {
                    DAL.Cls_S_IF_ICMOReportBillList_CusBarCodeBill oIF_ICMOReportBillList = new DAL.Cls_S_IF_ICMOReportBillList_CusBarCodeBill();
                    if (oIF_ICMOReportBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + HOrgID.ToString()))  //选择原单
                    {
                        FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
                        txtHSourceBillNo.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("所选源单类型,不支持此功能!");
                    return;
                }
 
            }
        }
 
        #endregion
 
 
        #region  //打印设置
 
        GridppReport Report;
 
        #region 内箱预览、打印
 
        #region 内箱预览
        private void yl_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (grdSub.Rows.Count < 1)
            {
                MessageBox.Show("内箱条码未生成,请先生成条码后再预览!");
                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);
            }
        }
 
        #endregion
 
        #region 内箱打印
        private void dy_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (grdSub.Rows.Count < 1)
            {
                MessageBox.Show("内箱条码未生成,请先生成条码后再打印!");
                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);
            }
        }
 
        #endregion
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdSub.Rows.Count; i++)
            {
                grdSub.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[HRemark2Col].Value);
            }
            catch (Exception e)
            {
                MessageBox.Show("内箱条码打印失败!表头:" + e.Message);
            }
        }
 
        //填入单据表体信息
        private void ReportFetchRecordByDataTable()
        {
            try
            {
                DataTable ds = new DataTable();
                BLL.Utility.FillRecordToReport_Sel(Report, grdSub, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("内箱条码打印失败!表体:" + e.Message);
            }
        }
 
        //打印结束后回填条码打印次数
        private void ReportPrintEnd()
        {
            try
            {
                oCn.RunProc("update Gy_BarCodeBill_Cus set HPrintQty=isnull(HPrintQty,0)+1 where HBarCodeType='内箱码' and HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
            }
            catch (Exception e)
            {
                MessageBox.Show("内箱条码打印失败!打印结束 :" + e.Message);
            }
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdSub);
        }
 
        #endregion
 
        #region 外箱预览、打印
 
        #region 外箱预览
        private void ylw_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (grdList.Rows.Count < 1)
            {
                MessageBox.Show("外箱条码未生成,请先生成条码后再预览!");
                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_w(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
 
        #endregion
 
        #region 外箱打印
        private void dyw_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (grdList.Rows.Count < 1)
            {
                MessageBox.Show("外箱条码未生成,请先生成条码后再打印!");
                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_w(oFrm.sOpenTmp);
                Report.Print(true);
                Thread.Sleep(1000);
            }
        }
 
        #endregion
 
 
        private void Sub_SetReport_w(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_w);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable_w);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd_w);
        }
        //填入单据表头信息
        private void ReportBeforePostRecord_w()// 
        {
            try
            {
                //Report.FieldByName("备注").AsString = ClsPub.isStrNull(grdList.Rows[CurRows].Cells[HRemark2Col].Value);
            }
            catch (Exception e)
            {
                MessageBox.Show("外箱条码打印失败!表头:" + e.Message);
            }
        }
 
        //填入单据表体信息
        private void ReportFetchRecordByDataTable_w()
        {
            try
            {
                DataTable ds = new DataTable();
                BLL.Utility.FillRecordToReport_Sel(Report, grdList, ds, Fun_GetCol_w("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("外箱条码打印失败!表体:" + e.Message);
            }
        }
 
        //打印结束后回填条码打印次数
        private void ReportPrintEnd_w()
        {
            try
            {
                oCn.RunProc("update Gy_BarCodeBill_Cus set HPrintQty=isnull(HPrintQty,0)+1 where HBarCodeType='外箱码' and HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
            }
            catch (Exception e)
            {
                MessageBox.Show("外箱条码打印失败!打印结束 :" + e.Message);
            }
        }
 
        private Int32 Fun_GetCol_w(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
        }
 
        #endregion
 
        #endregion
 
        #region 获取客户料号
        private void GetCusMatNo(int num)
        {
            Int64 HCusID = ClsPub.isLong(cmbHCusName.SelectedValue);   //客户ID
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value);  // 物料ID
 
                if (HMaterID != 0)
                {
                    DataSet ds = oCn.RunProcReturn("exec h_p_Gy_CusBarCodeBill_CusMatNo " + num.ToString() + "," + HCusID.ToString() + "," + HMaterID.ToString(), "h_p_Gy_CusBarCodeBill_CusMatNo");
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                        grdMain.Rows[j].Cells[HCusModelNameCol].Value = "";
                    }
                    else
                    {
                        grdMain.Rows[j].Cells[HCusModelNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HCusRelationNumber"]);
                        if (num == 2)
                        {
                            grdMain.Rows[j].Cells[HCode1Col].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HCode1"]);
                            grdMain.Rows[j].Cells[HCode3Col].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HCode3"]);
                        }
                    }
                }
            }
        }
 
        #endregion
 
 
        #region 选择客户
        private void cmbHCusName_TextChanged(object sender, EventArgs e)
        {
            GetCusMatNo(1);
        }
 
        #endregion
 
 
        #region 选择组织
        private void cmbHOrgID_SelectionChangeCommitted(object sender, EventArgs e)
        {
            HOrgID = ClsPub.isLong(cmbHOrgID.SelectedValue);
            //加载客户信息
            Sub_AddHCusNameList();
            //清空初始化列表
            initGrid();
            grdMain.Columns[HBillNoCol].ReadOnly = false;
        }
 
 
 
        #endregion
 
 
 
    }
}