1
yusijie
2023-05-25 6592e8f84bf7958dd256a33b66e1fa3203296312
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.Data.SqlClient;
using System.Net.Sockets;
using System.Net;
 
namespace Pub_Class
{
    public class ClsPub
    {
        //public static string HTextBox = "HXErp_Test.ini";
        public static string HTextBox = "HXErp.ini";
        public static string HUrl_CLD = "http://122.227.128.123:8090/k3cloud/";
        public static string HdbID_CLD = "5b3711f4fe3fa5";
        public static string HUserName_CLD = "测试1";
        public static string HPsd_CLD = "111111";
        public static string HWEBSUrl_CLD = "http://localhost/SafeWell_Web/WebService1.asmx";
 
        public static string sCLOUDUrl = "";
        public static string sCLOUDAcc = "";
        public static string sCLOUDUseName = "";
        public static string sCLOUDPsd = "";
 
        public static Int64 HOrgID = 0;//组织内码
        public static string HOrgNumber = ""; //组织代码
        public static string HOrgName = ""; //组织名称
        public static Int64 HORGANIZATIONSID = 0;
        public static string HORGANIZATIONSNO = "";
        public static string HDataCenterID = "";
        public static string IPAddress;
        public static string ComputerName;
        public static string VersionNew;
        public static string VersionOld;
        public static string VersionNum;
        public static string CurUserName="";
        public static string CurUserID;
        public static string sExeReturnInfo;
        public static string AppPath;
        public static string AccNumber;//帐套代码
        public static string AccName;//帐套名称
        public static string CompName;//客户公司名称
        public static int CurYear;
        public static int CurPeriod;
        public static Color EditColor = Color.White;
        public static Color ViewColor = Color.WhiteSmoke;
        public static int CBCurYear;
        public static int CBCurPeriod;
        public static int XFCurYear;
        public static int XFCurPeriod;
        public static int KQCurYear;
        public static int KQCurPeriod;
        public static DateTime CBCurBDate;
        public static DateTime CBCurEDate;
        public static DateTime XFCurBDate;
        public static DateTime XFCurEDate;
        public static DateTime KQCurBDate;
        public static DateTime KQCurEDate;
 
        public static bool check;
        public static int HCheckStatus;
        public static string sSQLInfo;
        public static string sErrInfo;
 
        public enum Enum_BillStatus : int
        {
            BillStatus_AddNew = 1,
            BillStatus_Modify = 2,
            BillStatus_View = 4,
            BillStatus_UpdatePrice = 8
        }
 
        public enum Enum_OKTag : int
        {
            OKTag_Cancel = 0,
            OKTag_OK = 1
        }
 
        public enum Enum_Color : long
        {
            hx_Red = 255,
            hx_Black = 0,
            hx_Write = 16777215,
            hx_Blue = 16711680,
            hx_Green = 65280,
            hx_Yellow = 65535,
            hx_Control = 13425104
        }
 
        public enum Enum_InputMode : int
        {
            InputMode_View = 0,
            InputMode_AddNew = 1,
            InputMode_Modify = 2,
            InputMode_AddNewGroup = 3,
            InputMode_ModifyGroup = 4
        }
 
        public enum Enum_InputModeGroup : int
        {
            InputMode_View = 0,
            InputMode_AddNew = 1,
            InputMode_Modify = 2,
        }
         
 
        //获取CLOUD登录信息
        public static bool GetCLOUDLoginInfo(ref string sExeReturnInfo)
        {
            try
            {
                AppPath = System.Environment.CurrentDirectory;
                sCLOUDUrl = ClsIni.ReadIni("CLOUDINFO", "sCLOUDUrl", AppPath + @"\" + HTextBox);
                sCLOUDAcc = ClsIni.ReadIni("CLOUDINFO", "sCLOUDAcc", AppPath + @"\" + HTextBox);
                sCLOUDUseName = ClsIni.ReadIni("CLOUDINFO", "sCLOUDUseName", AppPath + @"\" + HTextBox);
                sCLOUDPsd = ClsIni.ReadIni("CLOUDINFO", "sCLOUDPsd", AppPath + @"\" + HTextBox);
                if (isStrNull(sCLOUDUrl + sCLOUDAcc + sCLOUDUseName + sCLOUDPsd) == "" ||
                    isStrNull(sCLOUDUrl + sCLOUDAcc + sCLOUDUseName + sCLOUDPsd).Contains("没有找到") == true)
                {
                    sExeReturnInfo = "读取CLOUD配置文件为空! 网址:" + isStrNull(sCLOUDUrl) + "  ; 账套:" + isStrNull(sCLOUDAcc) + " ; 用户:"
                        + isStrNull(sCLOUDUseName) + " ; 密码:" + isStrNull(sCLOUDPsd) + "  文件地址:" + isStrNull(AppPath);
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception e)
            {
                sExeReturnInfo = "读取CLOUD配置文件失败!网址:" + isStrNull(sCLOUDUrl) + "  ; 账套:" + isStrNull(sCLOUDAcc) + " ; 用户:"
                        + isStrNull(sCLOUDUseName) + " ; 密码:" + isStrNull(sCLOUDPsd) + "  文件地址:" + isStrNull(AppPath) + e.Message;
                return false;
            }
 
        }
 
 
        //检验 最新版本
        public static bool CheckUpdate()
        {
            
            DataSet oDs = new DataSet();
            ClsSqlHelperMaster oCn = new ClsSqlHelperMaster();
            string LastNumber1 = "";
            string LastNumber2 = "";
            string BbNumber = "";
            string sTableName = "";
            //得到更新表
            sTableName = ClsIni.ReadIni("UpDateCounts", "sTableName", ClsPub.AppPath + @"\" + "UpDatePrj.ini");
            if (sTableName == "没有找到!" || sTableName == "")
            {
                sTableName = "HX_Update";
            }
            //得到最新版本
            try
            {
                oDs = oCn.RunProcReturn("select top 1 * from " + sTableName + " order by FItemID", sTableName);
                if (oDs == null || oDs.Tables[0].Rows.Count == 0)
                {
                    return false;
                }
                else
                {
                    LastNumber1 = oDs.Tables[0].Rows[0]["FNumber"].ToString().Trim();
                    VersionNew = LastNumber1;
                }
                //得到本地版本
                LastNumber2 = ClsIni.ReadIni("UpDateCounts", "LastUpdateID", ClsPub.AppPath + @"\" + "UpDatePrj.ini");
                VersionOld = LastNumber2;
                if (LastNumber2 == "没有找到!")
                {
                    return false;
                }
                if (LastNumber2.Trim().ToUpper() == LastNumber1.Trim().ToUpper())
                {
                    return false;
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
            
        }
        //
       
 
        //得到列标识
        public static int Fun_GetCol(DataGridView oGrd, string KeyItem)
        {
            for (int c = 0; c < oGrd.ColumnCount; c++)
            {
                if (ClsPub.isStrNull(oGrd.Columns[c].HeaderText).ToUpper().Trim() == KeyItem.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
 
        //得到列标识
        public static int Fun_GetCol_New(DataGridView oGrd, string KeyItem)
        {
            for (int c = 0; c < oGrd.ColumnCount; c++)
            {
                if (ClsPub.isStrNull(oGrd.Columns[c].HeaderText).ToUpper().Trim() == KeyItem.Trim().ToUpper())
                {
                    return c;
                }
            }
            return -1;
        }
 
        //得到组织内码根据组织名称
        public static Int64 get_ORGANIZATIONSIDByName(string HDataCenterName)
        {
            try
            {
                ClsSqlHelper oCN = new ClsSqlHelper();
                DataSet ds = oCN.RunProcReturn("select HItemID from h_v_CLD_ORGANIZATIONSList where Hname='" + HDataCenterName + "'", "h_v_CLD_ORGANIZATIONSList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return -1;
                }
                else
                {
                    return  ClsPub.isLong(ds.Tables[0].Rows[0]["HItemID"]);
                }
            }
            catch (Exception e)
            {
                return -1;
            }
        }
 
        //得到组织编码根据组织名称
        public static string get_ORGANIZATIONSNOByName(string HDataCenterName)
        {
            try
            {
                ClsSqlHelper oCN = new ClsSqlHelper();
                DataSet ds = oCN.RunProcReturn("select HNumber from h_v_CLD_ORGANIZATIONSList where Hname='" + HDataCenterName + "'", "h_v_CLD_ORGANIZATIONSList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return "";
                }
                else
                {
                    return  ClsPub.isStrNull(ds.Tables[0].Rows[0]["HNumber"]);
                }
            }
            catch (Exception e)
            {
                return "";
            }
        }
 
        //获取组织列表
        public static DataSet get_ORGANIZATIONSList()
        {
            try
            {
                ClsSqlHelper oCN = new ClsSqlHelper();
                return oCN.RunProcReturn("select * from h_v_CLD_ORGANIZATIONSList", "h_v_CLD_ORGANIZATIONSList");
            }
            catch (Exception e)
            {
                return null;
            }
        }
 
        //得到会计年份根据日期
        public static bool Sub_GetPeriodByDate(string sDate, ref int sYear, ref int sPeriod)
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                return true;
            }
        }
 
        //得到工资 会计年份根据日期
        public static bool Sub_GetPeriodByDate_Pay(string sDate, ref int sYear, ref int sPeriod)
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                return true;
            }
        }
 
 
        //得到K3会计年份根据日期
        public static bool Sub_GetPeriodByDateK3(string sDate, ref int sYear, ref int sPeriod)
        {
            DataSet Ds;
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from h_v_K3_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                return true;
            }
        }
 
        //得到当前会计年份 
        public static bool Sub_GetCurPeriod(ref int CurYear,ref int CurPeriod)
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                CurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                CurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                return true;
            }
        }
 
        //得到工资 当前会计年份 
        public static bool Sub_GetCurPeriod_Pay(ref int CurYear, ref int CurPeriod)
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                CurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                CurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                return true;
            }
        }
 
        //得到最大单据号
        public static string CreateBillCode(string BillCode, ref string sReturn, bool Add)
        {
            Int64 BillCodeMode;
            string Profix;
            Int64 Glida;
            Int32 CodeLen;
            string sBillNo = "";
            char c = Convert.ToChar("0");
            string sKjYear = DateTime.Today.Year.ToString();
            string sPeriod = DateTime.Today.Month.ToString();
            string sDay = DateTime.Today.Day.ToString();
            //得到单据号表 信息
            ClsSqlHelper oCn = new ClsSqlHelper();
            DataSet Ds = new DataSet();
            Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
            if (Ds.Tables[0].Rows.Count != 0)
            {
                BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString());
                Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString());
                Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString());
                CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString());
            }
            else
            {
                return "";
            }
            //
            string sStr;
            switch (BillCodeMode)
            {
                case 0:
                    switch (Glida)
                    {
                        case 0://纯流水号
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)");
                                sBillNo = Profix.Trim() + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'");
                            }
                            return sBillNo;
 
