智云外网版WMS\MES\SCM(作废)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
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 SCM
{
    public partial class Gy_BarCodeBill_Cus : Form
    {
        public Gy_BarCodeBill_Cus()
        {
            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 HMaterIDCol = 5;
        public const Int16 HCusModelCol = 6;
        public const Int16 HCusModelNameCol = 7;
        public const Int16 HCode1Col = 8;
        public const Int16 HSupNumberCol = 9;
        public const Int16 HSupNameCol = 10;
        public const Int16 HCode2Col = 11;
        public const Int16 HWorkLineNameCol = 12;
        public const Int16 HBarCodeDateCol = 13;
        public const Int16 HCode3Col = 14;
        public const Int16 HBackDataFlagCol = 15;
        public const Int16 HQtyCol = 16;
        public const Int16 HMinQtyCol = 17;
        public const Int16 HBQtyCol = 18;
        public const Int16 HDateCol = 19; 
        public const Int16 HinitQtyCol = 20;
        public const Int16 HRemarkCol = 21;
        public const Int16 HBillTypeCol = 22;
        public const Int16 HLSSnoCol = 23;
        public const Int16 HBoxNoCol = 24;
 
        public Int16 HSelectCol = 0;
        public Int16 HSno2Col = 1;
        public Int16 HTMCol = 2;
        public Int16 HMaterID2Col = 3;
        public Int16 HCusModel2Col = 4;
        public Int16 HCusModelName2Col = 5;
        public Int16 HCode1_SecCol = 6;
        public Int16 HSupNumber2Col = 7;
        public Int16 HSupName2Col = 8;
        public Int16 HCode2_SecCol = 9;
        public Int16 HWorkLineName2Col = 10;
        public Int16 HBarCodeDate2Col = 11;
        public Int16 HCode3_SecCol = 12;
        public Int16 HBackDataFlag2Col = 13;
        public Int16 HQty2Col = 14;
        public Int16 HWeiCol = 15;
        public Int16 HPrintCol = 16;
        public Int16 HDate2Col = 17;
        public Int16 HBeginDate2Col = 18;
        public Int16 HEndDate2Col = 19;
        public Int16 HRemark2Col = 20;
        public Int16 HBarCodeType2Col = 21;
        public  Int16 HLSSno2Col = 22;
        public  Int16 HBoxNo2Col = 23;
        //
        public  string ModName = "85";
        public  string ModCaption = "条码生成";
        public bool BillChange;   //
 
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
        public Int64 KeyID;
        public bool  grdStatus;
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        public int selectRow = 0;
        public int selectRow2 = 0;
        public Int64 HInterID = 0;      //内码
        public Int64 HOrgID = -1;
        public string HOrgNumber = "";
        public string CampanyName = ""; //客户定制化名称
        //-------------------------------------------------------------------------
        #region 固定代码
         
        //清空界面
        public void Sub_ClearBill()
        {
            DataSet Ds1;
            ////表体清空
            //grdMain.Rows.Clear();
            //grdSub.Rows.Clear();
            txtHGroupID.Text = "";
            txtHCaseNo.Text = "";
            cmbHBarCodeType.Items.Clear();
            cmbSourceBillType.Items.Clear();
 
            
            //
            //DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
 
            Ds1 = oWeb.getDataSetBySQL("select * from Xt_ORGANIZATIONS with(nolock) where HItemID=" + ClsPub1.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"]);
            }
            //
            dtpHDate.Value = DateTime.Today;
            txtHMaker.Text = ClsPub.CurUserName;
            txtHMakeDate.Text = "";
            txtHChecker.Text = "";
            txtHCheckDate.Text = "";
            txtHCloseMan.Text = "";
            txtHCloseDate.Text = "";
            txtHDeleteMan.Text = "";
            txtHDeleteDate.Text = "";
            txtHUpDater.Text = "";
            txtHUpDateDate.Text = "";
            initGrid();
            grdList.DataSource = null;
        }
 
        //保存列宽
        private void bclk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.SaveGrid(grdSub, this.Name + "grdSub");
            DBUtility.Xt_BaseBillFun.SaveGrid(grdList, this.Name + "grdList");
        }
 
        //默认列宽
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdSub, this.Name + "grdSub");
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdList, this.Name + "grdList");
        }
 
        //增行按钮  
        private void AddRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
        }
 
        //删行按纽  
        private void DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
 
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
            this.Sub_SaveBill();
            Display();
        }
 
        //重置按纽
        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_BarCodeBill_Cus_Paint(object sender, PaintEventArgs e)//画线
        {
            //Graphics g = this.panel2.CreateGraphics();
            //Pen p = new Pen(Color.Gray);
            //p.Width = 1;
            //g.DrawLine(p, new Point(txtHMaker.Left, txtHMaker.Top + txtHMaker.Height), new Point(txtHMaker.Left + txtHMaker.Width, txtHMaker.Top + txtHMaker.Height));
            //g.DrawLine(p, new Point(txtHMakeDate.Left, txtHMakeDate.Top + txtHMakeDate.Height), new Point(txtHMakeDate.Left + txtHMakeDate.Width, txtHMakeDate.Top + txtHMakeDate.Height));
            ////
            //g.DrawLine(p, new Point(txtHChecker.Left, txtHChecker.Top + txtHChecker.Height), new Point(txtHChecker.Left + txtHChecker.Width, txtHChecker.Top + txtHChecker.Height));
            //g.DrawLine(p, new Point(txtHCheckDate.Left, txtHCheckDate.Top + txtHCheckDate.Height), new Point(txtHCheckDate.Left + txtHCheckDate.Width, txtHCheckDate.Top + txtHCheckDate.Height));
            ////
            //g.DrawLine(p, new Point(txtHCloseMan.Left, txtHCloseMan.Top + txtHCloseMan.Height), new Point(txtHCloseMan.Left + txtHCloseMan.Width, txtHCloseMan.Top + txtHCloseMan.Height));
            //g.DrawLine(p, new Point(txtHCloseDate.Left, txtHCloseDate.Top + txtHCloseDate.Height), new Point(txtHCloseDate.Left + txtHCloseDate.Width, txtHCloseDate.Top + txtHCloseDate.Height));
            ////
            //g.DrawLine(p, new Point(this.txtHDeleteMan.Left, txtHDeleteMan.Top + txtHDeleteMan.Height), new Point(txtHDeleteMan.Left + txtHDeleteMan.Width, txtHDeleteMan.Top + txtHDeleteMan.Height));
            //g.DrawLine(p, new Point(txtHDeleteDate.Left, txtHDeleteDate.Top + txtHDeleteDate.Height), new Point(txtHDeleteDate.Left + txtHDeleteDate.Width, txtHDeleteDate.Top + txtHDeleteDate.Height));
            ////
            //g.DrawLine(p, new Point(this.txtHUpDater.Left, txtHUpDater.Top + txtHUpDater.Height), new Point(txtHUpDater.Left + txtHUpDater.Width, txtHUpDater.Top + txtHUpDater.Height));
            //g.DrawLine(p, new Point(txtHUpDateDate.Left, txtHUpDateDate.Top + txtHUpDateDate.Height), new Point(txtHUpDateDate.Left + txtHUpDateDate.Width, txtHUpDateDate.Top + txtHUpDateDate.Height));
            ////控件位置设置
 
        }
 
        //控件位置
        private void Sub_ControlLocation()
        {
            //gbUp.Width = P1.Width - 20;
            //gbUp.Left = 10;
            //gbUp.Height = P1.Height - 35;
            //gbUp.Top = 30;
        }
 
        //窗体加载
        private void Gy_BarCodeBill_Cus_Load(object sender, EventArgs e)
        {
            //设置动态URL
            oWeb.Url = SCM.ClsPub1.WEBSURL;
            //
            //打印初始化   
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            this.Text = ModCaption;
            this.lblCaption.Text = ModCaption;
            //加载组织信息
            Sub_AddOrdList();
            //加载工厂代码信息
            Sub_AddWorksNumberList();
            cmbHBarCodeType.SelectedIndex = 0;
        }
 
        //加载组织信息
        private void Sub_AddOrdList()
        {
            DataSet ds;
            ds = oWeb.get_ORGANIZATIONSList();
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("获取组织失败");
                return;
            }
            cmbHOrgID.Items.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                cmbHOrgID.Items.Add(DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HName"]));
            }
        }
 
        //加载工厂代码信息
        private void Sub_AddWorksNumberList()
        {
            ////获取系统参数  客户定制化名称
            //DataSet Ds = oWeb.getDataSetBySQL("select HValue from Xt_SystemParameter with(nolock) where HKey='WMS_CampanyName'", "Xt_SystemParameter", ref DBUtility.ClsPub.sExeReturnInfo);
            //if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            //{
            //    MessageBox.Show("获取系统参数失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示");
            //    return;
            //}
            //else
            //{
            //    CampanyName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HValue"]);
            //}
 
            //cmbHWorksNumber.Items.Clear();
            //if (CampanyName == "飞龙") //系统参数  客户定制化名称
            //{
            //    cmbHWorksNumber.Items.Add("ZL");
            //    cmbHWorksNumber.Items.Add("ST1");
            //    cmbHWorksNumber.Items.Add("ST2");
            //    cmbHWorksNumber.Items.Add("ST3");
            //    cmbHWorksNumber.Items.Add("ST4");
            //    cmbHWorksNumber.Items.Add("ST5");
            //    cmbHWorksNumber.Items.Add("ST6");
            //    cmbHWorksNumber.Items.Add("SQ");
            //    cmbHWorksNumber.Items.Add("MQ");
            //    cmbHWorksNumber.SelectedIndex = 0;
            //}
            //else
            //{
            //    cmbHWorksNumber.Items.Add("");
            //}
        }
 
        //窗体尺寸变化时
        private void Gy_BarCodeBill_Cus_Resize(object sender, EventArgs e)
        {
            //Sub_ControlLocation();
        }
 
        //根据编辑状态 设置 控件是否允许录入    
        private void Sub_LrtextStatus(bool TextEnabled)
        {
            if (TextEnabled == true)
            {
                //控件全部有效
                gbUp.Enabled = true;
                grdMain.BackColor = ClsPub.EditColor;
            }
            else
            {   //控件全部无效
                gbUp.Enabled = false;
                grdMain.BackColor = ClsPub.ViewColor;
            }
        }
 
        //timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            Sub_ControlLocation();
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            {
                //this.Sub_ShowBill();
            }
            else
            {
                this.Sub_AddBill();
            }
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        //窗体卸载
        private void Gy_BarCodeBill_Cus_FormClosing(object sender, FormClosingEventArgs e)
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        //TOOLBAR状态  按钮是否灰度
        public void Sub_OperStatus()
        {
            switch (BillStatus)
            {
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_View:
                    //浏览状态
                    yl.Enabled = true;  
                    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 //已作废
                    {  
                        bc.Enabled = false;
                        cz.Enabled = false; 
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Deleted.jpg");
                        //
                    }
                    Sub_LrtextStatus(false);
                    grdStatus = false;
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew:
                    //新增状态
                    yl.Enabled = true;  
                    bc.Enabled = true;
                    cz.Enabled = true; 
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true; 
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify:
                    //修改状态
                    yl.Enabled = true;  
                    bc.Enabled = true;
                    cz.Enabled = true; 
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true; 
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
            }
 
        }
 
        #endregion 
 
        #region  读写类
 
        //单据完整性判断          未完成
        private bool Sub_AllowSave()
        {
            ////必输项目是否为空
            //if (txtHDeptID.Tag.ToString().Trim() == "0")
            //{
            //    MessageBox.Show("生产车间没有选择!", "提示");
            //    return false;
            //}
            //if (txtHGroupID.Tag.ToString().Trim() == "0")
            //{
            //    MessageBox.Show("班组没有选择!", "提示");
            //    return false;
            //}
            //单据号是否重复
            //if (BillNew.IsExistBillNo(ref ClsPub.sExeReturnInfo, txtHBillNo.Text.Trim(), BillStatus, BillOld.omodel.HInterID))
            //{
            //    MessageBox.Show("单据号重复!", "提示");
            //    return false;
            //}
            //明细表是否为零行
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HCusModelCol].Value) !="")
                {
                    b = true;
                    break;
                }
            }
            if (b == false)
            {
                MessageBox.Show("明细行不存在!", "提示");
                return false;
            }
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                if (ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelCol].Value) != "" && (ClsPub.isStrNull(grdMain.Rows[j].Cells[HWorkLineNameCol].Value) == "" || ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value) == 0 || ClsPub.isDoule(grdMain.Rows[j].Cells[HBQtyCol].Value) == 0))
                {
                    MessageBox.Show(" 第" + ClsPub.isLong(grdMain.Rows[j].Cells[HSnoCol].Value) + "行,物料:" + ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelCol].Value) + " ,中存在数量、最小包装数、箱数为 0,不允许生成条码!");
                    return false;
                }
                
 
            }
            
            return true;
        }
 
        private bool BarCodeCheckAuxPropID(Int64 sHMaterID)
        {
            //判断CLOUD物料辅助属性表里该物料是否启用了物料属性(1为启用)
            //DataSet DS = oWeb.getDataSetBySQL("exec h_p_Gy_BarCodeCheckAuxPropID_CLD " + sHMaterID, "h_p_Gy_BarCodeCheckAuxPropID_CLD", ref DBUtility.ClsPub.sExeReturnInfo);
            ////
            //if (DS == null || DS.Tables[0].Rows.Count == 0)
            //{
            //    return false;
            //}
            //else if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["FISENABLE"]) == "1")
            //{
            //    return true;
            //}
 
            return false;
        }
 
 
        //保存单据
        private bool Sub_SaveBill()
        {
            //获取内码
            if (!oWeb.get_MaxBillID(ModName, ref HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
            {
                MessageBox.Show("获取内码失败,请重新点击生成按钮生成条码!");
                return false;
            } 
            //获取组织信息
            HOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            HOrgNumber = oWeb.get_ORGANIZATIONSNOByName(cmbHOrgID.Text);
            if (HOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return false;
            }
            lblCaption.Focus();
            if (!Sub_AllowSave())//单据完整性判断
            {
                return false;
            }
            bc.Enabled = false;
            SaveBarCode();
            return true;
        }
        const string X34 = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
 
        //34进制 
        private string set_SNoBy10To34Type(int iSno)
        {  
            var a = X34.Length;
            //if(iSno==35)
            //{
            //    iSno = iSno;
            //}
            string Result = "";
            while (iSno >= 34)
            {
                Result = X34[(iSno % 34) == 0 ? 0 : (iSno % 34) ] + Result;
                iSno /= 34;
            }
            if (iSno >= 0) 
                Result = X34[iSno] + Result;
 
            return Result;
        }
 
        //生成条码
        private void SaveBarCode()
        {
            try
            {
                grdSub.Rows.Clear();
                int LSHlen = 4;             //流水号长度
                int SumLen = 10;            //总长度
                string TM = "";             //条码
                string HNumber = "";        //物料代码
                double HSumQty = 0;         //产品数量
                double HMinQty = 0;         //最小包装数
                int HBQty = 0;              //箱数
                double HQty = 0;            //数量
                string WeiShu = "";         //尾数
                int LSH = 0;                //流水号
                string LSH2 = "";           //流水号转换成字符
                string sDate = "";          //日期
                string sYear = "";          //年
                string sPeriod = "";        //月
                string sDay = "";           //日
                string HBatchNo = "";       //批次
                int k = 0;
                int n = 0;                  //同一批生成条码中的第几条
                string HJiaYe = "";         //注液代码
                string HGroupNumber = "";   //班组代码
                string sTMNumber = "";      //条码自定义前缀
                string sTMNumber_b = "";      //条码自定义后缀
                string sSeOrderNo = "";     // 销售订单号  
                ///////////////////////////////////////////////////////////
                string sCusModel = "";
                string sSupNumber = "";
                string sLineNumber = "";
                string sCode1 = "";
                string sCode2 = "";
                string sCode3 = "";
                string sBarCodeDate = "";
                string sBackDataFlag = "";
                DataSet Ds;
                pb1.Value = 0;
                for (int j = 0; j < grdMain.Rows.Count; j++)
                {
                    Application.DoEvents();
                    if (ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelCol].Value) != "")
                    {
                        sCusModel = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusModelCol].Value);  //客户零件号
                        sSupNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSupNumberCol].Value);  // 
                        sLineNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HWorkLineNameCol].Value);  // 
                        sBackDataFlag = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBackDataFlagCol].Value);  // 
                        sCode1 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode1Col].Value);  // 
                        sCode2 = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode2Col].Value);  // 
                        sCode3= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCode3Col].Value);  // 
                        sDate = dtpHDate.Value.ToShortDateString();
                        sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                        sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                        sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                        sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                        sDay = sDay.Substring(sDay.Length - 2, 2);
 
                        //================================== 
                        //条码前缀 = 零件号17 + 扩展位1 2 + 供应商编码7 + 扩展位2 3+ 产线1 + 年00 + 月00 + 日00 + 扩展位3 4 + 追溯标识 
                        sCusModel = (sCusModel + "*****************").Substring(0, 17);
                        sSupNumber = (sSupNumber + "*******").Substring(0, 7);
                        sTMNumber = sCusModel + sCode1 + sSupNumber + sCode2 + sLineNumber  + sYear + sPeriod + sDay ;
                        sTMNumber_b =  sCode3 + sBackDataFlag;
                        Ds = oWeb.getDataSetBySQL("exec h_p_WMS_GetMaxNo_Cus  '" + sTMNumber + sTMNumber_b + "'", "h_p_WMS_GetMaxNo_Cus", ref DBUtility.ClsPub.sExeReturnInfo);//获取最大流水号
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
 
                        HBQty = 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);
                        n = 0;
                        pb1.Value = 0;
                        pb1.Maximum = HBQty;
                        //
                        string[] sSQLNoMul = new string[ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value)];
                        int nn = 0;
                        //
                        for (int i = k; i < HBQty; i++)  //从K到总包数, 是累加的方式
                        {
                            Application.DoEvents();
                            pb1.Value = i;
                            Application.DoEvents();
                            if (HSumQty - HMinQty > 0)
                            {
                                WeiShu = "";
                                HSumQty = HSumQty - HMinQty;
                            }
                            else
                            {
                                if (HSumQty == HMinQty)
                                {
                                    WeiShu = "";
                                }
                                else
                                {
                                    WeiShu = "尾数";
                                }
                                HMinQty = HSumQty;
                            }
                            LSH = LSH + 1;
                            LSH2 = set_SNoBy10To34Type(LSH);
                            while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                            {
                                LSH2 = "0" + LSH2;
                            } 
 
                            TM = sTMNumber + LSH2 + sTMNumber_b;
 
                            if (i + 1 > grdSub.Rows.Count)
                            {
                                grdSub.RowCount = grdSub.RowCount + 1;
                            }
                            grdSub.Rows[i].Cells[HSno2Col].Value = ClsPub.isStrNull(i + 1);
                            if (TM.Trim() == "")
                            {
                                MessageBox.Show("条形码不能为空,不能生成条码!");
                                return;
                            }
                            grdSub.Rows[i].Cells[HTMCol].Value = TM;  
                            grdSub.Rows[i].Cells[HQty2Col].Value = HMinQty;
                            grdSub.Rows[i].Cells[HMaterID2Col].Value = grdMain.Rows[j].Cells[HMaterIDCol].Value;
                            grdSub.Rows[i].Cells[HLSSno2Col].Value = LSH2;
                            grdSub.Rows[i].Cells[HCusModel2Col].Value = grdMain.Rows[j].Cells[HCusModelCol].Value;
                            grdSub.Rows[i].Cells[HCusModelName2Col].Value = grdMain.Rows[j].Cells[HCusModelNameCol].Value;
                            grdSub.Rows[i].Cells[HCode1_SecCol].Value = grdMain.Rows[j].Cells[HCode1Col].Value;
                            grdSub.Rows[i].Cells[HSupNumber2Col].Value = grdMain.Rows[j].Cells[HSupNumberCol].Value;
                            grdSub.Rows[i].Cells[HSupName2Col].Value = grdMain.Rows[j].Cells[HSupNameCol].Value;
                            grdSub.Rows[i].Cells[HCode2_SecCol].Value = grdMain.Rows[j].Cells[HCode2Col].Value;
                            grdSub.Rows[i].Cells[HWorkLineName2Col].Value = grdMain.Rows[j].Cells[HWorkLineNameCol].Value;
                            grdSub.Rows[i].Cells[HCode3_SecCol].Value = grdMain.Rows[j].Cells[HCode3Col].Value;
                            grdSub.Rows[i].Cells[HBarCodeDate2Col].Value = grdMain.Rows[j].Cells[HBarCodeDateCol].Value;
                            grdSub.Rows[i].Cells[HBackDataFlag2Col].Value = grdMain.Rows[j].Cells[HBackDataFlagCol].Value;
                            grdSub.Rows[i].Cells[HPrintCol].Value = "0";
                            grdSub.Rows[i].Cells[HWeiCol].Value = WeiShu;  
                            grdSub.Rows[i].Cells[HRemark2Col].Value = grdMain.Rows[j].Cells[HRemarkCol].Value;
                            grdSub.Rows[i].Cells[HDate2Col].Value = grdMain.Rows[j].Cells[HDateCol].Value;  
                            grdSub.Rows[i].Cells[HCusModel2Col].Value = grdMain.Rows[j].Cells[HCusModelCol].Value;  
                            k = k + 1;
                            n = n + 1; 
                            sSQLNoMul[nn] = " exec h_p_WMS_SetMaxNo_Cus '" + sTMNumber + sTMNumber_b + "' ";
                            nn = nn + 1;
                        }
                        //后台批量执行语句
                        if (oWeb.getRunProcByMul_Back(sSQLNoMul, ref DBUtility.ClsPub.sExeReturnInfo) == false)
                        {
                            MessageBox.Show("条码生成失败,批量生成流水号失败!");
                            return;
                        }
                        //
                    }
                }
                
                string HWei = "";      //尾数
                string HBarCode = "";
                string HBarCode_Pack = "";
                string HBarCodeType = "";
                Int64 HMaterID = 0;
                Int64 HAuxPropID = 0;
                Int64 HUnitID = 0;
                double HQty2 = 0;
                string HBatchNo2 = "";
                Int64 HSupID = 0;
                Int64 HGroupID = 0;
                int HPrintQty = 0;
                Int64 HSourceInterID = 0;
                Int64 HSourceEntryID = 0;
                string HSourceBillNo = "";
                string HSourceBillType = "";
                Int64 HBarcodeNo = 0;       //托号
                Int64 HBarcodeQtys = 0;     //总托数
                Int64 HDeptID = 0;
                Int64 HWhID = 0;
                Int64 HSPID = 0;
                string HRemark = "";
                string HMaterName = "";
                string HMaterModel = "";
                string HPinfan = "";
                string HMTONo = "";
                Int64 HCusID = 0;
                string HCusType = "";
                DateTime HEndDate; 
                DateTime HBeginDate;
                string HSeOrderBillNo = "";
                string HJiaYe2 = "";
                string HPressModel = ""; 
                string HMaterialModel = "";
                string HColor = "";
                string HLogo = "";
                string HPackageSize = "";
                double HMaterialJQty = 0;
                double HMaterialMQty = 0;
                string HCustomBatchNo = "";
                string HGBBarCode = "";
                string POOrderBillNo = "";
                //
                string HCusModel = "";
                string HWorkLineName = "";
                string HCode1 = "";
                string HSupNumber = "";
                string HCode2 = "";
                string HBarCodeDate = "";
                string HCode3 = "";
                string HBackDataFlag = "";
                string HCusModelName = "";
                string HSupName = "";
                string HLSSNO = "";
                long HCustomQty1 = 0;
 
                string[] sSQLMul = new string[grdSub.Rows.Count];
 
                pb1.Maximum = grdSub.Rows.Count;
                int mm = 0;
                for (int i = 0; i < grdSub.Rows.Count; i++)
                {
                    Application.DoEvents();
                    pb1.Value = i + 1;
                    Application.DoEvents();
                    if (ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusModel2Col].Value) != "")
                    {
                        HLSSNO = ClsPub.isStrNull(grdSub.Rows[i].Cells[HLSSno2Col].Value);
                        HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        HCusModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusModel2Col].Value);
                        HCusModelName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusModelName2Col].Value);
                        HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWorkLineName2Col].Value);
                        HCode1 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCode1_SecCol].Value);
                        HSupNumber = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSupNumber2Col].Value);
                        HSupName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSupName2Col].Value);
                        HCode2 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCode2Col].Value);
                        HBarCodeDate = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBarCodeDate2Col].Value);
                        HCode3 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCode3_SecCol].Value);
                        HBackDataFlag = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBackDataFlag2Col].Value);
 
                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                         
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value); 
                         
                        HQty2 = ClsPub.isDoule(grdSub.Rows[i].Cells[HQty2Col].Value); 
                        //HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value); 
                        HEndDate = ClsPub.isDate(grdSub.Rows[i].Cells[HEndDate2Col].Value); 
                        HBeginDate = ClsPub.isDate(grdSub.Rows[i].Cells[HBeginDate2Col].Value); 
                        HCusModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusModel2Col].Value);  
                        sSQLMul[mm] = "insert into Gy_BarCodeBill_Cus (HBarCode,HBarCodeType,HCusModel,HWorkLineName,HQty" +
                                    ",HCode1,HSupNumber,HCode2,HMaker,HMakeDate,HPrintQty" +
                                    ",HBarCodeDate,HCode3,HBackDataFlag,HRemark " +
                                    ",HInterID,HCusModelName,HSupName,HMaterID,HSNO " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "','" + HCusModel.ToString() + "','" + HWorkLineName.ToString() + "'," + HQty2.ToString()
                                    + ",'" + HCode1 + "','" + HSupNumber.ToString() + "','" + HCode2.ToString() + "','" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() 
                                    + ", '" + HBarCodeDate.ToString() + "','" + HCode3.ToString() + "','" + HBackDataFlag + "', '" + HRemark + "'" 
                                    + "," + HInterID.ToString() + " ,'" + HCusModelName + "'" + " ,'" + HSupName + "'" + "," + HMaterID.ToString() + ",'" + HLSSNO + "')";
                        //oCn.RunProc("exec setLSH '" + ClsPub.GetServerDate(0) + "'");
                        mm = mm + 1;
                        Application.DoEvents(); 
                        Application.DoEvents();
                    }
                }
                //
                
                //
                oWeb.Timeout = 200000;
                if (oWeb.getRunProcByMul_Back(sSQLMul, ref DBUtility.ClsPub.sExeReturnInfo))
                {
                    //查询最后一行条码是否存在于条码档案表中
                    int r = grdSub.Rows.Count - 1;
                    DataSet DS2 = oWeb.getDataSetBySQL("Select top 1 1 from Gy_BarCodeBill_Cus with(nolock) where HBarCode='" + DBUtility.ClsPub.isStrNull(grdSub.Rows[r].Cells[HTMCol].Value) + "'", "Gy_BarCodeBill_Cus", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DS2 == null || DS2.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("条码生成失败,请重新生成!" + DBUtility.ClsPub.sExeReturnInfo);
                        grdSub.RowCount = 0;
                        grdSub.RowCount = 20;
                    }
                    else
                    {
                        MessageBox.Show("条码生成完毕!");
                    }
                }
                else
                {
                    MessageBox.Show("条码生成失败!" + DBUtility.ClsPub.sExeReturnInfo);
                    grdSub.RowCount = 0;
                    grdSub.RowCount = 20;
                }
 
                tabControl1.SelectedIndex = 2;
            }
            catch (Exception e)
            {
                //oCn.RollBack();
                MessageBox.Show("条码生成失败!" + e.Message);
                grdSub.RowCount = 0;
                grdSub.RowCount = 20;
            }
        }
 
        #endregion 
 
 
        public string SetDateStr(DateTime sDateTime)
        {
            string sDate = sDateTime.ToShortDateString();
            string sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
            string sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
            string sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
            sDay = sDay.Substring(sDay.Length - 2, 2);
            return sYear+ sPeriod+ sDay;
        }
 
        #region 窗体处理方法
        //初始化GRID
        private void initGrid()
        {
            grdMain.RowCount = 0;
            grdSub.RowCount = 0;
            grdMain.ColumnCount = 25;                       //总列数
            ClsPub1.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[HQtyCol].HeaderText = "数量";
            grdMain.Columns[HMinQtyCol].HeaderText = "最小包装数";
            grdMain.Columns[HBQtyCol].HeaderText = "箱数"; 
            grdMain.Columns[HCode1Col].HeaderText = "扩展位1";
            grdMain.Columns[HCode2Col].HeaderText = "扩展位2";
            grdMain.Columns[HCode3Col].HeaderText = "扩展位3";
            grdMain.Columns[HBarCodeDateCol].HeaderText = "条码日期";
            grdMain.Columns[HBackDataFlagCol].HeaderText = "追溯标识";
            grdMain.Columns[HWorkLineNameCol].HeaderText = "产线";
            grdMain.Columns[HSupNumberCol].HeaderText = "供应商编码";
            grdMain.Columns[HSupNameCol].HeaderText = "供应商名称";
            grdMain.Columns[HDateCol].HeaderText = "进料日期";
            grdMain.Columns[HRemarkCol].HeaderText = "备注"; 
            grdMain.Columns[HCusModelCol].HeaderText = "客户零件号";
            grdMain.Columns[HCusModelNameCol].HeaderText = "客户零件名称";
            grdMain.Columns[HMaterIDCol].HeaderText = "物料代码";
            grdMain.Columns[HLSSnoCol].HeaderText = "流水号";
            grdMain.Columns[HBoxNoCol].HeaderText = "箱号";
            ////
            //格式化    隐藏列
            grdMain.Columns[HTagCol].Visible = false;
            grdMain.Columns[HMainIDCol].Visible = false;
            grdMain.Columns[HSubIDCol].Visible = false;
            grdMain.Columns[HBillTypeCol].Visible = false; 
            //grdMain.Columns[HBatchNoCol].Visible = false; 
            //grdMain.Columns[HCusModelCol].Visible = false; 
            grdMain.Columns[HDateCol].Visible = false; 
            //grdMain.Columns[HSupNumberCol].Visible = false;  
            grdMain.Columns[HinitQtyCol].Visible = false;
 
 
 
 
            //设置可编辑列
            string sAllowCol;
            sAllowCol = HQtyCol.ToString() +
                            "," + HCusModelCol.ToString() +
                            "," + HMaterIDCol.ToString() +
                            "," + HCusModelNameCol.ToString() +
                            "," + HWorkLineNameCol.ToString() +
                            "," + HSupNumberCol.ToString() +
                            "," + HSupNameCol.ToString() +
                            "," + HCode1Col.ToString() +
                            "," + HCode2Col.ToString() +
                            "," + HCode3Col.ToString() +
                            "," + HBarCodeDateCol.ToString() +
                            "," + HBackDataFlagCol.ToString() +
                            "," + HMinQtyCol.ToString();
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
 
            ClsPub1.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            //----------------------------
 
            grdSub.ColumnCount = 25;                       //总列数
            ClsPub1.initGridFst(grdSub, this.Name);
            grdSub.Columns[HSelectCol].HeaderText = "选择";
            grdSub.Columns[HCusModel2Col].HeaderText = "客户零件号";
            grdSub.Columns[HCode1_SecCol].HeaderText = "扩展位1";
            grdSub.Columns[HSupNumber2Col].HeaderText = "供应商编码";
            grdSub.Columns[HCode2_SecCol].HeaderText = "扩展位2";
            grdSub.Columns[HWorkLineName2Col].HeaderText = "产线";
            grdSub.Columns[HCode3_SecCol].HeaderText = "扩展位3";
            grdSub.Columns[HBackDataFlag2Col].HeaderText = "追溯标识";
            grdSub.Columns[HTMCol].HeaderText = "条码编号";
            grdSub.Columns[HBarCodeType2Col].HeaderText = "条码类型";
            grdSub.Columns[HSno2Col].HeaderText = "序号"; 
            grdSub.Columns[HQty2Col].HeaderText = "数量";
            grdSub.Columns[HWeiCol].HeaderText = "尾数";
            grdSub.Columns[HPrintCol].HeaderText = "打印次数"; 
            grdSub.Columns[HSupNumber2Col].HeaderText = "供应商编码";
            grdSub.Columns[HSupName2Col].HeaderText = "供应商编码";
            grdSub.Columns[HDate2Col].HeaderText = "进料日期";
            grdSub.Columns[HRemark2Col].HeaderText = "备注"; 
            grdSub.Columns[HBeginDate2Col].HeaderText = "计划开工日期";
            grdSub.Columns[HEndDate2Col].HeaderText = "计划完工日期"; 
            grdSub.Columns[HCusModel2Col].HeaderText = "客户型号";
            grdSub.Columns[HCusModelName2Col].HeaderText = "客户型号名称";
            grdSub.Columns[HMaterID2Col].HeaderText = "物料代码";
            grdSub.Columns[HLSSno2Col].HeaderText = "流水号";
            grdSub.Columns[HBoxNo2Col].HeaderText = "箱号";
 
            //格式化    隐藏列
            grdSub.Columns[HBarCodeType2Col].Visible = false; 
            //grdSub.Columns[HBatchNo2Col].Visible = false; 
            grdSub.Columns[HCusModel2Col].Visible = false;
            grdSub.Columns[HWeiCol].Visible = false;
            grdSub.Columns[HPrintCol].Visible = false; 
            grdSub.Columns[HDate2Col].Visible = false;
            grdSub.Columns[HBeginDate2Col].Visible = false;
            grdSub.Columns[HEndDate2Col].Visible = false; 
            grdSub.Columns[HSupNumber2Col].Visible = false; 
             
                 
 
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
            DBUtility.Xt_BaseBillFun.GetGrid(grdSub, this.Name + "grdSub");
            grdSub.SelectionMode = DataGridViewSelectionMode.FullRowSelect;                     //选行模式
 
            ////
            ClsPub1.initGridList(grdList, this.Name + "grdList");
            ////
        }
 
        private void Display()
        {
            DataSet DSet;
            //过滤条件  
            //if (HInterID <= 0)
            //{
            //    return;
            //}
            //
            DSet = oWeb.getDataSetBySQL("exec h_p_IF_BarCodeBill_CusList " + HInterID.ToString() + "  ", "h_p_IF_BarCodeBill_CusList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdList.DataSource = DSet.Tables[0].DefaultView;
            //冻结
            int FrCol = 0;
            string s = "是";
            ClsPub1.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
            //画线
            //GraphLine();
 
            // 
        }
 
        //公式重算
        private void RowCount(int sRow, int sTag)
        {
            if (sTag == 0)
            {
                //箱数列=数量/最小包装数
                double sMoney = 0;
                if (ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value) == 0)
                {
                    sMoney = 0;
                }
                else
                {
                    sMoney = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) / ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value);
                }
                sMoney = Math.Ceiling(sMoney);
                grdMain.Rows[sRow].Cells[HBQtyCol].Value = sMoney;
            }
            else 
            {
 
            }
            if (CampanyName == "四维尔") //系统参数  客户定制化名称
            {
 
            }
            else
            {
                //if (ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) > ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value)
                //    && ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HBillNoCol].Value) != "")
                //{
                //    MessageBox.Show("所输入的产品总数量大于剩余可生成数量" + ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value) + ",请重新输入!");
                //    grdMain.Rows[sRow].Cells[HQtyCol].Value = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HinitQtyCol].Value);
                //    return;
                //}
            }
        }
 
        //核对选择的内容
        public bool CheckGridCell(Cell oCell)
        {
            int Row;
            int Col;
            Row = oCell.Row;
            Col = oCell.Col;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //grdMain.Redraw = VSFlex7.RedrawSettings.flexRDNone;
            //判断选中列
            //if (Col == HMaterNumberCol)  //物料代码列
            //{
            //    //ClsGy_MaterialHlp oMate = new ClsGy_MaterialHlp();
            //    //if (oMate.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HMaterIDCol].Value)))
            //    //{
            //    //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = oMate.HItemID.ToString();
            //    //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = oMate.HNumber;
            //    //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = oMate.HName;
            //    //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = oMate.HModel;
            //    //}
            //    //else
            //    //{
            //    //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = "";
            //    //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = "";
            //    //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = "";
            //    //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = "";
            //    return false;
            //    //}
            //}
            //else if (Col == HUnitIDCol)  //单位ID列
            //{
            //    //ClsGy_UnitHlp oUn = new ClsGy_UnitHlp();
            //    //if (oUn.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HUnitIDCol])))
            //    //{
            //    //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = oUn.HItemID.ToString();
            //    //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = oUn.HName;
            //    //}
            //    //else
            //    //{
            //    //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = "";
            //    //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = "";
            //        return false;
            //    //}
            //}
            //else //其他列
            //{
            //}
            // 
            //
            grdMain.Rows[Row].Cells[HTagCol].Value = "*";
            oSumGrid.EditStatus = false;
            return true;
        }
        //是否是空行
        private bool IsNullRow(int Row)
        {
            return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HCusModelCol ,grdMain);
        }
        //'判断网格行的录入是否正确
        private bool CheckGridRow(int Row)
        {
            Cell oCell = new Cell();
            int c = 0;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //
            for (c = 0; c < grdMain.ColumnCount; c++)
            {
                oCell.Row = Row;
                oCell.Col = c;
                //if (!CheckGridCell(oCell))
                //    return false;
 
            }
            return true;
        }
        //帮助函数
        private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit)
        {
            DataSet oDs2 = new DataSet();
            long sHMaterID = 0;
            long sHOrgID=-1;
            string sWhere = "";
            sHOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            if (sHOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
             
            SCM.ClsIF_Supplier_View oSup = new SCM.ClsIF_Supplier_View();       //供应商
            SCM.ClsIF_Material_View oMater = new SCM.ClsIF_Material_View();       //
 
            if (!grdStatus)
            {
                return;
            }
            oSumGrid.EditStatus = true;
            switch (sKeyCode)
            {
                case 118:          //F7
                    {
                        switch (sCol)
                        {
                             
 
                            case HMaterIDCol:
                                oMater.WherePart = "";
                                sWhere = " and HUSEORGID = " + sHOrgID;
                                if (oMater.RefreshViewForBig(sWhere))
                                {
                                    grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString(); 
                                    grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 1;
                                    grdMain.Rows[sRow].Cells[HCusModelNameCol].Value = oMater.omodel.HName.ToString();
                                    grdMain.Rows[sRow].Cells[HCode1Col].Value = "00";
                                    grdMain.Rows[sRow].Cells[HCode2Col].Value ="000";
                                    grdMain.Rows[sRow].Cells[HCode3Col].Value = "0000";
                                    grdMain.Rows[sRow].Cells[HSupNumberCol].Value = "VG509";
                                    grdMain.Rows[sRow].Cells[HWorkLineNameCol].Value = "1";
                                    grdMain.Rows[sRow].Cells[HBarCodeDateCol].Value = dtpHDate.Value.ToShortDateString();
                                    grdMain.Rows[sRow].Cells[HBackDataFlagCol].Value = "%";
                                    oEdit.Text = oMater.omodel.HItemID.ToString();
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0; 
                                    grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 0; 
                                }
                                //if (CampanyName == "四维尔") //系统参数  客户定制化名称
                                //{
                                    sHMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[sRow].Cells[HMaterIDCol].Value);
                                    //获取品番
                                    oDs2 = oWeb.getDataSetBySQL("exec h_p_HMaterPinfan " + sHMaterID, "h_p_HMaterPinfan", ref DBUtility.ClsPub.sExeReturnInfo);
                                    //
                                    if (oDs2 != null && oDs2.Tables[0].Rows.Count > 0)
                                    {
                                        grdMain.Rows[sRow].Cells[HCusModelCol].Value = DBUtility.ClsPub.isStrNull(oDs2.Tables[0].Rows[0]["HPinfan"]);
                                        
                                    }
                                    else
                                    {
                                        grdMain.Rows[sRow].Cells[HCusModelCol].Value = "";
                                         
                                    }
                                //}
                                break;
 
                            //case HDateCol:
                            //    BLL.ClsPub_BLL.Sub_SelectDate(grdMain, sRow, HDateCol);
                            //    oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HDateCol].Value);
                            //    break;
 
 
                             
 
 
                            default:
                                break;
                        }
                        //bc.Enabled = true;
                        break;
                    }
                case 117:  //F6
                    {
                        switch (sCol)
                        {
                            
                           
                            default:
                                break;
                        }
                        break;
                    }
                default:
                    break;
            }
        }
       
        //选原单
        private void cmdSourceBillNo_Click(object sender, EventArgs e)
        {
            long sHOrgID = -1;
            string sWhere = "";
            sHOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            if (sHOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
 
            if (cmbSourceBillType.Text.Trim() == "生产订单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IFCLD_ICMOList oIFCLD_ICMOList = new SCM.Cls_S_IFCLD_ICMOList();
                if (oIFCLD_ICMOList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "生产汇报单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IF_ICMOReportBillList oIF_ICMOReportBillList = new SCM.Cls_S_IF_ICMOReportBillList();
                if (oIF_ICMOReportBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "收料通知单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IF_POInStockBillList oIF_POInStockBillList = new SCM.Cls_S_IF_POInStockBillList();
                if (oIF_POInStockBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POInStockBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "采购订单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IF_POOrderBillList oIF_POOrderBillList = new SCM.Cls_S_IF_POOrderBillList();
                if (oIF_POOrderBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_POOrderBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "委外订单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IF_EntrustOrderBillList oIF_EntrustOrderBillList = new SCM.Cls_S_IF_EntrustOrderBillList();
                if (oIF_EntrustOrderBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_EntrustOrderBillList.oBillSelectColl);
                }
            }
            else if (cmbSourceBillType.Text.Trim() == "入库申请单")
            {
                sWhere = " and HOrgID =" + sHOrgID.ToString();
                SCM.Cls_S_IF_StockInRequestBillList oIF_StockInRequestBillList = new SCM.Cls_S_IF_StockInRequestBillList();
                if (oIF_StockInRequestBillList.Refresh(sWhere))  //选择原单
                {
                    FillSelectData(oIF_StockInRequestBillList.oBillSelectColl);
                }
            }
            else
            {
 
            }
        }
        //
        private void FillSelectData(List<DBUtility.BillSelect> oList)
        {
            //DataSet Ds;
            //oSumGrid.Changelock = true;
            //int i = -1;
            //if (chkAddModel.Checked == false)
            //{
            //    initGrid();
            //    i = -1;
            //}
            //else
            //{
            //    for (int n = 0; n < grdMain.Rows.Count; n++)
            //    {
            //        if (DBUtility.ClsPub.isLong(grdMain.Rows[n].Cells[HMaterIDCol].Value) == 0)
            //        {
            //            i = n - 1;
            //            break;
            //        }
            //    }
            //}
            //foreach (DBUtility.BillSelect oSelectRow in oList)
            //{
            //    i = i + 1;
            //    //生产订单
            //    if (oSelectRow.BillType == "3710")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IFCLD_ICMOList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IFCLD_ICMOList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm(Ds.Tables[0], i);
            //    }
            //    //生产汇报单
            //    if (oSelectRow.BillType == "3711")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IF_ICMOReportList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ICMOReportList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm1(Ds.Tables[0], i);
            //    }
            //    //收料通知单
            //    if (oSelectRow.BillType == "1103")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IF_POInStockList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POInStockList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm1(Ds.Tables[0], i);
            //    }
            //    //采购订单
            //    if (oSelectRow.BillType == "1102")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IF_POOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_POOrderList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm1(Ds.Tables[0], i);
            //    }
            //    //委外订单
            //    if (oSelectRow.BillType == "1601")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IF_EntrustOrderList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_EntrustOrderList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm1(Ds.Tables[0], i);
            //    }
            //    //入库申请单
            //    if (oSelectRow.BillType == "1241")
            //    {
            //        grdMain.Rows.Add();
            //        grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_IF_StockInRequestList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_StockInRequestList", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm_1241(Ds.Tables[0], i);
 
            //        if (CampanyName == "森楷") //系统参数  客户定制化名称
            //        {
            //            //选源单后获取班组、箱号信息显示在界面上
            //            SCM.ClsGy_Group_View oGroup = new SCM.ClsGy_Group_View();
            //            txtHGroupID.Tag = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells[HGroupIDCol].Value);
            //            if (oGroup.GetInfoByID(DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells[HGroupIDCol].Value)))
            //            {
            //                txtHGroupID.Text = oGroup.omodel.HName;
            //            }
            //            else
            //            {
            //                txtHGroupID.Text = "";
            //            }
 
            //            string HGroupID = "";   //班组
            //            string HBatchNo = "";   //批次
            //            string HDate = "";      //日期
            //            string sCaseNoNumber = "";      //箱号前缀
            //            string sMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells[HMaterNumberCol].Value);
            //            string sAuxItemName = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells[HAuxPropNameCol].Value);
            //            HGroupID = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells[HGroupIDCol].Value);
            //            HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells[HBatchNoCol].Value);
            //            HDate = SetDateStr(dtpHDate.Value);
 
            //            //箱号前缀 = 班组ID + 批次 + 日期 + 物料代码 + 辅助属性
            //            sCaseNoNumber = HGroupID + HBatchNo + HDate + sMaterNumber + sAuxItemName; 
            //            txtHCaseNo.Tag = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]).ToString();
            //        }
            //    }
            //    //即时库存
            //    if (oSelectRow.BillType == "JSKC")
            //    {
            //        grdMain.Rows.Add();
            //        Application.DoEvents();
            //        //得到信息
            //        Ds = oWeb.getDataSetBySQL("select * from h_v_KF_ICInventoryList_IF where hmaterid=" + oSelectRow.BillMainID + " and hwhid=" + oSelectRow.BillSubID + " and hspid=" + oSelectRow.SPID + " and 批次='" + oSelectRow.BatchNo + "' and 计划跟踪号='" + oSelectRow.BillNo + "'", "h_v_KF_ICInventoryList_IF", ref DBUtility.ClsPub.sExeReturnInfo);
            //        //写入信息
            //        Sub_WriteInForm2(Ds.Tables[0], i);
            //    }
 
            //}
            ////
            //oSumGrid.Changelock = false;
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
        //根据TABLE写入界面(生产任务单) 
        private void Sub_WriteInForm(DataTable oTable, int i)
        {
            //if (CampanyName == "韩电") //系统参数  客户定制化名称
            //{
            //    ////加载表头
            //    //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //    //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            //    ////加载表体
            //    grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //    grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //    grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //    //
            //    grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            //    grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            //    grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            //    grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            //    grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString();
            //    grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
            //    grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            //    grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            //    grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            //    grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
            //    grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString();
            //    grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            //    grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            //    grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            //    grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            //    //grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[0]["是否启用批次"].ToString();
            //    grdMain.Rows[i].Cells[HCustomBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            //    grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            //    grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            //    grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            //    grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            //    grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            //    grdMain.Rows[i].Cells[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[HCusIDCol].Value = oTable.Rows[0]["HCusID"].ToString();
            //    grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["客户代码"].ToString();
            //    grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["客户"].ToString();
            //    grdMain.Rows[i].Cells[HCusTypeCol].Value = oTable.Rows[0]["客户型号"].ToString();
            //    //grdMain.Rows[i].Cells[HSourceIDCol].Value = oTable.Rows[0]["HSourceID"].ToString();
            //    //grdMain.Rows[i].Cells[HSourceNumberCol].Value = oTable.Rows[0]["生产线代码"].ToString();
            //    grdMain.Rows[i].Cells[HSourceNameCol].Value = oTable.Rows[0]["生产线"].ToString();
            //    grdMain.Rows[i].Cells[HBeginDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();
            //    grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();
            //    grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
            //    grdMain.Rows[i].Cells[HSeOrderBillNoCol].Value = oTable.Rows[0]["销售订单号"].ToString();
            //    grdMain.Rows[i].Cells[HModelCol].Value = oTable.Rows[0]["产品型号"].ToString();
            //    grdMain.Rows[i].Cells[HColorCol].Value = oTable.Rows[0]["颜色"].ToString();
            //    grdMain.Rows[i].Cells[HJiaYeCol].Value = oTable.Rows[0]["加液代码"].ToString();
            //    grdMain.Rows[i].Cells[HPackageSizeCol].Value = oTable.Rows[0]["包装尺寸"].ToString();
            //    grdMain.Rows[i].Cells[HJQtyCol].Value = oTable.Rows[0]["净重"].ToString();
            //    grdMain.Rows[i].Cells[HMQtyCol].Value = oTable.Rows[0]["毛重"].ToString();
            //    grdMain.Rows[i].Cells[HLogoCol].Value = oTable.Rows[0]["品牌"].ToString();
            //    grdMain.Rows[i].Cells[HPressModelCol].Value = oTable.Rows[0]["压机型号"].ToString();
            //    grdMain.Rows[i].Cells[HCusModelCol].Value = oTable.Rows[0]["客户型号"].ToString();
            //    grdMain.Rows[i].Cells[HGBBarCodeCol].Value = oTable.Rows[0]["国标码"].ToString();
            //    grdMain.Rows[i].Cells[HJiaYeLXCol].Value = oTable.Rows[0]["制冷液类型"].ToString();
            //    grdMain.Rows[i].Cells[HJiaYeLCol].Value = oTable.Rows[0]["加液量"].ToString();
            //    //grdMain.Rows[i].Cells[HDateCol].Value = string.Format("{0:yyyyMMdd}", ClsPub.isDate(ClsPub.GetServerDate(0)));
            //    //--
            //    //设置可编辑列
            //    string sAllowCol = HQtyCol.ToString() +
            //                        "," + HGroupNameCol.ToString() +
            //                        "," + HMaterNameCol.ToString() +
            //                        "," + HAuxPropNumberCol.ToString() +
            //                        "," + HPressModelCol.ToString() +
            //                        "," + HGBBarCodeCol.ToString() +
            //        //"," + HCusModelCol.ToString() +
            //        //"," + HLogoCol.ToString() +
            //                        "," + HMinQtyCol.ToString();
            //    grdMain.Columns[HBillNoCol].ReadOnly = true;
            //    //设置合计列
            //    string sTotalCol = HQtyCol.ToString();
            //    //
            //    ClsPub1.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            //    tabControl1.SelectedIndex = 0;
            //    bc.Enabled = true;
            //    //
            //    RowCount(i, 0);
            //}
            //else
            //{
            //    ////加载表头
            //    //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //    //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            //    ////加载表体
            //    grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //    grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //    grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //    //
            //    grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            //    grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            //    grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            //    grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            //    grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); 
            //    grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            //    grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            //    grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            //    grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
            //    grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString();
            //    grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            //    grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            //    grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            //    grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            //    //grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[0]["是否启用批次"].ToString();
            //    grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            //    grdMain.Rows[i].Cells[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[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            //    grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            //    grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            //    grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            //    grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            //    grdMain.Rows[i].Cells[HCusIDCol].Value = oTable.Rows[0]["HCusID"].ToString();
            //    grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["客户代码"].ToString();
            //    grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["客户"].ToString();
            //    grdMain.Rows[i].Cells[HCusTypeCol].Value = oTable.Rows[0]["客户型号"].ToString();
            //    //grdMain.Rows[i].Cells[HSourceIDCol].Value = oTable.Rows[0]["HSourceID"].ToString();
            //    //grdMain.Rows[i].Cells[HSourceNumberCol].Value = oTable.Rows[0]["生产线代码"].ToString();
            //    grdMain.Rows[i].Cells[HSourceNameCol].Value = oTable.Rows[0]["生产线"].ToString();
            //    grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();
            //    grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
            //    grdMain.Rows[i].Cells[HPinfanCol].Value = oTable.Rows[0]["HPinfan"].ToString();
            //    grdMain.Rows[i].Cells[HPinfanBarCodeCol].Value = oTable.Rows[0]["HPinfanBarCode"].ToString();
            //    //grdMain.Rows[i].Cells[HDateCol].Value = string.Format("{0:yyyyMMdd}", ClsPub.isDate(ClsPub.GetServerDate(0)));
            //    //--
            //    //设置可编辑列
            //    string sAllowCol;
            //    sAllowCol = HQtyCol.ToString() +
            //                "," + HCusModelCol.ToString() +
            //                "," + HWorkLineNameCol.ToString() +
            //                "," + HSupNumberCol.ToString() +
            //                "," + HCode1Col.ToString() +
            //                "," + HCode2Col.ToString() +
            //                "," + HCode3Col.ToString() +
            //                "," + HBarCodeDateCol.ToString() +
            //                "," + HBackDataFlagCol.ToString() +
            //                "," + HMinQtyCol.ToString();
            //    grdMain.Columns[HBillNoCol].ReadOnly = true;
            //    //设置合计列
            //    string sTotalCol = HQtyCol.ToString();
            //    //
            //    ClsPub1.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            //    tabControl1.SelectedIndex = 0;
            //    bc.Enabled = true;
            //    //
            //    RowCount(i, 0);
            //}
        }
 
        //根据TABLE写入界面
        private void Sub_WriteInForm1(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            //grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            //grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            ////
            //grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            //grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            //grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            //grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            //grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); 
            //grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            //grdMain.Rows[i].Cells[HWorkLineNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            //grdMain.Rows[i].Cells[HCode1Col].Value = oTable.Rows[0]["HDeptID"].ToString();
            //grdMain.Rows[i].Cells[HCode2Col].Value = oTable.Rows[0]["部门代码"].ToString();
            //grdMain.Rows[i].Cells[HCode3Col].Value = oTable.Rows[0]["部门"].ToString();
            //grdMain.Rows[i].Cells[HCusModelCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            //grdMain.Rows[i].Cells[HBarCodeDateCol].Value = oTable.Rows[0]["物料代码"].ToString();
            //grdMain.Rows[i].Cells[HBackDataFlagCol].Value = oTable.Rows[0]["物料名称"].ToString();
            //grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString(); 
            //grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString();
            
            //--
            //设置可编辑列
            string sAllowCol; 
            sAllowCol = HQtyCol.ToString() +
                            "," + HCusModelCol.ToString() +
                            "," + HWorkLineNameCol.ToString() +
                            "," + HSupNumberCol.ToString() +
                            "," + HCode1Col.ToString() +
                            "," + HCode2Col.ToString() +
                            "," + HCode3Col.ToString() +
                            "," + HBarCodeDateCol.ToString() +
                            "," + HBackDataFlagCol.ToString() + 
                            "," + HMinQtyCol.ToString();
             
            grdMain.Columns[HBillNoCol].ReadOnly = true;
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            ClsPub1.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            tabControl1.SelectedIndex = 0;
            bc.Enabled = true;
            //
            RowCount(i, 0);
        }
        
 
        //根据TABLE写入界面(即时库存)
        private void Sub_WriteInForm2(DataTable oTable, int i)
        {
            ////加载表头
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门名称"].ToString();
            ////加载表体
            //grdMain.Rows[i].Cells[HTagCol].Value = "*";
            //grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["数量"]);
            //grdMain.Rows[i].Cells[HinitQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["数量"]);
            ////
            ////grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            ////grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["任务单号"].ToString();
            ////grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            //grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString();
            //grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString();
            //grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString();
            //grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString();
            //grdMain.Rows[i].Cells[HAuxPropIDCol].Value = oTable.Rows[0]["HAuxPropID"].ToString();
            //grdMain.Rows[i].Cells[HAuxPropNumberCol].Value = oTable.Rows[0]["辅助属性代码"].ToString();
            //grdMain.Rows[i].Cells[HAuxPropNameCol].Value = oTable.Rows[0]["辅助属性名称"].ToString();
            //grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString();
            //grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString();
            //grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString();
            //grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            //grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["HSupplyID"].ToString();
            //grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
            //grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["供应商"].ToString();
            //grdMain.Rows[i].Cells[HWhIDCol].Value = oTable.Rows[0]["HWhID"].ToString();
            //grdMain.Rows[i].Cells[HWhNumberCol].Value = oTable.Rows[0]["仓库代码"].ToString();
            //grdMain.Rows[i].Cells[HWhNameCol].Value = oTable.Rows[0]["仓库"].ToString();
            //grdMain.Rows[i].Cells[HSPIDCol].Value = oTable.Rows[0]["HSPID"].ToString();
            //grdMain.Rows[i].Cells[HSPNumberCol].Value = oTable.Rows[0]["仓位代码"].ToString();
            //grdMain.Rows[i].Cells[HSPNameCol].Value = oTable.Rows[0]["仓位"].ToString();
            //grdMain.Rows[i].Cells[HDateCol].Value = ClsPub.GetServerDate(0);
            //grdMain.Rows[i].Cells[HRemarkCol].Value = "按库存生成";
            //grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            ////--
            ////设置可编辑列
            //string sAllowCol = HQtyCol.ToString() +
            //                    "," + HMinQtyCol.ToString();
            //grdMain.Columns[HBillNoCol].ReadOnly = true;
            ////设置合计列
            //string sTotalCol = HQtyCol.ToString();
            ////
            //ClsPub1.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            //tabControl1.SelectedIndex = 0;
            //bc.Enabled = true;
            ////
            //RowCount(i, 0);
        }
 
        //网格编辑前判断
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid,i))
            {
                e.Cancel = true;
            }
        }
 
        //网格编辑后处理
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            if (e.ColumnIndex == HMinQtyCol)
            {
                RowCount(e.RowIndex, 0);  //
            }
            else if (e.ColumnIndex == HQtyCol)
            {
                RowCount(e.RowIndex, 0);  //
            }
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
        DataGridViewTextBoxEditingControl EditingControl;
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            ////
            //if (!grdStatus)
            //{
            //    return;
            //}
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            ////
            ////if (oSumGrid.Changelock)
            ////    return;
            ////if(oSumGrid.EditStatus)
            ////{
            //if (!CheckGridRow(oSumGrid.OldCell.Row))
            //    return;
            ////}
        }
 
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdMain.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //增加委托处理 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
            }
        }
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //业务处理 
            Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl);
        }
        private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            oSumGrid.DisplayCurRow();
        }
 
        #endregion
 
 
        #region  //打印设置
 
        GridppReport Report;
        string sBarCode = "";
 
        //预览
        int CurRows = 0;
        private void yl_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再预览!");
                return;
            }
 
            //打印前判断条码是否已打印过
            if (ReportPrintBegin())
            {
                return;
            }
 
            //选择打印模板
            SCM.Gy_OpenTmp oFrm = new SCM.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(false); 
                Thread.Sleep(1000);
            }
        }
 
        //打印前判断条码是否已打印过
        private bool ReportPrintBegin()
        {
            string sRelQty = "";
 
            if (oWeb.Set_BPrintQtyBarCode(DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value), ref sRelQty))
            {
                MessageBox.Show("条码已经打印过,不可重复打印!");
                return true;
            }
            else
            {
                return false;
            }
        }
 
        //打印结束后回填条码打印次数
        private void ReportPrintEnd()
        {
            try
            {
                //sBarCode = "";
                //for (int i = 0; i < grdSub.Rows.Count; i++)
                //{
                //    sBarCode = sBarCode + "," + DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                //}
 
                //oWeb.getRunProc("exec h_p_Gy_BarCodePrintQty_Update '" + sBarCode + "'", ref DBUtility.ClsPub.sExeReturnInfo);
 
                oWeb.getRunProc("update Gy_BarCodeBill_Cus set HPrintQty=isnull(HPrintQty,0)+1 where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!打印结束 :" + e.Message);
            }
        }
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdList.Rows.Count; i++)
            {
                grdList.Rows[i].Cells[0].Value = "*";
                //grdList.Rows[i].Cells[0].Value = "";
            }
            //for (int i = 0; i < grdList.SelectedRows.Count; i++)
            //{
            //    grdList.Rows[grdList.SelectedRows[i].Index].Cells[0].Value = "*";
            //}
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
        }
 
        //填入单据表头信息
        private void ReportBeforePostRecord()// 
        {
            try
            {
                //Report.FieldByName("物料代码").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterNumber2Col].Value);
                //Report.FieldByName("物料名称").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterName2Col].Value);
                //Report.FieldByName("规格型号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HMaterModel2Col].Value);
                ////Report.FieldByName("自定义规格").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HModel2Col].Value);
                //Report.FieldByName("条码编号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HTMCol].Value);
                //Report.FieldByName("数量").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HQty2Col].Value);
                //Report.FieldByName("源单单号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HSourceBillNoCol].Value);
                //Report.FieldByName("销售订单号").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HSeOrderBillNo2Col].Value);
                //Report.FieldByName("生产车间").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HDeptName2Col].Value);
                //Report.FieldByName("备注").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HRemark2Col].Value);
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表头:" + e.Message);
            }
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
        }
        private void ReportFetchRecordByDataTable()
        {
            try
            {
                DataTable ds = new DataTable();
                //BLL.Utility.FillRecordToReport(Report, grdSub, ds, HMaterIDCol);
                SCM.Utility.FillRecordToReport(Report, grdList, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表体:" + e.Message);
            }
        }
 
        private void dy_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再打印!");
                return;
            }
 
            //打印前判断条码是否已打印过
            if (ReportPrintBegin())
            {
                return;
            }
 
            //选择打印模板
            SCM.Gy_OpenTmp oFrm = new SCM.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 grdSub_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdSub.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            {
                e.Cancel = true;
            }
        }
 
        private void grdSub_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            RowCount(e.RowIndex, 0);  //计算 金额 单价
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
 
        //按库存生成条码
        private void kc_Click(object sender, EventArgs e)
        {
            //long sHOrgID = -1;
            //string sWhere = "";
            //sHOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            //sWhere = " and HOrgID =" + sHOrgID.ToString();
            //SCM.Cls_S_KF_ICInventoryList_IF oadd = new SCM.Cls_S_KF_ICInventoryList_IF();
            //if (oadd.Refresh(sWhere))  //选择原单
            ////if (oadd.Refresh(" and HErpClsID in (1,2,3) "))  //选择原单
            //{
            //    FillSelectData(oadd.oBillSelectColl);
            //}
        }
 
 
        //获取本月的第几周
        private static int getWeekNumInMonth(DateTime daytime)
        {
            int dayInMonth = daytime.Day;
            //本月第一天
            DateTime firstDay = daytime.AddDays(1 - daytime.Day);
            //本月第一天是周几
            int weekday = (int)firstDay.DayOfWeek == 0 ? 7 : (int)firstDay.DayOfWeek;
            //本月第一周有几天
            int firstWeekEndDay = 7 - (weekday - 1);
            //当前日期和第一周之差
            int diffday = dayInMonth - firstWeekEndDay;
            diffday = diffday > 0 ? diffday : 1;
            //当前是第几周,如果整除7就减一天
            int WeekNumInMonth = ((diffday % 7) == 0
             ? (diffday / 7 - 1)
             : (diffday / 7)) + 1 + (dayInMonth > firstWeekEndDay ? 1 : 0);
            return WeekNumInMonth;
        }
 
        //同步基础资料信息
        private void tb_Click(object sender, EventArgs e)
        {
            try
            {
                oWeb.getRunProc("exec h_p_IFCLD_ERPDataToLocal", ref DBUtility.ClsPub.sExeReturnInfo);
                MessageBox.Show("同步基础资料成功!");
            }
            catch (Exception sExeReturnInfo)
            {
                MessageBox.Show("同步基础资料失败!" + sExeReturnInfo.Message);
            }
        }
 
        public Frm_Split oDlg = new Frm_Split();
 
        private void spRow_Click(object sender, EventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
            oDlg.ShowDialog();
            if (oDlg.IsOk == 1)
            {
                grdMainData_CF(DBUtility.ClsPub.isInt(oDlg.txtHQ.Text), oDlg.cmbHAutoSNO.Text);
            }
        }
 
        private void grdMainData_CF(int HQty, string HAutoSNO)
        {
            //double hq = 0;
            //int Qty = HQty - 1;
            //int row = grdMain.CurrentCell.RowIndex;
            //string Sno = "";
            //grdMain.Rows.Insert(row + 1, Qty);
            //hq = DBUtility.ClsPub.isDoule(grdMain.Rows[row].Cells[HQtyCol].Value) / HQty;
            //grdMain.Rows[row].Cells[HQtyCol].Value = hq;
            //for (int i = 0; i < Qty; i++)
            //{
            //    int r = i + 1;
            //    grdMain.Rows[row + r].Cells[HMaterIDCol].Value = grdMain.Rows[row].Cells[HMaterIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HMaterNumberCol].Value = grdMain.Rows[row].Cells[HMaterNumberCol].Value;
            //    grdMain.Rows[row + r].Cells[HMaterNameCol].Value = grdMain.Rows[row].Cells[HMaterNameCol].Value;
            //    grdMain.Rows[row + r].Cells[HMaterModelCol].Value = grdMain.Rows[row].Cells[HMaterModelCol].Value;
            //    grdMain.Rows[row + r].Cells[HUnitIDCol].Value = grdMain.Rows[row].Cells[HUnitIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HUnitNameCol].Value = grdMain.Rows[row].Cells[HUnitNameCol].Value;
            //    grdMain.Rows[row + r].Cells[HSourceIDCol].Value = grdMain.Rows[row].Cells[HSourceIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HSourceNumberCol].Value = grdMain.Rows[row].Cells[HSourceNumberCol].Value;
            //    grdMain.Rows[row + r].Cells[HSourceNameCol].Value = grdMain.Rows[row].Cells[HSourceNameCol].Value;
            //    grdMain.Rows[row + r].Cells[HQtyCol].Value = DBUtility.ClsPub.isDoule(hq, 4);
            //    grdMain.Rows[row + r].Cells[HinitQtyCol].Value = grdMain.Rows[row].Cells[HinitQtyCol].Value;
            //    grdMain.Rows[row + r].Cells[HMinQtyCol].Value = 0;
 
            //    grdMain.Rows[row + r].Cells[HTagCol].Value = grdMain.Rows[row].Cells[HTagCol].Value;
            //    grdMain.Rows[row + r].Cells[HMainIDCol].Value = grdMain.Rows[row].Cells[HMainIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HSubIDCol].Value = grdMain.Rows[row].Cells[HSubIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HBillNoCol].Value = grdMain.Rows[row].Cells[HBillNoCol].Value;
            //    grdMain.Rows[row + r].Cells[HBillTypeCol].Value = grdMain.Rows[row].Cells[HBillTypeCol].Value;
            //    grdMain.Rows[row + r].Cells[HDateCol].Value = grdMain.Rows[row].Cells[HDateCol].Value;
            //    grdMain.Rows[row + r].Cells[HSupIDCol].Value = grdMain.Rows[row].Cells[HSupIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HSupNumberCol].Value = grdMain.Rows[row].Cells[HSupNumberCol].Value;
            //    grdMain.Rows[row + r].Cells[HSupNameCol].Value = grdMain.Rows[row].Cells[HSupNameCol].Value;
            //    grdMain.Rows[row + r].Cells[HDeptIDCol].Value = grdMain.Rows[row].Cells[HDeptIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HDeptNumberCol].Value = grdMain.Rows[row].Cells[HDeptNumberCol].Value;
            //    grdMain.Rows[row + r].Cells[HDeptNameCol].Value = grdMain.Rows[row].Cells[HDeptNameCol].Value;
            //    if (DBUtility.ClsPub.isStrNull(HAutoSNO) == "是")
            //    {
            //        Sno = "00" + (r + 1).ToString();
            //        Sno = Sno.Substring(Sno.Length - 2, 2);
            //        grdMain.Rows[row + r].Cells[HBatchNoCol].Value = grdMain.Rows[row].Cells[HBatchNoCol].Value + Sno;
            //    }
            //    else
            //    {
            //        grdMain.Rows[row + r].Cells[HBatchNoCol].Value = grdMain.Rows[row].Cells[HBatchNoCol].Value;
            //    }
            //    grdMain.Rows[row + r].Cells[HAuxPropIDCol].Value = grdMain.Rows[row].Cells[HAuxPropIDCol].Value;
            //    grdMain.Rows[row + r].Cells[HAuxPropNumberCol].Value = grdMain.Rows[row].Cells[HAuxPropNumberCol].Value;
            //    grdMain.Rows[row + r].Cells[HAuxPropNameCol].Value = grdMain.Rows[row].Cells[HAuxPropNameCol].Value;
            //    grdMain.Rows[row + r].Cells[HRemarkCol].Value = grdMain.Rows[row].Cells[HRemarkCol].Value;
            //    grdMain.Rows[row + r].Cells[HMTONoCol].Value = grdMain.Rows[row].Cells[HMTONoCol].Value;
 
            //}
            //if (DBUtility.ClsPub.isStrNull(HAutoSNO) == "是")
            //{
            //    grdMain.Rows[row].Cells[HBatchNoCol].Value = grdMain.Rows[row].Cells[HBatchNoCol].Value + "01";
            //}
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void txtHSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (e.KeyChar == (char)Keys.Return)//回车带出源单信息
            //{
            //    long sHOrgID = -1;
            //    string sWhere = "";
            //    sHOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            //    if (sHOrgID == -1)
            //    {
            //        MessageBox.Show("选择组织有错误!");
            //        return;
            //    }
 
            //    if (txtHSourceBillNo.Text.Length < 4)
            //    {
            //        MessageBox.Show("请输入4位以上数据!");
            //        return;
            //    }
            //    //根据源单类型 和源单号 获取信息
            //    if (cmbSourceBillType.Text.Trim() == "生产订单")
            //    {
            //        SCM.Cls_S_IFCLD_ICMOList oIFCLD_ICMOList = new SCM.Cls_S_IFCLD_ICMOList();
            //        if (oIFCLD_ICMOList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + sHOrgID.ToString()))  //选择原单
            //        {
            //            FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
            //            txtHSourceBillNo.Text = "";
            //        }
            //    }
            //    else if (cmbSourceBillType.Text.Trim() == "收料通知单")
            //    {
            //        SCM.Cls_S_IF_POInStockBillList oIF_POInStockBillList = new SCM.Cls_S_IF_POInStockBillList();
            //        if (oIF_POInStockBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
            //        {
            //            FillSelectData(oIF_POInStockBillList.oBillSelectColl);
            //            txtHSourceBillNo.Text = "";
            //        }
            //    }
            //    else if (cmbSourceBillType.Text.Trim() == "采购订单")
            //    {
            //        SCM.Cls_S_IF_POOrderBillList oIF_POOrderBillList = new SCM.Cls_S_IF_POOrderBillList();
            //        if (oIF_POOrderBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
            //        {
            //            FillSelectData(oIF_POOrderBillList.oBillSelectColl);
            //            txtHSourceBillNo.Text = "";
            //        }
            //    }
            //    else if (cmbSourceBillType.Text.Trim() == "委外订单")
            //    {
            //        SCM.Cls_S_IF_EntrustOrderBillList oIF_EntrustOrderBillList = new SCM.Cls_S_IF_EntrustOrderBillList();
            //        if (oIF_EntrustOrderBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
            //        {
            //            FillSelectData(oIF_EntrustOrderBillList.oBillSelectColl);
            //            txtHSourceBillNo.Text = "";
            //        }
            //    }
            //    else if (cmbSourceBillType.Text.Trim() == "入库申请单")
            //    {
            //        SCM.Cls_S_IF_StockInRequestBillList oIF_StockInRequestBillList = new SCM.Cls_S_IF_StockInRequestBillList();
            //        if (oIF_StockInRequestBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' "))  //选择原单
            //        {
            //            FillSelectData(oIF_StockInRequestBillList.oBillSelectColl);
            //            txtHSourceBillNo.Text = "";
            //        }
            //        else
            //        {
            //            MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!");
            //            return;
            //        }
            //    }
            //    else
            //    {
 
            //    }
 
            //}
 
        }
 
        private void cmdHGroupID_Click(object sender, EventArgs e)
        {
            long sHOrgID = -1;
            string sWhere = "";
            sHOrgID = oWeb.get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
            if (sHOrgID == -1)
            {
                MessageBox.Show("选择组织有错误!");
                return;
            }
 
            sWhere = " and HUSEORGID = " + sHOrgID;
            SCM.ClsGy_Group_View oGroup = new SCM.ClsGy_Group_View();
            if (oGroup.RefreshView())
            {
                txtHGroupID.Text = oGroup.oModel.HName;
                txtHGroupID.Tag = oGroup.oModel.HItemID.ToString();  
            }
            else
            {
                txtHGroupID.Text = ""; 
            }
            oGroup = null;
        }
 
        private void txtHGroupID_TextChanged(object sender, EventArgs e)
        {
            if (txtHGroupID.Text.Trim() == "")
            {
                txtHGroupID.Tag = "0";
            }
        }
    }
}