                        case 1://根据 YY年+MM月 日 + 流水号  生成单据号 (日 采用了 仓库的字段)
                            sKjYear = sKjYear.Substring(2, 2);
                            sPeriod = "0" + sPeriod;
                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                            sDay = "";
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sKjYear +  sPeriod  +  sDay  + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
                                sBillNo = Profix.Trim() + sKjYear +  sPeriod +  sDay + sStr + "1";
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
                            }
                            return sBillNo;
                        case 2:      //根据年+月+日  生成单据号
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
                                sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
                            }
                            return sBillNo;
                        case 3: //根据 乔一 (S + 年(23)+五位流水号)实例:S2300001
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''", "Gy_MaxNum");
                            sKjYear = sKjYear.Substring(2, 2);
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                Profix = Profix.Substring(0, 1);
                                sBillNo = Profix.Trim() + sKjYear + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
                                sBillNo = Profix.Trim() + sKjYear + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''");
                            }
                            return sBillNo;
                        default:
                            return sBillNo;
 
                    }
 
                case 1:
                    return sBillNo;
 
                default:
                    return sBillNo;
 
            }
            oCn.CnClose();
            oCn.CnDispose();
            oCn = null;
        }
 
        //得到最大单据号
        public static string CreateBillCode(string BillCode,string HOrgNumber,Int64 HOrgID,string HWhNumber, ref string sReturn, bool Add)
        {
            Int64 BillCodeMode;
            string Profix;
            Int64 Glida;
            Int32 CodeLen;
            string sBillNo = "";
            char c = Convert.ToChar("0");
            string sKjYear = DateTime.Today.Year.ToString();
            string sPeriod = DateTime.Today.Month.ToString();
            string sDay = DateTime.Today.Day.ToString();
            //得到单据号表 信息
            ClsSqlHelper oCn = new ClsSqlHelper();
            DataSet Ds = new DataSet();
            Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
            if (Ds.Tables[0].Rows.Count != 0)
            {
                BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString());
                Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString());
                Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString());
                CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString());
            }
            else
            {
                return "";
            }
            //
            string sStr;
            switch (BillCodeMode)
            {
                case 0:
                    switch (Glida)
                    {
                        case 0://纯流水号
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)");
                                sBillNo = Profix.Trim() + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'");
                            }
                            return sBillNo;
 
                        case 1://根据 YY年+MM月 日 + 流水号  生成单据号 (日 采用了 仓库的字段)
                            sKjYear = sKjYear.Substring(2, 2);
                            sPeriod = "0" + sPeriod;
                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                            sDay = "";
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
                                sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1";
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
                            }
                            return sBillNo;
                        case 2:      //根据年+月+日  生成单据号 (这功能 好像是作废了)
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
                                sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
                            }
                            return sBillNo;
                        case 3://根据 前缀+组织+ YY年+MM月   + 流水号  生成单据号  (组织 采用了 仓库的字段)
                            sKjYear = sKjYear.Substring(2, 2);
                            sPeriod = "0" + sPeriod;
                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                            
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + HOrgNumber + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + HOrgNumber + sKjYear + sPeriod  + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + HOrgNumber + "',1)");
                                sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1";
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + HOrgNumber + "'");
                            }
                            return sBillNo;
                        default:
                            return sBillNo;
 
                    }
 
                case 1:
                    return sBillNo;
 
                default:
                    return sBillNo;
 
            }
            oCn.CnClose();
            oCn.CnDispose();
            oCn = null;
        }
 
 
        //得到最大单据号2
        public static string CreateBillCode(string BillCode, ref string sReturn, bool Add,ClsSqlHelper oCn)
        {
            Int64 BillCodeMode;
            string Profix;
            Int64 Glida;
            Int32 CodeLen;
            string sBillNo = "";
            char c = Convert.ToChar("0");
            //得到单据号表 信息 
            DataSet Ds = new DataSet();
            Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
            if (Ds.Tables[0].Rows.Count != 0)
            {
                BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString());
                Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString());
                Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString());
                CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString());
            }
            else
            {
                return "";
            }
            //
            string sStr;
            switch (BillCodeMode)
            {
                case 0:
                    switch (Glida)
                    {
                        case 0:
                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum");
                            if (Ds.Tables[0].Rows.Count != 0)
                            {
                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
                                sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
                            }
                            else //插入新记录
                            {
                                sStr = new string(c, CodeLen - 1);
                                oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)");
                                sBillNo = Profix.Trim() + sStr + 1;
                            }
                            if (Add == true)
                            {
                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'");
                            }
                            return sBillNo;
 
                        case 1:
                            return sBillNo;
 
                        case 2:
                            return sBillNo;
 
                        default:
                            return sBillNo;
 
                    }
 
                case 1:
                    return sBillNo;
 
                default:
                    return sBillNo;
 
            }
 
        }
 
 
        //得到最大单据号 存储过程
        public static string CreateBillCode_Prod(string BillCode, ref string sReturn, bool Add)
        {
            try
            {
                string BillType = "";
                DataSet Ds;
                ClsSqlHelper oCn = new ClsSqlHelper();
                string  sBIllNO;
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillNo '" + BillCode + "'", "h_p_Xt_GetMaxBillNo");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sBIllNO = "ERROR";
                }
                else
                {
                    sBIllNO = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]);
                }
                oCn.CnClose();
                oCn.CnDispose();
                oCn = null;
                Ds = null;
                return sBIllNO;
            }
            catch (Exception e)
            {
                return "ERROR";
            }
        }
 
        //得到最大HINTERID 存储过程
        public static Int64 CreateBillID_Prod(string BillCode, ref string sReturn)
        {
            try
            {
                string BillType = "";
                DataSet Ds;
                ClsSqlHelper oCn = new ClsSqlHelper();
                Int64 lID;
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillID '" + BillCode + "'", "h_p_Xt_GetMaxBillID");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    lID = -1;
                }
                else
                {
                    lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HBillNo"]);
                }
                oCn.CnClose();
                oCn.CnDispose();
                oCn = null;
                Ds = null;
                return lID;
            }
            catch (Exception e)
            {
                return -2;
            }
        }
 
        //得到最大单据号 存储过程
        public static string CreateBillCode_SRMProd(string BillCode, ref string sReturn, bool Add)
        {
            try
            {
                string BillType = "";
                DataSet Ds;
                ClsSqlHelper_SRM oCn = new ClsSqlHelper_SRM();
                string sBIllNO;
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillNo '" + BillCode + "'", "h_p_Xt_GetMaxBillNo");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sBIllNO = "ERROR";
                }
                else
                {
                    sBIllNO = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]);
                }
                oCn.CnClose();
                oCn.CnDispose();
                oCn = null;
                Ds = null;
                return sBIllNO;
            }
            catch (Exception e)
            {
                return "ERROR";
            }
        }
 
 
 
        //得到最大HINTERID 存储过程
        public static Int64 CreateBillID_SRMProd(string BillCode, ref string sReturn)
        {
            try
            {
                string BillType = "";
                DataSet Ds;
                ClsSqlHelper_SRM oCn = new ClsSqlHelper_SRM();
                Int64 lID;
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillID '" + BillCode + "'", "h_p_Xt_GetMaxBillID");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    lID = -1;
                }
                else
                {
                    lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HBillNo"]);
                }
                oCn.CnClose();
                oCn.CnDispose();
                oCn = null;
                Ds = null;
                return lID;
            }
            catch (Exception e)
            {
                return -2;
            }
        }
 
        //得到最大HINTERID
        public static Int64 CreateBillID(string BillCode, ref string sReturn)
        {
            string BillType = "";
            DataSet Ds;
            ClsSqlHelper oCn = new ClsSqlHelper();
            Int64 lID;
            Ds = oCn.RunProcReturn("select * from Gy_BillNumber with (nolock) where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
            if (Ds.Tables[0].Rows.Count != 0)
            {
                lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["IDNow"].ToString());
                BillType = Ds.Tables[0].Rows[0]["BillType"].ToString().Trim();
            }
            else
            {
                lID = 0;
            }
            //同类型单据 自增1
            if (BillType.Trim() != "")
            {
                oCn.RunProc("update Gy_BillNumber set IDNow=IDNow+1 where BillType='" + BillType.Trim() + "'");
            }
            oCn.CnClose();
            oCn.CnDispose();
            oCn = null;
            Ds = null; 
            return lID;
        }
 
        //得到最大HINTERID
        public static Int64 CreateBillID(string BillCode, ref string sReturn,ClsSqlHelper oCn )
        {
            string BillType = "";
            DataSet Ds; 
            Int64 lID;
            Ds = oCn.RunProcReturn("select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
            if (Ds.Tables[0].Rows.Count != 0)
            {
                lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["IDNow"].ToString());
                BillType = Ds.Tables[0].Rows[0]["BillType"].ToString().Trim();
            }
            else
            {
                lID = 0;
            }
            //同类型单据 自增1
            if (BillType.Trim() != "")
            {
                oCn.RunProc("update Gy_BillNumber set IDNow=IDNow+1 where BillType='" + BillType.Trim() + "'");
            }
            Ds = null;
            return lID;
        }
 
 
        //判断是否存在权限,并写入日志
        public static bool Security_Log(string gnsy, int LogTF, bool Msg,string CurUserName)
        {
            //gnsy 功能索引,模块
            //usercode 当前用户代码
            //LogTF 1判断权限并写日志,2只写日志,3只判断权限
            //Msg 没有权限时 是否提示框
            string UserID = CurUserName;
            try
            {
                ClsSqlHelper oCn = new ClsSqlHelper();
                DataSet Ds = new DataSet();
                DataSet DsUser = new DataSet();
                DataSet DsJS = new DataSet();//角色
                long ModID = 0;
                bool HavRight = false;
                //找到模块权限
                Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    if (Msg == true)
                    {
                        MessageBox.Show("没有找到该功能模块!", "提示");
                    }
                    return false;
                }
                else
                {
                    ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());  //返回模块
                }
                if (LogTF == 1 || LogTF == 3)//需要判断权限
                {
                    //根据用户名称判断权限
                    DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl");
                    if (DsUser.Tables[0].Rows.Count == 0)
                    {
                        if (Msg == true)
                        {
                            MessageBox.Show("没有找到当前操作员!", "提示");
                        }
                        return false;
                    }
                    //根据用户名称判断权限
                    if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员
                    {
                        HavRight = true;
                    }
                    else
                    {
                        if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                        {
                            HavRight = true;
                        }
                        else
                        {
                            //获取用户组  并循环判断权限
                            //判断角色是否有权限
                            DsJS = oCn.RunProcReturn("select isnull(AuthorityID,'') AuthorityID from System_UserGroupinfo a inner join System_UserGroup b on a.GroupID=b.GroupID " + 
                                " Where a.USERID='" + UserID.Trim() + "'", "gy_czygl");
                            if (DsJS == null)
                            {
                                HavRight = false;
                            }
                            else
                            {
                                HavRight = false;
                                for (int i = 0; i < DsJS.Tables[0].Rows.Count; i++)
                                {
                                    if (ClsPub.isStrNull(DsJS.Tables[0].Rows[i]["AuthorityID"]).Length > ModID)
                                    {
                                        if (DsJS.Tables[0].Rows[i]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                                        {
                                            HavRight = true;
                                            break;
                                        }
                                    }
                                }
 
                            } 
                        }
                    }
                   
                    if (HavRight == false)
                    {
                        if (Msg == true)
                        {
                            MessageBox.Show("您没有权限,请与管理员联系!", "提示");
                        }
                    }
                }
                //需要写入日志
                if ((LogTF == 1 && HavRight) || LogTF == 2)
                {
                    Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy +","+ Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName);
                }
                return HavRight;
            }
            catch (Exception e)
            {
                if (Msg == true)
                {
                    MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示");
                }
                return false;
            }
        }
 
        public static bool Security_Log_second(string gnsy, int LogTF, bool Msg, string CurUserName)
        {
            //gnsy 功能索引,模块
            //usercode 当前用户代码
            //LogTF 1判断权限并写日志,2只写日志,3只判断权限
            //Msg 没有权限时 是否提示框
            string UserID = CurUserName;
            try
            {
                ClsSqlHelper oCn = new ClsSqlHelper();
                DataSet Ds = new DataSet();
                DataSet DsUser = new DataSet();
                DataSet DsJS = new DataSet();//角色
                long ModID = 0;
                bool HavRight = false;
                //找到模块权限
                Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    if (Msg == true)
                    {
                        return false;
                        //MessageBox.Show("没有找到该功能模块!", "提示");
                    }
                    return false;
                }
                else
                {
                    ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());  //返回模块
                }
                if (LogTF == 1 || LogTF == 3)//需要判断权限
                {
                    //根据用户名称判断权限
                    DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl");
                    if (DsUser.Tables[0].Rows.Count == 0)
                    {
                        if (Msg == true)
                        {
                            return false;
                            //MessageBox.Show("没有找到当前操作员!", "提示");
                        }
                        return false;
                    }
                    //根据用户名称判断权限
                    if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员
                    {
                        HavRight = true;
                    }
                    else
                    {
                        if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                        {
                            HavRight = true;
                        }
                        else
                        {
                            //获取用户组  并循环判断权限
                            //判断角色是否有权限
                            DsJS = oCn.RunProcReturn("select isnull(AuthorityID,'') AuthorityID from System_UserGroupinfo a inner join System_UserGroup b on a.GroupID=b.GroupID " +
                                " Where a.USERID='" + UserID.Trim() + "'", "gy_czygl");
                            if (DsJS == null)
                            {
                                HavRight = false;
                            }
                            else
                            {
                                HavRight = false;
                                for (int i = 0; i < DsJS.Tables[0].Rows.Count; i++)
                                {
                                    if (ClsPub.isStrNull(DsJS.Tables[0].Rows[i]["AuthorityID"]).Length > ModID)
                                    {
                                        if (DsJS.Tables[0].Rows[i]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                                        {
                                            HavRight = true;
                                            break;
                                        }
                                    }
                                }
 
                            }
                        }
                    }
 
                    if (HavRight == false)
                    {
                        if (Msg == true)
                        {
                            return false;
                            //MessageBox.Show("您没有权限,请与管理员联系!", "提示");
                        }
                    }
                }
                //需要写入日志
                if ((LogTF == 1 && HavRight) || LogTF == 2)
                {
                    Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName);
                }
                return HavRight;
            }
            catch (Exception e)
            {
                if (Msg == true)
                {
                    return false;
                    //MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示");
                }
                return false;
            }
        }
 
        //判断是都存在权限,并写入日志
        public static bool Security_Log(string gnsy, int LogTF, bool Msg, string CurUserName, ClsSqlHelper oCn)
        {
            //gnsy 功能索引,模块
            //usercode 当前用户代码
            //LogTF 1判断权限并写日志,2只写日志,3只判断权限
            //Msg 没有权限时 是否提示框
            string UserID = CurUserName;
            try
            { 
                DataSet Ds = new DataSet();
                DataSet DsUser = new DataSet();
                long ModID = 0;
                bool HavRight = false;
                Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("没有找到该功能模块!", "提示");
                    return false;
                }
                else
                {
                    ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (LogTF == 1 || LogTF == 3)//需要判断权限
                {
                    DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl");
                    if (DsUser.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("没有找到当前操作员!", "提示");
                        return false;
                    }
                    if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员
                    {
                        HavRight = true;
                    }
                    else
                    {
                        if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                        {
                            HavRight = true;
                        }
                        else
                        {
                            HavRight = false;
                        }
                    }
                    if (HavRight == false)
                    {
                        if (Msg == true)
                        {
                            MessageBox.Show("您没有权限,请与管理员联系!", "提示");
                        }
                    }
                }
                //需要写入日志
                if ((LogTF == 1 && HavRight) || LogTF == 2)
                {
                    Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName);
                }
                return HavRight;
            }
            catch (Exception e)
            {
                if (Msg == true)
                {
                    MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示");
                }
                return false;
            }
        }
 
        //判断是都存在权限,并写入日志
        public static bool Security_Log2(string gnsy, int LogTF, bool Msg, string CurUserName)
        {
            //gnsy 功能索引,模块
            //usercode 当前用户代码
            //LogTF 1判断权限并写日志,2只写日志,3只判断权限
            //Msg 没有权限时 是否提示框
            string UserID = CurUserName;
            try
            {
                ClsSqlHelper oCn = new ClsSqlHelper();
                DataSet Ds = new DataSet();
                DataSet DsUser = new DataSet();
                long ModID = 0;
                bool HavRight = false;
                Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("没有找到该功能模块!", "提示");
                    return false;
                }
                else
                {
                    ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (LogTF == 1 || LogTF == 3)//需要判断权限
                {
                    DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl");
                    if (DsUser.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("没有找到当前操作员!", "提示");
                        return false;
                    }
                    if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员
                    {
                        HavRight = true;
                    }
                    else
                    {
                        if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1")
                        {
                            HavRight = true;
                        }
                        else
                        {
                            HavRight = false;
                        }
                    }
                    if (HavRight == false)
                    {
                        if (Msg == true)
                        {
                            MessageBox.Show("您没有权限,请与管理员联系!", "提示");
                        }
                    }
                }
                //需要写入日志
                if ((LogTF == 1 && HavRight) || LogTF == 2)
                {
                    Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName);
                }
                return HavRight;
            }
            catch (Exception e)
            {
                if (Msg == true)
                {
                    MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示");
                }
                return false;
            }
        }
        //写入日志
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="UserID">无用</param>
        /// <param name="WorkList">操作日志</param>
        /// <param name="CurUserName">操作员</param>
        /// <returns></returns>
        public static bool Add_Log(string UserID, string WorkList, string CurUserName)
        {
            ClsSqlHelper oCn = new ClsSqlHelper();
            try
            {
                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                    "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','ERP系统','"+IPAddress+"','进入')"
                    );
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show("写入日志时发现错误,原因是:" + e.Message);
                return false;
            }
        }
        //写入日志
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="UserID">无用</param>
        /// <param name="WorkList">操作日志</param>
        /// <param name="CurUserName">操作员</param>
        /// <param name="oCn">连接</param>
        /// <returns></returns>
        public static bool Add_Log(string UserID, string WorkList, string CurUserName, ClsSqlHelper oCn)
        { 
            try
            {
                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                    "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','ERP系统','" + IPAddress + "','进入')"
                    );
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show("写入日志时发现错误,原因是:" + e.Message);
                return false;
            }
        }
        //得到会计期间
        public static string Sub_GetDateByPeriod(int sYear, int sPeriod)
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select  HBeginDate,HEndDate from xt_AcCountPeriod where HYear=" + sYear + " and HPeriod=" + sPeriod, "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return "";
            }
            else
            {
                return ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString(), 0) + "," + ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString(), 0);
            }
        }
        //得到服务器日期
        public static string GetServerDate(Int64 iType)
        {
            ClsSqlHelper oCn = new ClsSqlHelper();
            DataSet Ds = new DataSet();
            try
            {
                Ds = oCn.RunProcReturn("Select GetDate() as CurDate", "xt_xtgnb");
                switch (iType)
                {
                    case 0:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd");
                    case 1:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("HH:mm:ss");
                    case -1:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd HH:mm:ss");
                    default:
                        return "1900-01-01";
                }
            }
            catch (Exception e)
            {
                return "1900-01-01";
            }
        }
 
        //得到服务器日期
        public static string GetServerDate(Int64 iType, ClsSqlHelper oCn)
        { 
            DataSet Ds;
            try
            {
                Ds = oCn.RunProcReturn("Select GetDate() as CurDate", "xt_xtgnb");
                switch (iType)
                {
                    case 0:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd");
                    case 1:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("hh:mm:ss");
                    case -1:
                        return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd HH:mm:ss");
                    default:
                        return "1900-01-01";
                }
            }
            catch (Exception e)
            {
                return "1900-01-01";
            }
        }
 
        //根据模块名 返回 网格 信息
        public static string Fun_GetGridStrByModName(string KeyItem)
        {
            try
            {
                ClsSqlHelper oCn = new ClsSqlHelper();
                DataSet ds;
                ds = oCn.RunProcReturn("select top 1 HGridString from Xt_grdAlignment where HUserName='" + ClsPub.CurUserName + "' and HModName='" + KeyItem + "'", "Xt_grdAlignment");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return "没有找到!";
                }
                else
                {
                    return ClsPub.isStrNull(ds.Tables[0].Rows[0]["HGridString"]);
                }
            }
            catch (Exception e)
            {
                return "没有找到!";
            }
        }
 
        // 读取隐藏列datagridview  并设置 对齐方式
        /// <summary>
        /// 读取隐藏列datagridview  并设置 对齐方式
        /// </summary>
        /// <param name="oGrd"></param>
        /// <param name="KeyItem"></param>
        /// <param name="AppPath"></param>
        public static void HideGridView(DataGridView oGrd, string KeyItem, string AppPath)
        {
            int Cols;
            char c = Convert.ToChar(",");
            char s = Convert.ToChar("|");
            string sStr =ClsPub.Fun_GetGridStrByModName(KeyItem);
            if (sStr != "没有找到!")
            {
                string[] Col = sStr.Split(c);
                for (int i = 0; i < Col.Length; i++)
                {
                    if (i >= oGrd.ColumnCount)
                    {
                        break;
                    }
                    string[] sCol = Col[i].Split(s);
                    if (sCol.Length > 1)
                    {
                        if (ClsPub.isStrNull(sCol[1]) == "1")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;                           //隐藏列
                        }
                        else
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = true;                           //隐藏列
                        }
                        //h开头的隐藏
                        if (oGrd.Columns[ClsPub.isInt(sCol[0])].HeaderText != "")
                        {
                            if (oGrd.Columns[ClsPub.isInt(sCol[0])].HeaderText.Substring(0, 1).ToLower() == "h")
                            {
                                oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;
                            }
                        }
                        else
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;
                        }
                    }
                    //
                    if (sCol.Length > 2)
                    {
                        if (ClsPub.isStrNull(sCol[2]) == "L")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;                           // 
                        }
                        else if (ClsPub.isStrNull(sCol[2]) == "R")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;    // 
                        }
                        else if (ClsPub.isStrNull(sCol[2]) == "M")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;    // 
                        }
                        else
                        {
                            //;
                        }
                    }
                }
            }
        }
 
 
        // 读取隐藏列datagridview  并设置 对齐方式  从数据库读取
        public static void HideGridView(DataGridView oGrd, string KeyItem)
        {
 
            int Cols;
            char c = Convert.ToChar(",");
            char s = Convert.ToChar("|");
            string sStr = ClsIni.ReadIni("GridHide", KeyItem, AppPath + @"\" + "grdWidth.wyini");
            if (sStr != "没有找到!")
            {
                string[] Col = sStr.Split(c);
                for (int i = 0; i < Col.Length; i++)
                {
                    string[] sCol = Col[i].Split(s);
                    if (sCol.Length > 1)
                    {
                        if (ClsPub.isStrNull(sCol[1]) == "1")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;                           //隐藏列
                        }
                        else
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = true;                           //隐藏列
                        }
                    }
                    //
                    if (sCol.Length > 2)
                    {
                        if (ClsPub.isStrNull(sCol[2]) == "L")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;                           // 
                        }
                        else if (ClsPub.isStrNull(sCol[2]) == "R")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;    // 
                        }
                        else if (ClsPub.isStrNull(sCol[2]) == "M")
                        {
                            oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;    // 
                        }
                        else
                        {
                            //;
                        }
                    }
                }
            }
        }
 
 
        // 读取列宽datagridview
        public static void GetGridView(DataGridView oGrd, string KeyItem, string AppPath)
        {
            try
            {
                if (oGrd.RowCount <= 1)
                {
                    return;
                }
                int Cols;
                char c = Convert.ToChar(",");
                string sStr = ClsIni.ReadIni("GridSave", KeyItem, AppPath + @"\" + "grdWidth.wyini");
                if (sStr != "没有找到!")
                {
                    string[] ColWidth = sStr.Split(c);
                    if (oGrd.ColumnCount > ColWidth.Length)
                    {
                        Cols = ColWidth.Length;
                    }
                    else
                    {
                        Cols = oGrd.ColumnCount;
                    }
                    for (int i = 0; i < Cols; i++)
                    {
                        if (ClsPub.isInt(ColWidth[i]) > 500)
                        {
                            oGrd.Columns[i].Width = ClsPub.isInt(ColWidth[i]);
                        }
                        else
                        {
                            oGrd.Columns[i].Width = ClsPub.isInt(ColWidth[i]);
                        }
                    }
                }
            }
            catch(Exception e)
            {
                MessageBox.Show("设置列宽失败!" + e.Message);
            }
        }
        //保存列宽
        public static void SaveGridView(DataGridView oGrd, string KeyItem, string AppPath)
        {
            int i;
            string SaveStr = "";
            for (i = 0; i <= oGrd.ColumnCount - 1; i++)
            {
                if (i == 0)
                    SaveStr = oGrd.Columns[i].Width.ToString();
                else
                    SaveStr = SaveStr + "," + oGrd.Columns[i].Width.ToString();
            }
            ClsIni oIni = new ClsIni();
            if (ClsIni.WriteIni("GridSave", KeyItem, SaveStr, AppPath + @"\" + "grdWidth.wyini"))
                SaveStr = "";
        }
        //默认列宽
        public static void DefaultGridView(DataGridView oGrd)
        {
            for (int i = 0; i <= oGrd.ColumnCount - 1; i++)
            {
                oGrd.Columns[i].Width = 100;
            }
            
        }
       
        //审核代码合理性
        public static bool AllowNumber(string sCode)
        {
            sCode = sCode.Trim();
            if (sCode == "")
            {
                return true;
            }
            if (sCode.Substring(sCode.Length-1, 1) == ".")
            {
                return false;
            }
            if (sCode.Substring(0, 1) == ".")
            {
                return false;
            }
            if (sCode.Contains(".."))
            {
                return false;
            }
            return true;
        }
        //得到父级
        public static string GetParentCode(string sCode)
        {
            if (sCode.Contains("."))
            {
                for (int i =sCode.Length ; i > 0; i--)
                {
                    if (sCode.Substring(i-1, 1) == ".")
                    {
                        return sCode.Substring(0, i - 1);
                    }
                }
                return "";
            }
            else
                return "";
        }
        //得到短代码
        public static string GetShortNumber(string sCode)
        {
            if (sCode.Contains("."))
            {
                for (int i = sCode.Length; i > 0; i--)
                {
                    if (sCode.Substring(i - 1, 1) == ".")
                    {
                        return sCode.Substring(i,sCode.Length - i);
                    }
                }
                return sCode;
            }
            else
                return sCode;
        }
        //得到代码等级
        public static int GetLevel(string sCode)
        {
            return sCode.Length - (sCode.Replace(".", "").Length)+1;
        }
 
        //获取下拉框的 内码
        public static int GetIDByComboBox(string sCode)
        {
            if (sCode.Trim() == "")
            {
                return 0;
            }
            if (sCode.Contains("-"))
            {
                string[] s;
                s = sCode.Split(Convert.ToChar("-"));
                return ClsPub.isInt(s[0]);
            }
            else
            {
                return 0;
            }
        }
 
        //转化GRID中的 布尔型
        public static string GridToStr(object message)
        {
            try
            {
                if (Convert.ToString(message) == "-1" || Convert.ToString(message) == "1" || Convert.ToString(message) == "True")
                    return "1";
                else
                    return "0";
 
            }
            catch (Exception e)
            {
                return "0";
            }
        }
 
        //字符转为布尔
        /// <summary>
        /// 将是或者否转化为TRUE和FALSE
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static bool StringToBool(object b)
        {
            try
            {
                if (Convert.ToString(b) == "是")
                    return true;
                else
                    return false;
            }
            catch (Exception e)
            {
                return false;
            }
        }
 
        //转化GRID中的 布尔型
        public static bool GridToBool(object message)
        {
            try
            {
                if (Convert.ToString(message) == "-1" || Convert.ToString(message) == "1" || Convert.ToString(message) == "True")
                    return true;
                else
                    return false;
 
            }
            catch (Exception e)
            {
                return false;
            }
        }
 
        //判断是否是INT64
        public static Int64 isLong(object message)
        {
            try
            {
                return Convert.ToInt64(message);
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        //判断是否是INT32
        public static int isInt(object message)
        {
            try
            {
                return Convert.ToInt16(message);
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        //判断是否NULL
        public static string  isStrNull(object message)
        {
            try
            {
                if (message == null)
                {
                    return "";
                }
                else
                {
                    return message.ToString().Trim();
                }
            }
            catch (Exception e)
            {
                return "";
            }
        }
        //判断是否双精度
        public static double isDoule(object message)
        {
            try
            {
                return Convert.ToDouble(message);
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        ////判断是否双精度 并返回保留小数
        public static string isDoule(object message, int n)
        {
            try
            {
                return Convert.ToDouble(message).ToString("F"+n.ToString());
            }
            catch (Exception e)
            {
                return "";
            }
        }
        //布尔转为字符
        public static string BoolToString(object b)
        {
            try
            {
                if (Convert.ToBoolean(b))
                    return "1";
                else
                    return "0";
            }
            catch (Exception e)
            {
                return "0";
            }
           
        }
        //判断布尔
        public static bool isBool(object message)
        {
            try
            {
                return Convert.ToBoolean(message);
            }
            catch (Exception e)
            {
                return false;
            }
        }
        //判断是否 单精度
        public static Single isSingle(object message)
        {
            try
            {
                return Convert.ToSingle(message);
            }
            catch (Exception e)
            {
                return 0;
            }
        }
        //判断2个日期的大小
        /// <summary>
        /// 比较2个日期的大小
        /// </summary>
        /// <param name="Date1">日期1</param>
        /// <param name="Date2">日期2</param>
        /// <returns>-1 日期1小于日期2 0 相等 1 日期1大于日期2</returns>
        public static int TwoDateCompare(object Date1,object Date2)
        {
            string Date3 = ClsPub.isDate(Date1, -1);
            string Date4 = ClsPub.isDate(Date2,-1);
            if (DateTime.Parse(Date3) > DateTime.Parse(Date4))
            {
                return 1;
            }
            else if (DateTime.Parse(Date3) == DateTime.Parse(Date4))
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }
 
        //判断是否是 
        public static Enum_Color GridToColor(object message)
        {
            try
            {
                switch (Convert.ToInt64(message))
                {
                    case 0:
                        return Enum_Color.hx_Black;
                    case 16711680:
                        return Enum_Color.hx_Blue;
                    case 65280:
                        return Enum_Color.hx_Green;
                    case 255:
                        return Enum_Color.hx_Red;
                    case 16777215:
                        return Enum_Color.hx_Write;
                    case 65535:
                        return Enum_Color.hx_Yellow;
                    case 13425104:
                        return Enum_Color.hx_Control;
                    default:
                        return Enum_Color.hx_Black;
                }
            }
            catch (Exception e)
            {
                return Enum_Color.hx_Black;
            }
        }
        //双精度 四舍五入
        public static double ChinaRound(Single value, int decimals)
        {
            return Math.Round(value, decimals, MidpointRounding.AwayFromZero);
        }
 
        /// <summary>
        /// 返回 日期的字符串
        /// </summary>
        /// <param name="oVal"></param>
        /// <param name="sType">d日期dt日期时间t时间</param>
        /// <returns></returns>
        public static string DataTimeToStr(object oVal,string sType)
        {
            try
            {
                DateTime dt;
                if (sType == "d")
                {
                    if (oVal == null)
                    {
                        return "1900-01-01" ;
                    }
                    else
                    {
                        dt = Convert.ToDateTime(oVal);
                        return dt.ToShortDateString();
                    }
                }
                else if (sType == "dt")
                {
                    if (oVal == null)
                    {
                        return  "1900-01-01 00:00:00" ;
                    }
                    else
                    {
                        dt = Convert.ToDateTime(oVal);
                        return dt.ToShortDateString() + " " + dt.ToShortTimeString();
                    }
                }
                else if (sType == "t")
                {
                    if (oVal == null)
                    {
                        return "00:00:00";
                    }
                    else
                    {
                        dt = Convert.ToDateTime(oVal);
                        return dt.ToShortTimeString();
                    }
                }
                else
                {
                    if (oVal == null)
                    {
                        return  "1900-01-01" ;
                    }
                    else
                    {
                        dt = Convert.ToDateTime(oVal);
                        return dt.ToShortDateString();
                    }
                }
            }
            catch (Exception e)
            {
                return  "1900-01-01";
            }
        }
 
        //判断是否 是日期类型
        public static DateTime isDate(object oVal)
        {
            DateTime dt;
            if (oVal == null)
            {
                return Convert.ToDateTime("1900-01-01");
            }
            try
            {
                dt = Convert.ToDateTime(oVal);
                if (dt > Convert.ToDateTime("1900-01-01"))
                {
                    return Convert.ToDateTime(oVal);
                }
                else
                {
                    return Convert.ToDateTime("1900-01-01");
                }
            }
            catch (Exception e)
            {
                return Convert.ToDateTime("1900-01-01");
            }
        }
        //判断是否 是日期类型 并按格式返回
        /// <summary>
        /// 
        /// </summary>
        /// <param name="oVal"></param>
        /// <param name="n">-1 全部 0 日期 1 时间</param>
        /// <returns></returns>
        public static string isDate(object oVal,int n)
        {
            if (oVal == null)
            {
                if (n == -1)
                {
                    return Convert.ToDateTime("1900-01-01 00:00:00").ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (n == 0)
                {
                    return Convert.ToDateTime("1900-01-01").ToString("yyyy-MM-dd");
                }
                else
                {
                    return Convert.ToDateTime("1900-01-01 00:00:00").ToString("HH:mm:ss");
                }
            }
            try
            {
                if (n == -1)
                {
                    return Convert.ToDateTime(oVal).ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (n == 0)
                {
                    return Convert.ToDateTime(oVal).ToString("yyyy-MM-dd");
                }
                else
                {
                    return Convert.ToDateTime(oVal).ToString("HH:mm:ss");
                }
            }
            catch (Exception e)
            {
                if (n == -1)
                {
                    return Convert.ToDateTime("1900-01-01 00:00:00").ToString("yyyy-MM-dd hh:mm:ss");
                }
                else if (n == 0)
                {
                    return Convert.ToDateTime("1900-01-01").ToString("yyyy-MM-dd");
                }
                else
                {
                    return Convert.ToDateTime("1900-01-01 00:00:00").ToString("hh:mm:ss");
                }
            }
        }
          
         
        //转化为密码
        public static string StrToPsd(string Str)
        {
            string MmJm = "";
            int Zf = 0;
            for (int i = 0; i <= Str.Length - 1; i++)
            {
                Zf = ChrToAsc(Str.Substring(i, 1)) + ChrToAsc(Str.Substring(Str.Length - i - 1, 1)) + Str.Length + 1 + i;
                MmJm = MmJm + Zf.ToString().Trim();
            }
            return MmJm;
        }
 
        //字符转ASCII码:
        public static int ChrToAsc(string character)
        {
            if (character.Length == 1)
            {
                System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
                return (intAsciiCode);
            }
            else
            {
                throw new Exception("Character is not valid.");
            }
        }
 
        //ASCII码转字符:
        public static string AscToChr(int asciiCode)
        {
            if (asciiCode >= 0 && asciiCode <= 255)
            {
                System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                byte[] byteArray = new byte[] { (byte)asciiCode };
                string strCharacter = asciiEncoding.GetString(byteArray);
                return (strCharacter);
            }
            else
            {
                throw new Exception("ASCII Code is not valid.");
            }
        }
        //数据导出
        public static bool ExportGrid(Form oFrm)
        {
            foreach (Control ct in oFrm.Controls)
            {
                switch (ct.GetType().Name)
                {
                    case "AxVSFlexGrid":
                        try
                        {
                            //string s = "";
                            //AxVSFlex7.AxVSFlexGrid ogrd;
                            //ogrd = (AxVSFlex7.AxVSFlexGrid)ct;
                            ////选择路径
                            //SaveFileDialog oDlg = new SaveFileDialog();
                            //oDlg.Title = "数据导出";
                            //oDlg.Filter = "数据格式(*.XLS)|*.XLS|数据格式(*.CSV)|*.CSV";
                            //oDlg.ShowDialog();
                            //if (oDlg.FileName.Trim() != "")
                            //{
                            //    ogrd.SaveGrid(oDlg.FileName, VSFlex7.SaveLoadSettings.flexFileTabText, true);
                            //}
                            return true;
                        }
                        catch (Exception e)
                        {
                            return false;
                        }
                    default:
 
                        break;
                }
            }
            return false;
        }
        //拷贝表格
        public static bool CopyGrid(Form oFrm)
        {
            foreach (Control ct in oFrm.Controls)
            {
                switch (ct.GetType().Name)
                {
                    case "AxVSFlexGrid":
                        try
                        {
                            //string s = "";
                            //AxVSFlex7.AxVSFlexGrid ogrd;
                            //ogrd = (AxVSFlex7.AxVSFlexGrid)ct;
                            //s = ogrd.get_Cell(VSFlex7.CellPropertySettings.flexcpText, 0, 0, ogrd.Rows - 1, ogrd.Cols - 1).ToString();
                            //Clipboard.Clear();
                            //Clipboard.SetText(s);
                            return true;
                        }
                        catch (Exception e)
                        {
                            return false;
                        }
                    default:
 
                        break;
                }
            }
            return false;
        }
 
        //遍历子控件
        public static void ForEachControl(Control oControl, bool b)
        {
            foreach (Control ct in oControl.Controls)
            {
                if (ct.HasChildren == true)
                {
                    ForEachControl(ct, b);
                }
                else
                {
                    switch (ct.GetType().Name)
                    {
                        case "AxVSFlexGrid":
                            try
                            {
                                if (b)
                                {
                                    string s = "";
                                    //AxVSFlex7.AxVSFlexGrid ogrd;
                                    //ogrd = (AxVSFlex7.AxVSFlexGrid)ct;
                                    //s = ogrd.get_Cell(VSFlex7.CellPropertySettings.flexcpText, 0, 0, ogrd.Rows - 1, ogrd.Cols - 1).ToString();
                                    //Clipboard.Clear();
                                    //Clipboard.SetText(s);
                                    //MessageBox.Show("拷贝成功!");
                                    return;
                                }
                                else
                                {
                                    string s = "";
                                    //AxVSFlex7.AxVSFlexGrid ogrd;
                                    //ogrd = (AxVSFlex7.AxVSFlexGrid)ct;
                                    ////选择路径
                                    //SaveFileDialog oDlg = new SaveFileDialog();
                                    //oDlg.Title = "数据导出";
                                    //oDlg.Filter = "数据格式(*.XLS)|*.XLS|数据格式(*.CSV)|*.CSV";
                                    //oDlg.ShowDialog();
                                    //if (oDlg.FileName.Trim() != "")
                                    //{
                                    //    ogrd.SaveGrid(oDlg.FileName, VSFlex7.SaveLoadSettings.flexFileTabText, true);
                                    //}
                                    //MessageBox.Show("导出成功!");
                                    return;
                                }
                            }
                            catch (Exception e)
                            {
                                return;
                            }
                        default:
 
                            break;
                    }
                }
            }
        }
 
        
 
        //得到下查SQL
        public static string GetDownBillSql(ref string HBillType, ref string tRight, ref string FrmName, ref string FrmCaption, ref  string sViewName, string SourceType, long SourceMainID, long SourceSubID)
        {
            ClsSqlHelper oCn = new ClsSqlHelper();
            DataSet Ds;
            try
            {
                //得到下查单据 类型
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetDownBillSql " + SourceMainID.ToString() + "," + SourceSubID.ToString() + ",'" + SourceType.Trim() + "'", "gy_czygl");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    return "";
                }
                HBillType = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]);
                tRight = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRightName"]);
                FrmCaption = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HName"]);
                FrmName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HTemplate"]);
                sViewName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HViewName"]);
                return "select top 10000 * from " + sViewName + " Where 源单主内码=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceInterID"]) +
                    " and 源单子内码=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceEntryID"]) +
                    " and 源单类型='" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillType"]) + "'";
            }
            catch (Exception e)
            {
                MessageBox.Show("关联信息失败,原因: " + e.Message);
                return "";
            }
 
 
        }
 
        //得到上查SQL
        public static string GetUpBillSql(ref string HBillType, ref string tRight, ref string FrmName, ref string FrmCaption, ref  string sViewName, string SourceType, long SourceMainID, long SourceSubID)
        {
            ClsSqlHelper oCn = new ClsSqlHelper();
            DataSet Ds;
            try
            {
                //得到下查单据 类型
                Ds = oCn.RunProcReturn("exec h_p_Xt_GetUpBillSql " + SourceMainID.ToString() + "," + SourceSubID.ToString() + ",'" + SourceType.Trim() + "'", "gy_czygl");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    return "";
                }
                HBillType = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]);
                tRight = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRightName"]);
                FrmCaption = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HName"]);
                FrmName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HTemplate"]);
                sViewName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HViewName"]);
                return "select top 10000 * from " + sViewName + " Where hmainid=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HInterID"]) +
                    " and hsubid=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HEntryID"]) +
                    " and 单据类型='" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]) + "'";
            }
            catch (Exception e)
            {
                MessageBox.Show("关联信息失败,原因: " + e.Message);
                return "";
            }
        }
 
        //根据名字获取K3用户ID
        /// <summary>
        /// 根据名字获取K3用户ID
        /// </summary>
        /// <param name="HUserName"></param>
        /// <returns></returns>
        public static long GetUser_K3(string HUserName)
        {
            try
            {
                ClsSqlHelper oCn = new ClsSqlHelper();
                DataSet ds;
                long HK3UserID = 0;
                ds = oCn.RunProcReturn("select * from h_v_K3_User where hname='" + HUserName + "'", "xt_xtgnb");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                HK3UserID = ClsPub.isLong(ds.Tables[0].Rows[0]["hitemid"]);
                return HK3UserID;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
 
 
       //得到电脑名和IP
        public static void SetIPAddress()
        {
            IPAddress[] arrIPAddresses = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in arrIPAddresses)
            {
                if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
                {
                    IPAddress = ip.ToString();
                    ComputerName = System.Net.Dns.GetHostName();
                }
            }
        }
 
        //成本结账得到当前会计年份 
        public static bool Sub_CBGetCurPeriod()
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HCBEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                ClsPub.CBCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                ClsPub.CBCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                ClsPub.CBCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString());
                ClsPub.CBCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString());
                return true;
            }
        }
        //消费结账得到当前会计年份 
        public static bool Sub_XFGetCurPeriod()
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HXFEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                ClsPub.XFCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                ClsPub.XFCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                ClsPub.XFCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString());
                ClsPub.XFCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString());
                return true;
            }
        }
        //考勤结账得到当前会计年份 
        public static bool Sub_KQGetCurPeriod()
        {
            DataSet Ds = new DataSet();
            ClsSqlHelper oCn = new ClsSqlHelper();
            Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HKqEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            else
            {
                ClsPub.KQCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString());
                ClsPub.KQCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                ClsPub.KQCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString());
                ClsPub.KQCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString());
                return true;
            }
        }
 
        //设置 年 月 下拉框
        public static void Sub_SetYearPeriodCmb(ComboBox oYearCmb,ComboBox oPeriodCmb)
        {
            oYearCmb.Items.Clear(); 
            oYearCmb.Items.Add(DateTime.Today.Year - 10);
            oYearCmb.Items.Add(DateTime.Today.Year - 9);
            oYearCmb.Items.Add(DateTime.Today.Year - 8);
            oYearCmb.Items.Add(DateTime.Today.Year - 7);
            oYearCmb.Items.Add(DateTime.Today.Year - 6);
            oYearCmb.Items.Add(DateTime.Today.Year - 5);
            oYearCmb.Items.Add(DateTime.Today.Year - 4);
            oYearCmb.Items.Add(DateTime.Today.Year - 3);
            oYearCmb.Items.Add(DateTime.Today.Year - 2);
            oYearCmb.Items.Add(DateTime.Today.Year - 1);
            oYearCmb.Items.Add(DateTime.Today.Year);
            oYearCmb.Items.Add(DateTime.Today.Year + 1);
            oYearCmb.Items.Add(DateTime.Today.Year + 2);
            oYearCmb.Items.Add(DateTime.Today.Year + 3);
            oYearCmb.Items.Add(DateTime.Today.Year + 4);
            oYearCmb.SelectedIndex = 10;
            oPeriodCmb.Items.Clear();
            //oPeriodCmb.Items.Add("0");
            oPeriodCmb.Items.Add("1");
            oPeriodCmb.Items.Add("2");
            oPeriodCmb.Items.Add("3");
            oPeriodCmb.Items.Add("4");
            oPeriodCmb.Items.Add("5");
            oPeriodCmb.Items.Add("6");
            oPeriodCmb.Items.Add("7");
            oPeriodCmb.Items.Add("8");
            oPeriodCmb.Items.Add("9");
            oPeriodCmb.Items.Add("10");
            oPeriodCmb.Items.Add("11");
            oPeriodCmb.Items.Add("12");
            oPeriodCmb.Text = DateTime.Today.Month.ToString();
        }
 
        /// <summary>   
        /// DataTable转成Json    
        /// </summary>   
        /// <param name="jsonName"></param>   
        /// <param name="dt"></param>   
        /// <returns></returns>   
        public static string DataTableToJson(DataTable dt, string jsonName)
        {
            StringBuilder Json = new StringBuilder();
            if (string.IsNullOrEmpty(jsonName))
                jsonName = dt.TableName;
            Json.Append("{" + jsonName + ":[");
            //Json.Append("[");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Json.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        Type type = dt.Rows[i][j].GetType();
                        Json.Append("" + dt.Columns[j].ColumnName.ToString().ToLower() + ":" + StringFormat(dt.Rows[i][j].ToString(), type));
                        if (j < dt.Columns.Count - 1)
                        {
                            Json.Append(",");
                        }
                    }
                    Json.Append("}");
                    if (i < dt.Rows.Count - 1)
                    {
                        Json.Append(",");
                    }
                }
            }
            //Json.Append("]}");
            Json.Append("]}");
            Json.Replace(Convert.ToChar("\""), Convert.ToChar("\'"));
            return Json.ToString();
        }
 
 
        /// <summary>   
        /// 格式化字符型、日期型、布尔型   
        /// </summary>   
        /// <param name="str"></param>   
        /// <param name="type"></param>   
        /// <returns></returns>   
        private static string StringFormat(string str, Type type)
        {
            if (type == typeof(string))
            {
                str = String2Json(str);
                str = "\"" + str + "\"";
            }
            else if (type == typeof(DateTime))
            {
                str = "\"" + str + "\"";
            }
            else if (type == typeof(bool))
            {
                str = str.ToLower();
            }
            return str;
        }
 
 
 
 
        /// <summary>   
        /// 过滤特殊字符   
        /// </summary>   
        /// <param name="s"></param>   
        /// <returns></returns>   
        private static string String2Json(String s)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i++)
            {
                char c = s.ToCharArray()[i];
                switch (c)
                {
                    case '\"':
                        sb.Append("\\\""); break;
                    case '\\':
                        sb.Append("\\\\"); break;
                    case '/':
                        sb.Append("\\/"); break;
                    case '\b':
                        sb.Append("\\b"); break;
                    case '\f':
                        sb.Append("\\f"); break;
                    case '\n':
                        sb.Append("\\n"); break;
                    case '\r':
                        sb.Append("\\r"); break;
                    case '\t':
                        sb.Append("\\t"); break;
                    default:
                        sb.Append(c); break;
                }
            }
            return sb.ToString();
        }
 
        //拼接sql,按车间,工作中心查询
        public static string SpliceSQL(string czymc,string ListName)
        {
            DataSet ds;
            ClsSqlHelper oCN = new ClsSqlHelper();
            string sql = "";
 
            //判断是否有查询列表所有信息权限
            if (!Security_Log("Xt_List_All", 1, false, czymc))
            {
                //无
                switch (ListName)
                {
                    case "工艺路线列表":
                        sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
                        break;
                    case "生产订单列表":
                        sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
                        break;
                    case "工序派工单列表":
                        sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
                        break;
                    case "工序派工单明细列表":
                        sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
                        break;
                    case "工序汇报单列表":
                        sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
                        break;
                    case "生产车间工序报表":
                        sql = ",'" + czymc +"'";
                        break;
                    case "工序在制品报表":
                        sql = ",'" + czymc + "'";
                        break;
                    case "工序汇报日报表":
                        sql = ",'" + czymc + "'";
                        break;
                    case "计件工资报表":
                        sql = ",'" + czymc + "'";
                        break;
                    case "计件工资汇总报表":
                        sql = ",'" + czymc + "'";
                        break;
                }
                return sql;
            }
            else
            {
                //有
                return sql;
            }
 
            //ds = oCN.RunProcReturn("select * from gy_czygl where Czymc='" + czymc + "'", "gy_czygl");
            ////判断是否查询到相关用户信息
            //if (ds != null || ds.Tables[0].Rows.Count != 0)
            //{
            //    Int64 HManagerFlag = Convert.ToInt64(ds.Tables[0].Rows[0]["ManagerFlag"]);
            //    if (HManagerFlag == 1)//有管理员权限
            //    {
            //        return sql;
            //    }
            //    else //没有管理员权限
            //    {
            //        switch (ListName)
            //        {
            //            case "工艺路线列表":
            //                sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
            //                break;
            //            case "生产订单列表":
            //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
            //                break;
            //            case "工序派工单列表":
            //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
            //                break;
            //            case "工序派工单明细列表":
            //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
            //                break;
            //            case "工序汇报单列表":
            //                sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))";
            //                break;
            //        }                   
            //        return sql;
            //    }
            //}
            //else
            //{
            //    sql = "没有查询到相关用户信息";
            //    return sql;
            //}
        }
 
    }
}