curtis
17小時前 0756bf12d10cf1b7f78c571de0a9ad69cbaeb7ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
{ ==============================================================================
  方法名稱:Initialize
  引用相依:TDibGraphic
  方法描述:初始化元件狀態。註冊各類視窗與滑鼠事件處理函式(如 OnActivate, OnClick
            , OnCreate 等),並設定多項預設參數,包含 MpsKey、瀏覽窗邊界、檔案副檔名、
            案件與表單編號長度、去直線容忍值及切圖條碼類型。
============================================================================== }
procedure TCB_IMGPSScanX.Initialize;
begin
  inherited Initialize;
  OnActivate := ActivateEvent;
  OnClick := ClickEvent;
  OnCreate := CreateEvent;
  OnDblClick := DblClickEvent;
  OnDeactivate := DeactivateEvent;
  OnDestroy := DestroyEvent;
  OnKeyPress := KeyPressEvent;
  OnMouseEnter := MouseEnterEvent;
  OnMouseLeave := MouseLeaveEvent;
  OnPaint := PaintEvent;
  MpsKey := 'fbim';
  Seg := 3;  //瀏覽窗的邊界
  Ext := '.tif';
  SafePixel := 20;
  CaseIDLength := 16;  //案件編號長度 16碼   20170222 在用網頁參數來取代
  FormIDLength := 15;  //FormID長度 15碼    20170222 發現是用來辨識條碼用的
  ///DocNoLength := 8;   //DocNo長度 8碼 (1~8)  //20170222 發現沒用到就註解吧
  Bt :=4; //去直線時橫線判斷的容忍值
  CropBarcode := 'CC';//要切影像的條碼
end;
 
 
{ ==============================================================================
  方法名稱:Get_Active
  引用相依:
  方法描述:獲取元件的 Active 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_Active: WordBool;
begin
  Result := Active;
end;
 
 
{ ==============================================================================
  方法名稱:Get_AlignDisabled
  引用相依:
  方法描述:獲取元件的 AlignDisabled 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_AlignDisabled: WordBool;
begin
  Result := AlignDisabled;
end;
 
 
{ ==============================================================================
  方法名稱:Get_AlignWithMargins
  引用相依:
  方法描述:獲取元件的 AlignWithMargins 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_AlignWithMargins: WordBool;
begin
  Result := AlignWithMargins;
end;
 
 
{ ==============================================================================
  方法名稱:Get_AutoScroll
  引用相依:
  方法描述:獲取元件的 AutoScroll 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_AutoScroll: WordBool;
begin
  Result := AutoScroll;
end;
 
 
{ ==============================================================================
  方法名稱:Get_AutoSize
  引用相依:
  方法描述:獲取元件的 AutoSize 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_AutoSize: WordBool;
begin
  Result := AutoSize;
end;
 
 
{ ==============================================================================
  方法名稱:Get_AxBorderStyle
  引用相依:
  方法描述:獲取元件的 AxBorderStyle 邊框樣式。
============================================================================== }
function TCB_IMGPSScanX.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
  Result := Ord(AxBorderStyle);
end;
 
 
{ ==============================================================================
  方法名稱:Get_Caption
  引用相依:
  方法描述:獲取元件的標題文字。
============================================================================== }
function TCB_IMGPSScanX.Get_Caption: WideString;
begin
  Result := WideString(Caption);
end;
 
 
{ ==============================================================================
  方法名稱:Get_Color
  引用相依:
  方法描述:獲取元件的背景顏色。
============================================================================== }
function TCB_IMGPSScanX.Get_Color: OLE_COLOR;
begin
  Result := OLE_COLOR(Color);
end;
 
 
{ ==============================================================================
  方法名稱:Get_DockSite
  引用相依:
  方法描述:獲取元件的 DockSite 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_DockSite: WordBool;
begin
  Result := DockSite;
end;
 
 
{ ==============================================================================
  方法名稱:Get_DoubleBuffered
  引用相依:
  方法描述:獲獲取元件的 DoubleBuffered 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_DoubleBuffered: WordBool;
begin
  Result := DoubleBuffered;
end;
 
 
{ ==============================================================================
  方法名稱:Get_DropTarget
  引用相依:
  方法描述:獲取元件的 DropTarget 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_DropTarget: WordBool;
begin
  Result := DropTarget;
end;
 
 
{ ==============================================================================
  方法名稱:Get_Enabled
  引用相依:
  方法描述:獲取元件的啟用狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_Enabled: WordBool;
begin
  Result := Enabled;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ExplicitHeight
  引用相依:
  方法描述:獲取元件的明確高度。
============================================================================== }
function TCB_IMGPSScanX.Get_ExplicitHeight: Integer;
begin
  Result := ExplicitHeight;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ExplicitLeft
  引用相依:
  方法描述:獲取元件的明確左座標。
============================================================================== }
function TCB_IMGPSScanX.Get_ExplicitLeft: Integer;
begin
  Result := ExplicitLeft;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ExplicitTop
  引用相依:
  方法描述:獲取元件的明確頂座標。
============================================================================== }
function TCB_IMGPSScanX.Get_ExplicitTop: Integer;
begin
  Result := ExplicitTop;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ExplicitWidth
  引用相依:
  方法描述:獲取元件的明確寬度。
============================================================================== }
function TCB_IMGPSScanX.Get_ExplicitWidth: Integer;
begin
  Result := ExplicitWidth;
end;
 
 
{ ==============================================================================
  方法名稱:Get_Font
  引用相依:
  方法描述:獲取元件的字型。
============================================================================== }
function TCB_IMGPSScanX.Get_Font: IFontDisp;
begin
  GetOleFont(Font, Result);
end;
 
 
{ ==============================================================================
  方法名稱:Get_HelpFile
  引用相依:
  方法描述:獲取元件的說明檔路徑。
============================================================================== }
function TCB_IMGPSScanX.Get_HelpFile: WideString;
begin
  Result := WideString(HelpFile);
end;
 
 
{ ==============================================================================
  方法名稱:Get_KeyPreview
  引用相依:
  方法描述:獲取元件的鍵盤預覽狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_KeyPreview: WordBool;
begin
  Result := KeyPreview;
end;
 
 
{ ==============================================================================
  方法名稱:Get_MouseInClient
  引用相依:
  方法描述:獲取滑鼠是否在元件內部區域。
============================================================================== }
function TCB_IMGPSScanX.Get_MouseInClient: WordBool;
begin
  Result := MouseInClient;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ParentCustomHint
  引用相依:
  方法描述:獲取元件的 ParentCustomHint 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_ParentCustomHint: WordBool;
begin
  Result := ParentCustomHint;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ParentDoubleBuffered
  引用相依:
  方法描述:獲取元件的 ParentDoubleBuffered 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_ParentDoubleBuffered: WordBool;
begin
  Result := ParentDoubleBuffered;
end;
 
 
{ ==============================================================================
  方法名稱:Get_PixelsPerInch
  引用相依:
  方法描述:獲取元件的 PixelsPerInch 設定。
============================================================================== }
function TCB_IMGPSScanX.Get_PixelsPerInch: Integer;
begin
  Result := PixelsPerInch;
end;
 
 
{ ==============================================================================
  方法名稱:Get_PopupMode
  引用相依:
  方法描述:獲取元件的彈出視窗模式。
============================================================================== }
function TCB_IMGPSScanX.Get_PopupMode: TxPopupMode;
begin
  Result := Ord(PopupMode);
end;
 
 
{ ==============================================================================
  方法名稱:Get_PrintScale
  引用相依:
  方法描述:獲取元件的列印縮放比例。
============================================================================== }
function TCB_IMGPSScanX.Get_PrintScale: TxPrintScale;
begin
  Result := Ord(PrintScale);
end;
 
 
{ ==============================================================================
  方法名稱:Get_Scaled
  引用相依:
  方法描述:獲取元件的 Scaled 縮放狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_Scaled: WordBool;
begin
  Result := Scaled;
end;
 
 
{ ==============================================================================
  方法名稱:Get_ScreenSnap
  引用相依:
  方法描述:獲取元件的 ScreenSnap 狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_ScreenSnap: WordBool;
begin
  Result := ScreenSnap;
end;
 
 
{ ==============================================================================
  方法名稱:Get_SnapBuffer
  引用相依:
  方法描述:獲取元件的 SnapBuffer 設定。
============================================================================== }
function TCB_IMGPSScanX.Get_SnapBuffer: Integer;
begin
  Result := SnapBuffer;
end;
 
 
{ ==============================================================================
  方法名稱:Get_UseDockManager
  引用相依:
  方法描述:獲取元件是否使用 Dock 管理。
============================================================================== }
function TCB_IMGPSScanX.Get_UseDockManager: WordBool;
begin
  Result := UseDockManager;
end;
 
 
{ ==============================================================================
  方法名稱:Get_Visible
  引用相依:
  方法描述:獲取元件的顯示狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_Visible: WordBool;
begin
  Result := Visible;
end;
 
 
{ ==============================================================================
  方法名稱:Get_VisibleDockClientCount
  引用相依:
  方法描述:獲取元件的可見 Dock 客戶端數量。
============================================================================== }
function TCB_IMGPSScanX.Get_VisibleDockClientCount: Integer;
begin
  Result := VisibleDockClientCount;
end;
 
 
{ ==============================================================================
  方法名稱:_Set_Font
  引用相依:
  方法描述:設定元件的字型。
============================================================================== }
procedure TCB_IMGPSScanX._Set_Font(var Value: IFontDisp);
begin
  SetOleFont(Font, Value);
end;
 
 
{ ==============================================================================
  方法名稱:mode1Click
  引用相依:
  方法描述:切換至檢視模式 0(單頁顯示),呼叫 GoViewMode 更新佈局,並隱藏 Panel14 
            控制面版。
============================================================================== }
procedure TCB_IMGPSScanX.mode1Click(Sender: TObject);
begin
  VMode := 0;
  GoViewMode;
  //ScrollBar1Change(Self);
  Panel14.Visible := False;
end;
 
 
{ ==============================================================================
  方法名稱:mode2Click
  引用相依:
  方法描述:切換至檢視模式 1(兩頁顯示),呼叫 GoViewMode 更新佈局,並顯示 Panel14 
            控制面版。
============================================================================== }
procedure TCB_IMGPSScanX.mode2Click(Sender: TObject);
begin
  VMode := 1;
  GoViewMode;
  //ScrollBar1Change(Self);
  Panel14.Visible := True;
end;
 
 
{ ==============================================================================
  方法名稱:mode3Click
  引用相依:
  方法描述:切換至檢視模式 2(多頁網格顯示),呼叫 GoViewMode 更新佈局,並觸發捲軸變
            動以重新載入影像。
============================================================================== }
procedure TCB_IMGPSScanX.mode3Click(Sender: TObject);
begin
  VMode := 2;
  GoViewMode;
  ScrollBar1Change(Self);
end;
 
 
{ ==============================================================================
  方法名稱:mode4Click
  引用相依:
  方法描述:切換至檢視模式 3(自定義檢視模式),呼叫 GoViewMode 更新佈局,並觸發捲軸
            變動以重新載入影像。
============================================================================== }
procedure TCB_IMGPSScanX.mode4Click(Sender: TObject);
begin
  VMode := 3;
  GoViewMode;
  ScrollBar1Change(Self);
end;
 
 
{ ==============================================================================
  方法名稱:Set_AlignWithMargins
  引用相依:
  方法描述:設定元件的 AlignWithMargins 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_AlignWithMargins(Value: WordBool);
begin
  AlignWithMargins := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_AutoScroll
  引用相依:
  方法描述:設定元件的 AutoScroll 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_AutoScroll(Value: WordBool);
begin
  AutoScroll := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_AutoSize
  引用相依:
  方法描述:設定元件的 AutoSize 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_AutoSize(Value: WordBool);
begin
  AutoSize := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_AxBorderStyle
  引用相依:
  方法描述:設定元件的 AxBorderStyle 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
  AxBorderStyle := TActiveFormBorderStyle(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_Caption
  引用相依:
  方法描述:設定元件的標題文字。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Caption(const Value: WideString);
begin
  Caption := TCaption(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_Color
  引用相依:
  方法描述:設定元件的背景顏色。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Color(Value: OLE_COLOR);
begin
  Color := TColor(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_DockSite
  引用相依:
  方法描述:設定元件的 DockSite 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_DockSite(Value: WordBool);
begin
  DockSite := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_DoubleBuffered
  引用相依:
  方法描述:設定元件的 DoubleBuffered 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_DoubleBuffered(Value: WordBool);
begin
  DoubleBuffered := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_DropTarget
  引用相依:
  方法描述:設定元件的 DropTarget 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_DropTarget(Value: WordBool);
begin
  DropTarget := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_Enabled
  引用相依:
  方法描述:設定元件的啟用狀態。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Enabled(Value: WordBool);
begin
  Enabled := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_Font
  引用相依:
  方法描述:設定元件的字型。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Font(const Value: IFontDisp);
begin
  SetOleFont(Font, Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_HelpFile
  引用相依:
  方法描述:設定元件的說明檔路徑。
============================================================================== }
procedure TCB_IMGPSScanX.Set_HelpFile(const Value: WideString);
begin
  HelpFile := string(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_KeyPreview
  引用相依:
  方法描述:設定元件的鍵盤預覽狀態。
============================================================================== }
procedure TCB_IMGPSScanX.Set_KeyPreview(Value: WordBool);
begin
  KeyPreview := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_ParentCustomHint
  引用相依:
  方法描述:設定元件的 ParentCustomHint 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_ParentCustomHint(Value: WordBool);
begin
  ParentCustomHint := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_ParentDoubleBuffered
  引用相依:
  方法描述:設定元件的 ParentDoubleBuffered 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_ParentDoubleBuffered(Value: WordBool);
begin
  ParentDoubleBuffered := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_PixelsPerInch
  引用相依:
  方法描述:設定元件的 PixelsPerInch 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_PixelsPerInch(Value: Integer);
begin
  PixelsPerInch := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_PopupMode
  引用相依:
  方法描述:設定元件的彈出視窗模式。
============================================================================== }
procedure TCB_IMGPSScanX.Set_PopupMode(Value: TxPopupMode);
begin
  PopupMode := TPopupMode(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_PrintScale
  引用相依:
  方法描述:設定元件的列印縮放比例。
============================================================================== }
procedure TCB_IMGPSScanX.Set_PrintScale(Value: TxPrintScale);
begin
  PrintScale := TPrintScale(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_Scaled
  引用相依:
  方法描述:設定元件的 Scaled 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Scaled(Value: WordBool);
begin
  Scaled := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_ScreenSnap
  引用相依:
  方法描述:設定元件的 ScreenSnap 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_ScreenSnap(Value: WordBool);
begin
  ScreenSnap := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_SnapBuffer
  引用相依:
  方法描述:設定元件的 SnapBuffer 屬性。
============================================================================== }
procedure TCB_IMGPSScanX.Set_SnapBuffer(Value: Integer);
begin
  SnapBuffer := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_UseDockManager
  引用相依:
  方法描述:設定元件是否使用 Dock 管理。
============================================================================== }
procedure TCB_IMGPSScanX.Set_UseDockManager(Value: WordBool);
begin
  UseDockManager := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_Visible
  引用相依:
  方法描述:設定元件的顯示狀態。
============================================================================== }
procedure TCB_IMGPSScanX.Set_Visible(Value: WordBool);
begin
  Visible := Value;
end;
 
 
{ ==============================================================================
  方法名稱:N1Click
  引用相依:
  方法描述:彈出對話框要求使用者輸入目標頁碼,呼叫 MoveImage 將當前顯示的影像移動
            到指定的位置。
============================================================================== }
procedure TCB_IMGPSScanX.N1Click(Sender: TObject);
var
  mp:string;
begin
  mp := InputBox(_Msg('移動頁數'),_Msg('請輸入移入頁碼'),'');
  if (mp <> '') then
  begin
    MoveImage(DisplayPath+NowDocDir+'\',strtoint(mp));
  end;
end;
 
 
{ ==============================================================================
  方法名稱:N51Click
  引用相依:
  方法描述:切換至檢視模式 4,呼叫 GoViewMode 更新佈局,並觸發捲軸變動以重新載入影
            像。
============================================================================== }
procedure TCB_IMGPSScanX.N51Click(Sender: TObject);
begin
  VMode := 4;
  GoViewMode;
  ScrollBar1Change(Self);
end;
 
 
{ ==============================================================================
  方法名稱:Panel11DblClick
  引用相依:
  方法描述:Panel11 的連按兩下事件,目前實作已註解掉。
============================================================================== }
procedure TCB_IMGPSScanX.Panel11DblClick(Sender: TObject);
begin
  // Button3.Visible := not Button3.Visible;
  //Button4.Visible := not Button4.Visible;
  //self.FCustDocYN := 'N';
end;
 
 
{ ==============================================================================
  方法名稱:Panel1DblClick
  引用相依:
  方法描述:Panel1 的連按兩下事件,用於切換 Button1 與 Button2 的顯示狀態。
============================================================================== }
procedure TCB_IMGPSScanX.Panel1DblClick(Sender: TObject);
begin
  Button1.Visible := not Button1.Visible;
  Button2.Visible := not Button2.Visible;
end;
 
 
{ ==============================================================================
  方法名稱:Panel9Resize
  引用相依:
  方法描述:當 Panel9 大小改變時,呼叫 GoViewMode 重新調整影像佈局。
============================================================================== }
procedure TCB_IMGPSScanX.Panel9Resize(Sender: TObject);
begin
  GoViewMode;
end;
 
 
{ ==============================================================================
  方法名稱:DocNoIsExistImg
  引用相依:FileExists, LoadFromFile
  方法描述:檢查指定的文件目錄路徑下是否存在影像檔案。首先讀取目錄中的 Context.da
            t 檔案,接著遍歷清單中的所有檔名並檢查實際檔案是否存在。若發現任何一個
            影像檔案存在則回傳 False(表示非空),否則回傳 True。
============================================================================== }
function TCB_IMGPSScanX.DocNoIsExistImg(DocNopath:String):boolean;
var
  i:integer;
  ST:TStringList;
begin
  Result:=False;
  ST:=TStringList.Create;
  if FileExists(DocNopath+'\Context.dat') then   /////20190319 Hong 當有空的Docno目錄時會掛掉,增加這行
    ST.loadFromfile(DocNopath+'\Context.dat');
  for I := 0 to ST.Count - 1 do
  begin
    if ISExistImg(DocNopath+ST.Strings[i]) then
    begin
 
      Result:=False;
      Exit;
      Break;
    end;
  end;
  Result:=True;
 
 
end;
 
 
{ ==============================================================================
  方法名稱:_DelTreeForExistImg
  引用相依:_DelTree
  方法描述:存根方法,目前未包含具體實作邏輯。
============================================================================== }
procedure TCB_IMGPSScanX._DelTreeForExistImg(ASourceDir:String);
var
  i:integer;
  ST:TStringList;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:ScrollBar1Change
  引用相依:
  方法描述:捲軸變動處理,目前實作已透過 Exit 暫時停用。
============================================================================== }
procedure TCB_IMGPSScanX.ScrollBar1Change(Sender: TObject);
begin
  Exit;
  If (TreeView1.Selected = MyTreenode1) or (TreeView1.Selected.ImageIndex = 6) Then
  begin
    view_image_FormCode(DisplayPath,'ShowAll',ScrollBar1.Position,1);
  end
  Else IF (TreeView1.Selected = MyTreenode2) then
  begin
    view_image_FormCode(DisplayPath,NowDocNo,ScrollBar1.Position,1);
  end
  Else if (TreeView1.Selected = MyTreenode3) then
  begin
    view_image_FormCode(DisplayPath,NowFormCode,ScrollBar1.Position,1);
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:ActiveFormKeyUp
  引用相依:
  方法描述:處理 ActiveForm 按鍵放開事件。當文字輸入框取得焦點且有選取影像時,攔截
            上下方向鍵並將其轉化為 PriorPage 或 NextPage 翻頁操作,並同步滾動捲軸
            。
============================================================================== }
procedure TCB_IMGPSScanX.ActiveFormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Edit1.Focused then
  begin
    if selectISB = nil then Exit;
 
    if (Key =VK_UP) then
    begin
      PriorPage(SelectPage);
      if (SelectISB.Parent.Top-4) < 0 then
       scrollBox1.VertScrollBar.Position := scrollBox1.VertScrollBar.Position + SelectISB.Parent.Top-4;
 
      //ISBClick(TImageScrollBox(FindComponent(ISBName+'1')));
    end;
    if (Key =VK_Down) then
    begin
      NextPage(SelectPage);
      if SelectISB.Parent.Top+SelectISB.Parent.Height+4 > scrollBox1.Height  then
        ScrollBox1.VertScrollBar.Position := scrollBox1.VertScrollBar.Position + (SelectISB.Parent.Top+SelectISB.Parent.Height-ScrollBox1.Height+8);
        //scrollBox1.VertScrollBar.ScrollPos := SelectISB.Parent.Top+SelectISB.Parent.Height;
      //ISBClick(TImageScrollBox(FindComponent(ISBName+'2')));
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:AddAttFileLBClick
  引用相依:CopyFile, FileExists
  方法描述:處理「加入附加電子檔」按鈕點擊。開啟檔案對話框選取多個 PDF 檔案,支援覆
            蓋檢查。執行 CopyFile 將檔案複製到案件目錄下,並呼叫 SetAttContextList
             更新附加檔案清單後載入顯示。
============================================================================== }
procedure TCB_IMGPSScanX.AddAttFileLBClick(Sender: TObject);
var
  i : Integer;
  Addfile : String;
begin
  OpenDialog1.Filter := 'PDF files|*.pdf';
  OpenDialog1.Options := [ofAllowMultiSelect];
  if OpenDialog1.Execute then
  begin
    ShowText :=_Msg('檔案加入中,請稍候');
    DataLoading(True,True);
    for i := 0 to OpenDialog1.Files.Count - 1 do
    begin
      AddFile := HTTPEncode(UTF8Encode(ExtractFileName(OpenDialog1.Files.Strings[i])));
      if FileExists(ImageSavePath+NowCaseno+'\'+AddFile) then
      begin
        if Messagedlg(Format(_Msg('%s己存在,是否覆蓋??'),[Addfile]),mtconfirmation,[mbyes,mbcancel],0) = mrcancel Then
          Continue;
        SetAttContextList('D',-1,NowCaseno,AddFile);
      end;
      // AttFileGB.Visible := True; //附加電子檔窗   //20120207楊玉說不在這加電子檔先拿掉
      //   Splitter2.Visible := True;
      CopyFile(Pchar(OpenDialog1.Files.Strings[i]),Pchar(ImageSavePath+NowCaseno+'\'+AddFile),False);
      SetAttContextList('A',-1,NowCaseno,AddFile);
      LoadAttFile(NowCaseno);
    end;
  end;
  DataLoading(False,False);
end;
 
 
{ ==============================================================================
  方法名稱:AddCredit1RGClick
  引用相依:
  方法描述:處理信用註記點擊,更新 Case_loandoc 狀態並寫入索引檔。
============================================================================== }
procedure TCB_IMGPSScanX.AddCredit1RGClick(Sender: TObject);
begin
  if DisplayPath <> '' then
  begin
    Case AddCredit1RG.ItemIndex of
      -1:Case_loandoc := '';
       0:Case_loandoc := 'Y';
       1:Case_loandoc := 'N';
    end;
    WriteCaseIndex(DisplayPath);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:BtnMouseEnter
  引用相依:
  方法描述:當滑鼠進入按鈕區域時,顯示該按鈕的 Hint 文字提示。
============================================================================== }
procedure TCB_IMGPSScanX.BtnMouseEnter(Sender: TObject);
begin
  AddToolTip(TBitBtn(Sender).Handle,nil,0,Pchar(TBitBtn(Sender).Hint),nil,0,0);
end;
 
 
{ ==============================================================================
  方法名稱:Button3Click
  引用相依:initkscan
  方法描述:工程師測試用按鈕。用於顯示當前系統環境變數與參數狀態,包含伺服器 URL、
            案件資訊、權限、DPI 設定及各類長度限制,最後重新載入影像檔案。
============================================================================== }
procedure TCB_IMGPSScanX.Button3Click(Sender: TObject);
begin
  //Showmessage(CreateDocNo_Info(NowCaseNo)+#13+'******'+#13+CreateCustDocNo_Info(NowCaseNo));
  //Showmessage(NowSelectFileList.Text);
  //SetIn_WH_DocNo;
  //CreateIn_WH(self.NowCaseno);
  //Create_Cust_DocDir(NowCaseNo);
  //Showmessage(self.GetDocNoDir(self.DisplayPath,'111'));
  //Case2upload(NowCaseNo);
  //mkdir(DisplayPath+'Test\');
  //Download2Case(DisplayPath+'Upload\',DisplayPath+'Test\');
  //CreateFormID_FormName(DisplayPath);  //產生FormID_FormName.dat
  //CreateDocNo_DocName(DisplayPath); //產生DocNo_Name.dat
  //Showmessage(CreateDocNo_Info(DisplayPath));  //產生 Docno,份數,頁數;Docno,份數,頁數 的回傳字串
  //lb1.Caption:='AAAAAAAAAAA';
  //Showmessage(CreateDocnoFrom_Info(NowCaseno));
  //Showmessage(self.CreateCustDocNoFrom_Info(NowCaseno));
  //ShowMessage('FMaxUploadSize='+FMaxUploadSize);
        //initkscan;
    showmessage('FUrl='+FUrl+#10#13+
    'FCaseID='+FCaseID+#10#13+
    'FMode='+FMode+#10#13+
    'FModeName='+FModeName+#10#13+
    'FWork_no='+FWork_no+#10#13+
    'FUserID='+FUserID+#10#13+
    'FUserName='+FUserName+#10#13+
    'FUserUnit='+FUserUnit+#10#13+
    'FData='+FData+#10#13+
    'FVerify='+FVerify+#10#13+
    'FReWrite='+FReWrite+#10#13+
    'FLanguage='+FLanguage+#10#13+
    'FLoanDoc_Value='+FLoanDoc_Value+#10#13+
    'FLoanDoc_Enable='+FLoanDoc_Enable+#10#13+
    'FUseProxy='+FUseProxy+#10#13+
    'FC_DocNoList='+FC_DocNoList+#10#13+
    'FC_DocNameList='+FC_DocNameList+#10#13+
    'FFixFileList='+FFixFileList+#10#13+
    'FIs_In_Wh='+FIs_In_Wh+#10#13+
    'FOldCaseInfo='+FOldCaseInfo+#10#13+
    'FPrintyn='+FPrintyn+#10#13+
    'FIs_OldCase='+FIs_OldCase+#10#13+
    'FCustDocYN='+FCustDocYN);
  ShowMessage('FImgDPI='+IntToStr(FImgDPI)+#10#13+
    'FScanColor='+    IntToStr(FScanColor)+#10#13+
    'FFileSizeLimit='+  IntToStr(FFileSizeLimit)  +#10#13+
    'FCaseNoLength='+ IntToStr(FCaseNoLength)   +#10#13+
    'FImgDelete='+    FImgDelete+#10#13+
    'FIsExternal='+    FIsExternal+#10#13+
    'FWH_category='+FWH_category+
    'FCheck_main_form='+    FCheck_main_form+#10#13+
    'FMaxUploadSize='+FMaxUploadSize);
    //FImgDelete:='Y';
  LoadImgFile;
 { ShowMessage('UpLPoint='+IntToStr(UpLPoint.X)+','+IntToStr(UpLPoint.Y)+#10#13+
    'UpRPoint='+IntToStr(UpRPoint.X)+','+IntToStr(UpRPoint.Y)+#10#13+
    'DownLPoint='+IntToStr(DownLPoint.X)+','+IntToStr(DownLPoint.Y)+#10#13+
    'DownRPoint='+IntToStr(DownRPoint.X)+','+IntToStr(DownRPoint.Y));
  }
end;
 
 
{ ==============================================================================
  方法名稱:Button4Click
  引用相依:
  方法描述:工程師測試用按鈕。用於傾印內部多個 TStringList 與 Record 資料,包含 OM
            R 錯誤資訊、表單與檢核規則清單、範本與已存在影像清單等,用於除錯。
============================================================================== }
procedure TCB_IMGPSScanX.Button4Click(Sender: TObject);
var
  i:integer;
  str:String;
begin
  //Showmessage(self.Doc_Inf_List.Text);
  //LoadImgFile;
  //LoadImgFile1;
  //ISB1.MouseMode:=mmAmplifier;
 
  str:='';
  for I := 1 to 11 do // 看 OMRErrInfo 的內容
  begin
  str:=str+BoolToStr(OMRErrInfo[i].Display,true)+','
          +BoolToStr(OMRErrInfo[i].Ignore,true)+','+OMRErrInfo[i].Info+','
          +OMRErrInfo[i].Mode+#10#13;
  end;
  ShowMessage('OMRErrInfo='+str);
  ShowMessage('Doc_Inf_List='+Doc_Inf_List.Text);
  ShowMessage('DM_FORM_INF_List='+DM_FORM_INF_List.Text) ;
  ShowMessage('FORM_INF_List='+FORM_INF_List.Text)       ;
  ShowMessage('CHECK_RULE_INF_List='+CHECK_RULE_INF_List.Text)  ;
  ShowMessage('MEMO_INF_List='+MEMO_INF_List.Text)         ;
  ShowMessage('WORK_INF_List='+WORK_INF_List.Text)          ;
  ShowMessage('LASTEST_FORM_INF_List='+LASTEST_FORM_INF_List.Text)   ;
  ShowMessage('SampleFormIDList='+SampleFormIDList.Text);
  ShowMessage('ExistImgList='+ExistImgList.Text);
  ShowMessage('LastInitFormidList='+LastInitFormidList.Text);
  ShowMessage('IN_WH_DocNoList='+IN_WH_DocNoList.Text);
 
//  SampleFormIDList.Add('31A00101011706A');
//  SampleFormIDList.Add('31A00101021706A');
//  SampleFormIDList.Add('31A00101031706A');
end;
 
 
{ ==============================================================================
  方法名稱:Button5Click
  引用相依:IIS_Ftp, SetFtpInfo
  方法描述:測試 FTP 上傳功能。連線 FTP 後嘗試將特定的 PDF 檔案上傳至伺服器路徑。
============================================================================== }
procedure TCB_IMGPSScanX.Button5Click(Sender: TObject);
begin
  GetftpInfo(NowCaseno,'upload');
  SetFtpInfo;
  IIS_Ftp.FtpsConnect;
 
  IIS_Ftp.FtpsToMain(FFtpExtraPath,NowCaseno+'.pdf','d:\1.pdf',display1);
end;
 
 
{ ==============================================================================
  方法名稱:Button6Click
  引用相依:FJpgCompression, IIS_Ftp, Rotate, Scanner, SetFtpInfo
  方法描述:測試 FTP 下載功能。連線 FTP 後嘗試從伺服器下載 ZIP 案件檔至本地。
============================================================================== }
procedure TCB_IMGPSScanX.Button6Click(Sender: TObject);
begin
  GetftpInfo(NowCaseno,'download');
  SetFtpInfo;
  IIS_Ftp.FtpsConnect;
  IIS_Ftp.FtpsCWD(IIS_Ftp.FtpPath);
  IIS_Ftp.FtpsReceive(NowCaseNo+'.zip','d:\'+NowCaseNo+'.zip');
 
 
end;
 
 
{ ==============================================================================
  方法名稱:ExportBtClick
  引用相依:En_DecryptionStr_Base64, FileExists, SaveToFile, dnFile, dnFile_Get
  方法描述:處理「匯出授權檔」按鈕點擊。透過 HTTPS 下載掃瞄與檢視用的 .lic 授權檔案
            。將授權檔連同加密的 mps.dat 檔案打包成帶有密碼保護的 mps.zip 壓縮包,
            完成後清理暫存檔並提示路徑。
============================================================================== }
procedure TCB_IMGPSScanX.ExportBtClick(Sender: TObject);
var
  SendData : String;
  EnCodeDateTime : String;
  S : TStringlist;
  SFileName,VFileName : String;
begin
  SFileName := En_DecryptionStr_Base64('E','MPSLIC_SCAN.lic','9338430');
  VFileName := En_DecryptionStr_Base64('E','MPSLIC_VIEW.lic','9338430');
  IIS_File2Web.S_LicEnName := SFileName;
  IIS_File2Web.V_LicEnName := VFileName;
 
  /////下載MPSLIC_SCAN.lic //////
  EnCodeDateTime := En_DecryptionStr_Base64('E',ServerDate+GetBalance2Time(Balance),Mpskey);
 
 
  //SendData := 'checktime='+EnCodeDateTime+'&workno=CW&formid=MPSLIC_SCAN.lic'+'&mode=sample';
  //if not dnFile(HTTPSClient,Furl,'servlet/CWC03',SendData,LngPath+SFileName,FReWrite,Memo1,False,DownImgStatus) then
  SendData:='data='+HTTPEncode(UTF8Encode(FData))+'&verify='+FVerify+'&work_no=PLN&file=MPSLIC_SCAN.lic';
  if not dnFile_Get(HTTPSClient,Furl,'service/imgpsc/IMGPSC04/sample',SendData,LngPath+SFileName,FReWrite,Memo1,False,DownImgStatus) then
  begin
    Showmessage(_Msg('檢查註冊檔案時,網路發生錯誤!!')+_Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason);
    Exit;
  end;
  /////下載MPSLIC_SCAN.lic /////
 
  /////下載MPSLIC_VIEW.lic //////
  EnCodeDateTime := En_DecryptionStr_Base64('E',ServerDate+GetBalance2Time(Balance),Mpskey);
  //SendData := 'checktime='+EnCodeDateTime+'&workno=CW&formid=MPSLIC_VIEW.lic'+'&mode=sample';  //這裡改成必傳CW 20121212
  //if not dnFile(HTTPSClient,Furl,'service/slic/SLIC04/sample',SendData,LngPath+VFileName,FReWrite,Memo1,False,DownImgStatus) then
  SendData:='data='+HTTPEncode(UTF8Encode(FData))+'&verify='+FVerify+'&work_no=PLN&file=MPSLIC_VIEW.lic';
  if not dnFile_Get(HTTPSClient,Furl,'service/imgpsc/IMGPSC04/sample',SendData,LngPath+VFileName,FReWrite,Memo1,False,DownImgStatus) then
  begin
    Showmessage(_Msg('檢查註冊檔案時,網路發生錯誤!!')+_Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason);
    Exit;
  end;
  /////下載MPSLIC_VIEW.lic /////
 
  ////壓zip/////
  S := TStringlist.Create;
  try
    S.Add(En_DecryptionStr_Base64('E',GetDate,'9338430'));
    S.Add(SFileName);
    S.Add(VFileName);
    S.SaveToFile(LngPath+'mps.dat');
    S.Clear;
    S.Add(LngPath+'mps.dat');
    S.Add(LngPath+SFileName);
    S.Add(LngPath+VFileName);
    if FileExists(LngPath+'mps.zip') then
      DeleteFile(LngPath+'mps.zip');
    ExecuteZip_Pwd(LngPath+'mps.zip',LngPath,S,False,False,'9338430');
 
  finally
  S.Free;
  DeleteFile(LngPath+SFileName);
  DeleteFile(LngPath+VFileName);
  DeleteFile(LngPath+'mps.dat');
  end;
  ////壓zip//////
  Showmessage(_Msg('匯出完成,匯出檔案:')+LngPath+'mps.zip');
end;
 
 
{ ==============================================================================
  方法名稱:ImportBtClick
  引用相依:En_DecryptionStr_Base64, FileExists, LoadFromFile, RenameFile, Str2D
            ir, _DelTree, upFile
  方法描述:處理「匯入授權檔」按鈕點擊。選取 mps.zip 授權包後進行解壓與過期驗證。驗
            證通過後對授權檔執行重新命名,並透過 upFile 函式逐一上傳至伺服器範本
            目錄,過程中會嚴格檢查 Session 與回傳狀態。
============================================================================== }
procedure TCB_IMGPSScanX.ImportBtClick(Sender: TObject);
var
  SendData : String;
  EnCodeDateTime : String;
  S : TStringlist;
  SFileName,VFileName : String;
  OpenDialog1 : TOpenDialog;
  ZipPath : String;
  ZipFile,ZipName : String;
  LicName : String;
  i : Integer;
begin
  OpenDialog1 := TOpenDialog.Create(self);
  S := TStringlist.Create;
  try
    OpenDialog1.Filter := 'Zip files (*.zip)|*.ZIP';
    if OpenDialog1.Execute then
    begin
      ZipFile:= ExtractFileName(OpenDialog1.FileName);
      ZipName := Copy(ZipFile,1,length(ZipFile)-length(ExtractFileExt(OpenDialog1.FileName)));
      ZipPath := LngPath+ZipName+'\';
 
      str2dir(ZipPath);
      if not ExecuteUnZip_Pwd(OpenDialog1.FileName,ZipPath,False,'9338430') then
        Showmessage(_Msg('無法解壓縮'));
      if not FileExists(ZipPath+'mps.dat') then
      begin
        Showmessage(_Msg('格式不符,無法匯入'));
        Exit;
      end;
      S.LoadFromFile(ZipPath+'mps.dat');
      if (En_DecryptionStr_Base64('D',S.Strings[0],'9338430')<> ServerDate) then
      begin
        Showmessage(_Msg('檔案過期,無法匯入'));
        Exit;
      end;
 
      for i := 1 to S.Count -1 do
      begin
        LicName := En_DecryptionStr_Base64('D',S.Strings[i],'9338430');
        RenameFile(ZipPath+S.Strings[i],ZipPath+LicName);
        if (LicName = 'MPSLIC_SCAN.lic') or (LicName = 'MPSLIC_VIEW.lic') then
 
        /////上傳MPSLICXXXX.lic ////
        //if not upFile(HTTPSClient,FUrl,'servlet/CWC04','formid='+LicName+'@workno=CW@mode=sample','file',ZipPath+LicName,FReWrite,Memo1,False) then
        //begin
        SendData := 'data='+HTTPEncode(UTF8Encode(FData))+'&verify='+FVerify+'&work_no=PLN&file_name='+LicName;
        if not upFile(HTTPSClient,FUrl,'service/imgpsc/IMGPSC02/sample',SendData,'file',ZipPath+LicName,FReWrite,Memo1,False) then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_MSg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason+')');
          DataLoading(False,False);
          Exit;
        end;
        if memo1.Lines.Strings[0] = '1' then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_Msg('錯誤原因:')+memo1.Lines.Strings[1]);
          DataLoading(False,False);
          Exit;
        end
        Else if Pos('<script type="text/javascript" src="scripts/CW00/login.js"></script>',Memo1.Lines.Text) > 0 then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入'));
          DataLoading(False,False);
          Exit;
        end;
        /////上傳MPSLICXXXX.lic /////
      end;
    end;
  Finally
  OpenDialog1.Free;
  S.Free;
  _DelTree(ZipPath);
  end;
  Showmessage(_Msg('匯入完成'));
end;
 
 
{ ==============================================================================
  方法名稱:HTTPSClientCertificateValidate
  引用相依:HTTPSClientCertificateValidate
  方法描述:HTTPS 用戶端憑證驗證回呼函數,預設直接將 Validate 設為 True,以接受所
            有伺服器憑證。
============================================================================== }
procedure TCB_IMGPSScanX.HTTPSClientCertificateValidate(Sender: TObject;
  X509Certificate: TElX509Certificate; var Validate: Boolean);
begin
  Validate := True;
end;
 
 
{ ==============================================================================
  方法名稱:HTTPSClientRedirection
  引用相依:
  方法描述:處理 HTTPS 客戶端的重導向事件,目前為空實作。
============================================================================== }
procedure TCB_IMGPSScanX.HTTPSClientRedirection(Sender: TObject;
  const OldURL: string; var NewURL: string; var AllowRedirection: Boolean);
begin
  AllowRedirection := True;
end;
 
 
{ ==============================================================================
  方法名稱:EnableImage
  引用相依:
  方法描述:啟用滑鼠工具列功能,更新按鈕圖示並切換滑鼠模式。
============================================================================== }
procedure TCB_IMGPSScanX.EnableImage(v:integer;Sender : TObject);
var bmp : Tbitmap;
begin
  DesableImage;
  bmp := TBitmap.Create;
  try
    ImageList3.GetBitmap(v,bmp);
    TBitBtn(Sender).Glyph.Assign(bmp);
  finally
  bmp.Free;
  end;
  ViewMouseMode(v);
end;
 
 
{ ==============================================================================
  方法名稱:DesableImage
  引用相依:
  方法描述:停用所有工具列功能。重置點選狀態,將所有功能按鈕(FC0-FC6)圖示切換為灰
            階,並將所有影像捲軸盒的滑鼠模式切換回一般使用者模式。
============================================================================== }
procedure TCB_IMGPSScanX.DesableImage;
var bmp : Tbitmap;
    i : integer;
begin
  NowClick := -1;
  bmp := Tbitmap.Create;
  try
  For i:= 0 to 6 do
  begin
    ImageList4.GetBitmap(i,bmp);
    TBitBtn(FindComponent('FC'+IntToStr(i))).Glyph.Assign(bmp);
    bmp.Width:=0;
    bmp.Handle:=0;
  end;
  finally
  bmp.Free;
  end;
  ViewMouseMode(NowClick);
end;
 
 
{ ==============================================================================
  方法名稱:ViewMouseMode
  引用相依:
  方法描述:設定全域的滑鼠作業模式。根據參數對應至放大鏡、縮放、拖曳、旋轉或刪除等模
            式,並同步更新所有影像捲軸盒(ISB1-ISB8)的屬性,確保行為一致。
============================================================================== }
Procedure TCB_IMGPSScanX.ViewMouseMode(v:Integer);
var
  i : Integer;
  Md : TMouseMode;
  ISB : TImageScrollBox;
begin
//ShowMessage(IntToStr(v));
  case v of
   -1 : Md := TMouseMode(mmUser);
    0 : Md := TMouseMode(mmAmplifier);
    1 : Md := TMouseMode(mmZoom);
    2 : Md := TMouseMode(mmDrag);
    3 : Md := TMouseMode(mmR270);
    4 : Md := TMouseMode(mmR180);
    5 : Md := TMouseMode(mmR90);
    6 : Md := TMouseMode(mmDelete);
  end;
  for i := 1 to 8 do
  begin
    ISB := TImageScrollBox(FindComponent('ISB'+inttostr(i)));
    ISB.MouseMode := TMouseMode(Md);
    //Label3.Caption:='v='+IntToStr(v)+'  time'+FormatDateTime('yyyy/mm/dd HH:MM:SS', now);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GoViewMode
  引用相依:
  方法描述:依檢視模式索引 VMode,呼叫 DisplayMode 來調整佈局。
============================================================================== }
Procedure TCB_IMGPSScanX.GoViewMode;
begin
  case VMode of
    0: DisplayMode(VMode,1,1,Panel9);
    1: DisplayMode(VMode,1,1,Panel9);
    2: DisplayMode(VMode,2,2,Panel9);
    3: DisplayMode(VMode,2,3,Panel9);
    4: DisplayMode(VMode,2,4,Panel9);
  end;
end;
 
 
 
{ ==============================================================================
  方法名稱:DisplayMode
  引用相依:
  方法描述:調整影像視窗的網格佈局(1x1, 2x2 等)。隱藏所有影像面板後,根據行數與列
            數計算面板寬高與位置,重新排列並顯示。同時調整標記框 Shape1 的大小,最
            後更新模式圖示並初始化首個視窗。
============================================================================== }
Procedure TCB_IMGPSScanX.DisplayMode(index,H_Count,W_Count:Integer;BasePanel:TPanel);
Var
  W,H,T,L:Integer;
  i,n,Count: Integer;
  Pl :TPanel;
  bmp : TBitmap;
begin
  for i := 1 to 8 do
  begin
    TPanel(Findcomponent('imgp'+inttostr(i))).Visible := False;
  end;
  W := Round((BasePanel.Width - ((W_Count+1) * Seg)) / W_Count);
  H := Round((BasePanel.Height -((H_Count+1) * Seg)) / H_Count);
  Count := 1;
  for i := 1 to H_Count do
  begin
    T := i * Seg + H * (i-1);
    for n := 1 to W_Count do
    begin
      L := n * Seg + W * (n-1);
      Pl := TPanel(Findcomponent('imgp'+inttostr(Count)));
      Pl.Visible := True;
      Pl.Left := L;
      Pl.Top := T;
      Pl.Width := W;
      Pl.Height := H;
      inc(Count);
    end;
  end;
  Shape1.Width := W + (Seg * 2);
  Shape1.Height := H + (Seg * 2);
  Shape1.Visible := True;
 
 
  bmp := Tbitmap.Create;
  try
    ImageList2.GetBitmap(index,bmp);
    ViewModeBtn.Glyph.Assign(bmp);
  finally
  bmp.Free;
  end;
  ISB1Click(ISB1);
end;
 
 
{ ==============================================================================
  方法名稱:CheckRequiredColumnValues
  引用相依:
  方法描述:檢查特定業務邏輯下的必填欄位。針對特定的 workno 與案號格式(caseno[9])
            判斷是否符合要求。
============================================================================== }
function TCB_IMGPSScanX.CheckRequiredColumnValues(workno, caseno:String): Boolean;
begin
//
  Result:=False;
  if (workno='HLN') and (caseno[9]='3') then
    Result:=True;
  if (workno='HLN') and (caseno[9]='4') then
    Result:=True;
end;
 
 
{ ==============================================================================
  方法名稱:CaseReSize
  引用相依:FileExists, ImageReSize_FormID, ImageResize, LoadFromFile
  方法描述:對案件執行影像縮放處理。清空舊有的檢核與定位錯誤記錄,隨後遍歷影像清單
            ,對每個檔案執行 ImageReSize_FormID 處理。
============================================================================== }
Procedure TCB_IMGPSScanX.CaseReSize(CaseID:String); //案件的影像縮放
var
  S : TStringlist;
  FileName : String;
  i : Integer;
begin
  {if FileExists(ImageSavePath+CaseID+'\ReSize.dat') then
    DeleteFile(ImageSavePath+CaseID+'\ReSize.dat');}
  if FileExists(ImageSavePath+CaseID+'\Upload\AnchorError.dat') then
    DeleteFile(ImageSavePath+CaseID+'\Upload\AnchorError.dat');
  S := TStringlist.Create;
  try
    S.LoadFromFile(ImageSavePath+CaseID+'\Upload\Context.dat');
    For i := 0 to S.Count -1 do
    begin
      FileName := S.Strings[i];
      ImageReSize_FormID(CaseID,FileName);  //依十字定位點做縮放
    end;
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:TransCaseID
  引用相依:CopyFile, FileExists, FindFirst, FtpCaseComplete, IIS_Ftp, LoadFromF
            ile, SetFtpInfo, _DelTree, upFile
  方法描述:傳送案件核心程序。包含排序影像、產生描述檔(FormID/DocNo對照、OMR資訊、附
            件狀態等)、建立 ZIP 壓縮包(含主圖與遮罩)並檢查大小。最後根據 HTTP 或 F
            TP 模式上傳至伺服器。上傳完成後針對異動模式處理舊件引入,並在最後清理
            本地暫存目錄。
============================================================================== }
Function TCB_IMGPSScanX.TransCaseID(Path,CaseID:String;MainCase:Boolean):Boolean; //傳送案件
Var
  i,n,v: Integer;
  ZipFileList : TStringlist;
  UpFormID:String;
  pages : Integer;
  TransName : String;
  MaskPath : String;
  HaveMask : Boolean;
  S : String;
  SendData:String;
  Doc_Data,Doc_Data1 : String;
  In_Doc1,In_Doc2 : String;
  AttachYN : String; //是否有附件 Y:有 N:沒有
 
  ST1,ST2,ST3:TStringList;
  str1,str2:String;
  must_formidStr :string;
  last_add_formidstr :string;
  ScanListStr:String;
  casepath:String;
  filesizeInt:integer;
  case_page:string;
  Fname:String;
  FileRec:TSearchrec;
begin
  Result := True;
  TransName := CaseID;
  MaskPath := Path+'MaskImg\';
  if fileExists(Path+'Context.dat') then
  begin
    ContextList.LoadFromFile(Path+'Context.dat');
    Context_DocnoList.LoadFromFile(Path+'Context_DocNo.dat');
  end;
 
  if FileExists(Path+'CustomDocNo.dat') then
    Cust_DocNoList.LoadFromFile(Path+'CustomDocNo.dat');
 
  Pages := ContextList.Count;
  case_page:=IntToStr(pages);
  if (FMode = 'NSCAN') or (FMode = 'ESCAN') or (FMode = 'ASCAN') or (FMode = 'DSCAN') or (FMode = 'SSCAN') or (FMode = 'MSCAN') or (FMode = 'RI_SCAN') or (FMode = 'RSCAN')  then
  begin
    //Showmessage('1');
    UpformID := GetCaseFormID(Path);
    {if UpformID = '' then             //20131213  yuu說不管主form
    begin
      Showmessage(_msg('取不到主FormID!!'));
      Result := False;
      DataLoading(False,False);
      Exit;
    end;}
  end;
 
  CaseResort2Scanlist(Path); //檔名照設定排序產生scanlist.dat
  //CaseResort(Path);  //檔名照設定排序
  CreateFormID_FormName(Path,CaseID);  //產生FormID_FormName.dat
  CreateDocNo_DocName(Path,CaseID); //產生DocNo_Name.dat
  Doc_Data := CreateDocNo_Info(CaseID);  //產生保管袋文件 Docno,份數,頁數;Docno,份數,頁數 的回傳字串
  Doc_Data1 := CreateCustDocNo_Info(CaseID);  //產生自定文件 Docname,份數,頁數;Docno,份數,頁數 的回傳字串
  In_Doc1 := CreateDocnoFrom_Info(CaseID); //產生被引進的保管袋文件資訊  Docno[tab]份數[tab]案件編號#13#10Docno[tab]份數[tab]案件編號
  In_Doc2 := CreateCustDocNoFrom_Info(CaseID);   //產生被引進的自定文件資訊  Docno[tab]份數[tab]案件編號#13#10Docno[tab]份數[tab]案件編號
  AttachYN := CreateAttach_Info(CaseID); //是否還有附件 Y:有 N:沒有
  ReadCaseIndex(Path);
  //LoanDoc := 'Y';
  //產生遮罩影像
//  if FWork_No = 'CW' then
//    HaveMask := Case2Mask(Path,MaskPath);
  //產生遮罩影像
 // S := S +#13+'5-->'+ Timetostr(now);
 
  ///////必要formid 20170315 start  //////////////////////////////
  must_formidStr:='';
  last_add_formidstr:='';
  ST1:=TStringList.Create;
  ST1.LoadFromFile(path+'FormCode_Name.dat');
//ShowMessage(ST1.Text);
//ShowMessage(LastInitFormidList.Text);
  ST2:=TStringList.Create;
  ST3:=TStringlist.Create;
 
  for I := 0 to ST1.Count - 1 do
  begin
    if (Pos('_',St1.Strings[i])<>1) and (Pos('_',St1.Strings[i])<>-1) then
    begin
      str1:=Copy(ST1.Strings[i],1,Pos('_',St1.Strings[i])-1);
      ST2.Add(str1);
      must_formidStr:= must_formidStr+str1+'@#,';
    end;
  end;
  must_formidStr:=Copy(must_formidStr,1,Length(must_formidStr)-3) ;
//ShowMessage('must_formidStr='+must_formidStr);
//ShowMessage('AST2='+ST2.Text);
 
 
  for I := 0 to LastInitFormidList.Count - 1 do
  begin
    if ST2.IndexOf(LastInitFormidList.Strings[i]) <> -1 then
    begin
      ST2.Delete(ST2.IndexOf(LastInitFormidList.Strings[i]));
    end;
  end;
//ShowMessage('BST2='+ST2.Text);
  for I := 0 to ST2.Count - 1 do
  begin
      last_add_formidstr:=last_add_formidstr+ST2.Strings[i]+'@#,';
  end;
  last_add_formidstr:=Copy(last_add_formidstr,1,Length(last_add_formidstr)-3) ;
 
  ST3.LoadFromFile(path+'scanlist.dat');
  for I := 0 to ST3.Count - 1 do
  begin
    if ScanListStr = '' then
      ScanListStr := FileName2FormCode(ST3.Strings[i])
    else
      ScanListStr := Format('%s,%s',[ScanListStr,FileName2FormCode(ST3.Strings[i])]);
  end;
 
  ST1.Free;
  ST2.Free;
  ST3.Free;
//ShowMessage('last_add_formidstr='+last_add_formidstr);
  ///////必要formid 20170315 end //////////////////////////
 
  ///保留外部影像  start///////////////////////////////
  casepath:= Copy(Path,1,pos('Upload',path)-1);
//ShowMessage('casepath='+casepath);
//FIsExternal:='Y';
  if (FMode='ESCAN') and (FIsExternal='Y') then
  begin
    if FileExists(casepath+'Download\FirstImg.zip') then
    begin
      CopyFile(PWChar(casepath+'Download\FirstImg.zip'),PWChar(path+'FirstImg.zip'),false);
    end
    else
    begin
      CopyFile(PWChar(casepath+'Download\'+CaseID+'.zip'),PWChar(path+'FirstImg.zip'),false);
    end;
  end;
  ///保留外部影像  end///////////////////////////////
 
  //file_size 計算  就先不做 20170316
  filesizeInt:=0;
 
 
  //////壓檔/////
  ZipMainFile(Path,Path,'Img.zip');
  if HaveMask then
    ZipMaskFile(Path,MaskPath,Path,'MaskImg.zip');  //有遮罩設定的才產生
  /////壓檔////
  ///檢查上傳的zip大小////
   FName :=Path+ 'Img.zip';
 
    FindFirst(FName, faAnyfile, FileRec);
 
    //FMaxUploadSize
//ShowMessage(IntToStr(FileRec.Size));
//Result:=False;
//exit;           //目前上傳檔案大小為xxMB,已超過50MB,無法上傳    %.3f  ,[FileRec.Size / 1048576]
    If FileRec.Size > StrtoInt(FMaxUploadSize) * 1048576 Then // 檢查檔案大小
    Begin
      ShowMessage(Format(_Msg('%s目前上傳檔案大小為%.3fMB,已超過%sMB,無法上傳'),[caseid,FileRec.Size / 1048576,FMaxUploadSize]));
      //ShowMessage(Format('%s目前上傳檔案大小為%.3fMB,已超過'+FMaxUploadSize+'MB,無法上傳',[caseid,FileRec.Size / 1048576]) );
      FindClose(FileRec);
      Result := False;
      Exit;
    End;
    FindClose(FileRec);
  ///檢查上傳的zip大小////
//ShowMessage('last_add_formidstr='+last_add_formidstr);
  if not GetftpInfo(CaseID,'upload') then   //取案件上傳方式
  begin
    //Showmessage(_Msg()Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason+'.');
    DownFileErrStr := _Msg('取案件上傳資訊失敗!!')+HttpErrStr;
    Result := False;
    Exit;
  end;
  SendData:='data='+HTTPEncode(UTF8Encode(FData))
      +'&verify='+FVerify
      +'&form_id='+UpformID
      +'&loan_doc='+Case_loandoc
      +'&case_no='+TransName
      +'&doc_data='+HTTPEncode(UTF8Encode(Doc_Data))
      +'&doc_data1='+HTTPEncode(UTF8Encode(Doc_Data1))
      +'&attach='+AttachYN
      +'&case_page='+case_page
      +'&file_size='+IntToStr(filesizeInt)
      +'&must_formid='+must_formidStr  //擁有的 formid
      +'&last_add_formid='+last_add_formidstr   //當次新加的 formid
      +'&form_code='+ScanListStr      //scanlist.dat 表單代號
      +'&ftp_image_path='+FFtpExtraPath   //加傳FTP目錄  HTTP上傳時會是空白
      +'&in_doc1='+HTTPEncode(UTF8Encode(In_Doc1))
      +'&in_doc2='+HTTPEncode(UTF8Encode(In_Doc2));
 
  case TransMode of
    tsHttp :
    begin
      ////上傳/////
      ShowText := CaseID+_Msg('資料上傳中(Http),請稍候');
      DataLoading(True,True);
      if not upFile(HTTPSClient,FUrl,'service/imgpsc/IMGPSC02/caseupload',SendData,'file',Path+'Img.zip',FReWrite,Memo1,False) then
      begin
        Showmessage(Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason+'.');
        Result := False;
        Exit;
      end;
      if memo1.Lines.Strings[0] = '1' then
      begin
        Showmessage(Format(_Msg('')+_Msg(''),[CaseID])+memo1.Lines.Strings[1]+'。');
        Result := False;
        Exit;
      end
      Else if Pos('<script type="text/javascript" src="scripts/IMGPS00/login.js"></script>',Memo1.Lines.Text) > 0 then
      begin
        Showmessage(Format(_Msg('')+_Msg('')+_Msg('閒置過久或被登出,請重新登入'),[CaseID]));
        Result := False;
        Exit;
      end;
      ////上傳////
    end;
    tsFtp :
    begin
       ShowText := CaseID+_Msg('資料上傳中(Ftp),請稍候');
       DataLoading(True,True);
       SetFtpInfo;
       try
         if not IIS_Ftp.FtpsConnect then
         begin
           Showmessage(Format('無法連上Ftp主機,錯誤原因:%s',[FtpErrReason]));
           Result := False;
           Exit;
         end;
         if not IIS_Ftp.FtpsToMain(FFtpExtraPath,CaseID+'.zip',Path+'Img.zip',display1) then
         begin
           Showmessage(Format(_msg('上傳案件(%s)時,發生錯誤,錯誤原因:%s'),[CaseID,FtpErrStr]));
           Result := False;
           Exit;
         end;
 
         if not FtpCaseComplete(SendData) then    //Ftp上傳後通知完成
         begin
           Showmessage(Format(_Msg('通知案件(%s)Ftp上傳完成時,發生錯誤!!'),[CaseID])+HttpErrStr);
           Result := False;
           Exit;
         end;
       finally
       IIS_Ftp.FtpsClose;
       end;
    end;
 
  end;
 
 
  if FMode = 'ESCAN' then    //上傳舊件引入檔案      //20140616 原本先搬舊件再搬新件,改為先搬新件再搬舊件
  begin
    if not TransOldCaseFile(ImageSavePath+CaseID+'\') then
    begin
      Result := False;
      Exit;
    end;
  end;
  // 呼叫Server完成 /////
  {If not CaseComplete(Path,CaseID,MainCase) Then
  begin
    Showmessage(_Msg('通知案件傳送完成時,網路發生錯誤!!')+HttpErrStr);
    DataLoading(False,False);
    Result := False;
    Exit;
  end;  }
  /// 呼叫Server完成////
 
  ////刪檔////
  //_DelTree(Path);  //會只刪TransPath
//ShowMessage('STOP');
  _DelTree(ImageSavePath+CaseID);
  SetCaseList('D',-1,CaseID);
  ////刪檔////
end;
 
 
{ ==============================================================================
  方法名稱:NewTreeNodeRefresh
  引用相依:
  方法描述:更新樹狀結構根節點文字,顯示總案件筆數與總頁數。
============================================================================== }
Procedure TCB_IMGPSScanX.NewTreeNodeRefresh;
var
  v : Integer;
begin
  //v := Pos('-',NewTreeNode.Text);
  //NewTreeNode.Text := Copy(NewTreeNode.Text,1,v-1)+'-共'+inttostr(NewTreeNode.Count)+'筆';
  GetCase_PageCount(CaseCount,PageCount);
  v := Pos('-',NewTreeNode.Text);
  NewTreeNode.Text := Format(_Msg('%s-共%d筆共%d頁'),[Copy(NewTreeNode.Text,1,v-1),CaseCount,PageCount]);
end;
 
 
{ ==============================================================================
  方法名稱:MyTreeNode1Refresh
  引用相依:
  方法描述:更新樹狀結構案件層級節點文字,顯示該層下的項目數量。
============================================================================== }
Procedure TCB_IMGPSScanX.MyTreeNode1Refresh;
var
  v : Integer;
begin
  v := Pos('-',MyTreeNode1.Text);
  MyTreeNode1.Text := Format(_Msg('%s-%d筆'),[Copy(MyTreeNode1.Text,1,v-1),MyTreeNode1.Count]);
end;
 
 
{ ==============================================================================
  方法名稱:MyTreeNode2ReFresh
  引用相依:
  方法描述:重新整理並繪製指定案件的文件層級樹狀結構。
============================================================================== }
Procedure TCB_IMGPSScanX.MyTreeNode2ReFresh(CaseID:String);
var
  P : Integer;
begin
  //p:= ContextList.Count;
  //MytreeNode1.Text := Format(_Msg('%s-%d頁'),[CaseID,p]);
  DrawDocItem2(MytreeNode1,CaseID);
  //DrawDocItem(MytreeNode1,FORM_INF_List,CaseID);
end;
 
 
{ ==============================================================================
  方法名稱:MyTreeNode3ReFresh
  引用相依:
  方法描述:重新整理並繪製指定案件的表單層級樹狀結構。
============================================================================== }
Procedure TCB_IMGPSScanX.MyTreeNode3ReFresh(CaseID:String);
begin
 
  //DrawDocItem1(MytreeNode1,Doc_Inf_List,CaseID);  //201408280改
  DrawDocItem2(MytreeNode1,CaseID);
  //DrawDocItem(MytreeNode1,FORM_INF_List,CaseID);
end;
 
 
{ ==============================================================================
  方法名稱:Node3FormID
  引用相依:
  方法描述:從樹狀結構節點 3(表單層)的文字中解析並提取表單 ID(FormID)。
============================================================================== }
Function TCB_IMGPSScanX.Node3FormID(Node3:TTreeNode):String;  //MyTreeNode3取FormCode出來
var
  v,v1,v2 : Integer;
begin
  v := Pos('{',Node3.Text);
  v1 := Pos('}',Node3.Text);
  v2 := Posend('-',Node3.Text);
  Result := Copy(Node3.Text,v+1,v1-v-1);
  IF v1 = 0 Then
  begin
    Result := '';
  end;
end;
 
 
 
{ ==============================================================================
  方法名稱:GetNode2Name
  引用相依:CopyFile, DeleteDocNoFile, DirectoryExists, En_DecryptionStr_Base64,
             FileExists, LoadFromFile, SaveToFile, Str2Dir, dnFile
  方法描述:提取文件層級節點的識別名稱字串,用於記錄與恢復節點選取狀態。
============================================================================== }
Function TCB_IMGPSScanX.GetNode2Name(Node2:TTreeNode):String;  //取MyTreeNode2的識別字出來(記之前點選用)
var
  v : Integer;
begin
  v := Posend('-',Node2.Text);
  Result := Copy(Node2.Text,1,v-1);
end;
 
{Function TCB_IMGPSScanX.Down_Replace_Img(SPath,DPath,CaseID:String):Boolean;
var
  EnCodeDateTime : String;
  DownUrl : String;
  SC,Main_C : TStringlist;
  i,n : Integer;
  FormID,DocNo,Version : String;
  OldFName,NewMainFName,NewSubFName : String;
  AttPath : String;
begin
  SC := TStringlist.Create;
  Main_C := TStringlist.Create;
  try
    Result := True;
    HaveAppDoc := False;
    EnCodeDateTime := En_DecryptionStr_Base64('E',ServerDate+GetBalance2Time(Balance),Mpskey);
    DownUrl := FUrl+CaseID+'&checktime='+EnCodeDateTime;
    if not dnFile(HTTPSClient,DownUrl,'','',DPath+CaseID+'.zip',FReWrite,Memo1,False,DownImgStatus) then
    begin
      HttpErrStr := _Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason;
      Result := False;
      Exit;
    end;
    if Memo1.Lines.Strings[0] = '1' then
    begin
      HttpErrStr :=_Msg('錯誤原因:')+memo1.Lines.Strings[1];
      Result := False;
      Exit;
    end
    Else if Pos('<script type="text/javascript" src="scripts/CW00/login.js"></script>',Memo1.Lines.Text) > 0 then
    begin
      HttpErrStr := _Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入');
      Result := False;
      Exit;
    end;
    AttPath := DPath + 'AttFile\';
    if FileExists(DPath+CaseID+'.zip') then
    begin
      ExecuteUnZip(DPath+CaseID+'.zip',DPath,True);
      if FileExists(DPath+'img.zip') then
      begin
        ExecuteUnZip(DPath+'img.zip',DPath,False);
      end;
      if FileExists(DPath+'att.zip') then
      begin
        Str2Dir(AttPath);
        ExecuteUnZip(DPath+'att.zip',AttPath,False);
      end;
    end
    Else
    begin
      if ((FMode = 'FSCAN') or (FMode = 'ISCAN')) and (Memo1.Lines.Strings[0] ='NO_FILE') then  //FGIS前台匯入件沒有影像是對的
      begin
        SC.Clear;
        SC.SaveToFile(DPath+'Context.dat');
      end
      Else
      begin
        HttpErrStr := _Msg('找不到影像');
        Result := False;
        Exit;
      end;
    end;
 
 
    if FileExists(SPath+'Context.dat') then
      SC.LoadFromFile(SPath+'Context.dat');
    for I := 0 to SC.Count - 1 do
    begin
      FormID := FileName2FormCode(SC.Strings[i]);
      DocNo := FormCode2DocNo(FormID);
      Version := FormCode2Version(FormID);
      If FindSQLData(Doc_Inf_List,'ADD_SCAN_RULE','DOC_NO,DOC_VERSION',DocNo+','+Version,0,FindResult) Then
      begin
        if GetFindResult('ADD_SCAN_RULE') = 'R' then  //替換的先刪再加  20101026 User由刪FormCode改刪DocNo
        begin
          //DeleteFormCodeFile(DPath,FormID);
          ContextList.LoadFromFile(DPath+'Context.dat');
          DeleteDocNoFile(DPath,DocNo);
        end;
      end;
    end;
    for I := 0 to SC.Count - 1 do   //複製補充進來的影像
    begin
      OldFName := SC.Strings[i];
      Main_C.LoadFromFile(DPath+'Context.dat');
      //NewMainFName:= Add_Zoo(Main_C.Count+1,3)+Copy(OldFName,4,length(OldFName)-3);
      NewMainFName:= Add_Zoo(Main_C.Count+1,3)+FileName2NoQuene_Filename(OldFName);
      FormID := FileName2FormCode(OldFName);
      DocNo := FormCode2DocNo(FormID);
      Version := FormCode2Version(FormID);
      If FindSQLData(Doc_Inf_List,'ADD_SCAN_RULE','DOC_NO,DOC_VERSION',DocNo+','+Version,0,FindResult) Then
      begin
        CopyFile(PWideChar(SPath+OldFName),PWideChar(DPath+NewMainFName),False);
      end;
      if FormID = '' then //附件
      begin
        CopyFile(PWideChar(SPath+OldFName),PWideChar(DPath+NewMainFName),False);
      end;
      Main_C.Add(NewMainFName);
      Main_C.SaveToFile(DPath+'Context.dat');
    end;
  finally
  SC.Free;
  Main_C.Free;
  end;
  ///加入的電子檔匯入案件裡
  if DirectoryExists(SPath+'AttFile\') then
    AttFile_Arrange(SPath+'AttFile\',DPath+'AttFile\');
end;}
 
 
{ ==============================================================================
  方法名稱:DownLoadImage
  引用相依:IIS_Ftp, SetFtpInfo
  方法描述:處理影像下載流程。根據案件上傳/下載方式(HTTP 或 FTP),從伺服器下載對應
            的 ZIP 檔案並解壓縮至本地案件目錄,供後續異動或補件使用。
============================================================================== }
Function TCB_IMGPSScanX.DownLoadImage(Path,CaseID:String):Boolean;
begin
  Result := True;
  if not GetftpInfo(CaseID,'download') then   //取案件下載方式
  begin
    DownFileErrStr := _Msg('取案件下載資訊失敗,')+HttpErrStr;
    Result := False;
    Exit;
  end;
  case TransMode of
    tsHttp:
    begin
      ShowText := _Msg('案件下載中(Http),請稍候');
      DataLoading(True,True);
      If not Down_Img(ImageSavePath+FCaseID+'\Download\',FCaseID) then
      begin
        Showmessage(FCaseID+_msg('載入異動影像時,網路發生錯誤')+HttpErrStr);
        DataLoading(False,False);
        Exit;
      end;
    end;
    tsFtp:
    begin
      ShowText := _Msg('案件下載中(Ftp),請稍候');
      DataLoading(True,True);
      SetFtpInfo;
 
      if not IIS_Ftp.FtpsConnect then
      begin
        DownFileErrStr := Format(_Msg('無法連上Ftp主機,錯誤原因:%s')+#13+'%s',[FtpErrReason,FTPSClient1.LastReceivedReply]);
        Result := False;
        Exit;
      end;
      if not IIS_Ftp.FtpsDownloadFile(FFtpExtraPath,CaseID+'.zip',Path+CaseID+'.zip',display1) then
      begin
        DownFileErrStr := Format(_Msg('錯誤原因:%s'),[FtpErrStr]);
        Result := False;
        Exit;
      end;
      ExecuteUnZip(Path+CaseID+'.zip',Path,False);
      DeleteFile(Path+CaseID+'.zip');
    end;
  end;
end;
 
 
 
{ ==============================================================================
  方法名稱:Down_Img
  引用相依:En_DecryptionStr_Base64, FileExists, Str2Dir, dnFile, dnFile_Get
  方法描述:透過 HTTPS 從伺服器下載案件影像。下載 ZIP 檔案(含 img.zip 與 att.zip)
            後執行本地解壓縮,將主影像與附件部署至指定目錄。
============================================================================== }
Function TCB_IMGPSScanX.Down_Img(Path,CaseID:String):Boolean;
var
  EnCodeDateTime : String;
  SendData : String;
  AttPath : String;
begin
  Result := True;
  EnCodeDateTime := En_DecryptionStr_Base64('E',ServerDate+GetBalance2Time(Balance),Mpskey);
  ///service/slic/SLIC04/case?data=&verify=&case_no=&file=
  SendData := 'data='+HTTPEncode(UTF8Encode(FData))+'&verify='+FVerify+'&case_no='+CaseID+'&file=';
//ShowMessage(SendData);
  if not dnFile_Get(HTTPSClient,Furl,'service/imgpsc/IMGPSC04/case',SendData,Path+CaseID+'.zip',FReWrite,Memo1,False,DownImgStatus) then
  begin
    HttpErrStr := _Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason;
    Result := False;
    Exit;
  end;
  if Memo1.Lines.Strings[0] = '1' then
  begin
    HttpErrStr :=_Msg('錯誤原因:')+memo1.Lines.Strings[1]+'。';
    Result := False;
    Exit;
  end
  Else if Pos('<script type="text/javascript" src="scripts/IMGPS00/login.js"></script>',Memo1.Lines.Text) > 0 then
  begin
    HttpErrStr := _Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入');
    Result := False;
    Exit;
  end;
//ShowMessage('替換zip');
  AttPath := Path + 'AttFile\';
  if FileExists(Path+CaseID+'.zip') then
  begin
    ExecuteUnZip(Path+CaseID+'.zip',Path,True);
    if FileExists(Path+'img.zip') then
    begin
      ExecuteUnZip(Path+'img.zip',Path,False);
    end;
    if FileExists(Path+'att.zip') then
    begin
      Str2Dir(AttPath);
      ExecuteUnZip(Path+'att.zip',AttPath,False);
    end;
  end
  Else
  begin
    HttpErrStr := _Msg('找不到影像');
    Result := True;
    Exit;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:GetNoNameCase
  引用相依:DirectoryExists, GetNoNameCase
  方法描述:在指定的本地路徑中尋找尚未被佔用的「未配號XXXX」目錄名稱。
============================================================================== }
Function TCB_IMGPSScanX.GetNoNameCase(Path:String):String; //取未配號XXXX
var
  i : Integer;
begin
  for i := 1 to 9999 do
  begin
    if Not DirectoryExists(Path+_Msg('未配號')+Add_Zoo(i,4)) then
    begin
      Result := _Msg('未配號')+Add_Zoo(i,4);
      Break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CaseResort
  引用相依:FileExists, LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:對案件檔案進行實體重新排序。依據文件清單(Doc_Inf_List)的順序,對主文件
            與次文件進行更名與重新編號,確保檔名序號符合業務邏輯。
============================================================================== }
Procedure TCB_IMGPSScanX.CaseResort(Path:String); //案件的檔案重新排序(次文件依Docno排)
var
  i,n,v,v1 : Integer;
  S,S1 : TStringlist;
  FormID,OldName,NewName,DocNo,Doc_Type:String;
  x : Integer;
begin
  S := TStringlist.Create;
  S1 := TStringlist.Create;
  try
  S.LoadFromFile(Path+'Context.dat');
  X := 0;
  {for I := 1 to FORM_INF_List.Count - 1 do    //在FormID有設定的   //主文件 照SQL排   20101028改
  begin
    FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
    if FormCode2FileName(FormID,S) = '' then
       Continue;
    Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='1') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;}
 
  {for I := 0 to FORM_INF_List.Count - 1 do  //次文件 照FormID 1~8碼+掃瞄順序排   20110512為了某個文件要先打的原因要求改
  begin
    for n := 0 to S.Count - 1 do
    begin
      FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
      Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
      if (S.Strings[n][1] <> '*') and (Copy(FileName2FormCode(S.Strings[n]),1,8) = Copy(FormID,1,8)) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;}
  for I := 0 to Doc_Inf_List.Count - 1 do  //主文件 照文件代碼+掃瞄順序排   20101101改   20110512晚上又說改回來
  begin
    DocNo := GetSQLData(Doc_Inf_List,'DOC_NO',i);
    if DocNo2FileName(DocNo,S) = '' then
      Continue;
    Doc_Type := GetSQLData(Doc_Inf_List,'DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FormCode2DocNo(FileName2FormCode(S.Strings[n])) = DocNo) and (Doc_Type='1') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;
 
 
  for I := 0 to Doc_Inf_List.Count - 1 do  //次文件 照文件代碼+掃瞄順序排   20101101改   20110512晚上又說改回來
  begin
    DocNo := GetSQLData(Doc_Inf_List,'DOC_NO',i);
    if DocNo2FileName(DocNo,S) = '' then
      Continue;
    Doc_Type := GetSQLData(Doc_Inf_List,'DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FormCode2DocNo(FileName2FormCode(S.Strings[n])) = DocNo) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;
 
  {for n := 0 to S.Count - 1 do    //次文件 照掃瞄順序排   20101028改
  begin
    FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
    Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
    for i := 0 to FORM_INF_List.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;}
  for i := 0 to S.Count - 1 do   //FormID沒設定的或附件
  begin
    if S.Strings[i][1] <> '*' then
    begin
      Inc(X);
      OldName := S.Strings[i];
      //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3);
      NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName);
      S.Strings[i] := '*'+S.Strings[i];
      S1.Add(OldName+','+NewName);
    end;
  end;
  S.Clear;
  for i := 0 to S1.Count - 1 do  //開始轉換檔名
  begin
    v := Pos(',',S1.Strings[i]);
    v1 := length(S1.Strings[i]);
    OldName := copy(S1.Strings[i],1,v-1);
    NewName := copy(S1.Strings[i],v+1,v1-v);
    if FileExists(Path+OldName) then
    begin
      ReNameFile(Path+OldName,Path+NewName);
      S.Add(NewName);
      S.SaveToFile(Path+'Context.dat');
    end;
  end;
  ReSortFileName(Path);
  finally
  S.Free;
  S1.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CaseResort2Scanlist
  引用相依:FileExists, LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:產生依表單代號排序的影像清單(scanlist.dat),用於上傳。
============================================================================== }
Procedure TCB_IMGPSScanX.CaseResort2Scanlist(Path:String); //案件的檔案重新排序給scanlist(次文件依FormID排)
var
  i,n,v,v1 : Integer;
  S,S1 : TStringlist;
  FormID,OldName,NewName,DocNo,Doc_Type:String;
  x : Integer;
begin
  S := TStringlist.Create;
  S1 := TStringlist.Create;
  try
  if FileExists(Path+'Context.dat') then
    S.LoadFromFile(Path+'Context.dat');
  X := 0;
  for I := 1 to FORM_INF_List.Count - 1 do    //在FormID有設定的   //主文件 照SQL排   20101028改
  begin
    FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
    if FormCode2FileName(FormID,S) = '' then
       Continue;
    Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='1') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;
 
  for I := 0 to FORM_INF_List.Count - 1 do  //次文件 照SQL排   20110512為了某個文件要先打的原因要求改
  begin
 
    FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
    if FormCode2FileName(FormID,S) = '' then
       Continue;
    Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;
 
  {for I := 0 to Doc_Inf_List.Count - 1 do  //次文件 照文件代碼+掃瞄順序排   20101101改   20110512晚上又說改回來
  begin
    DocNo := GetSQLData(Doc_Inf_List,'DOC_NO',i);
    Doc_Type := GetSQLData(Doc_Inf_List,'DOC_TYPE',i);
    for n := 0 to S.Count - 1 do
    begin
      if (S.Strings[n][1] <> '*') and (FormCode2DocNo(FileName2FormCode(S.Strings[n])) = DocNo) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;}
 
  {for n := 0 to S.Count - 1 do    //次文件 照掃瞄順序排   20101028改
  begin
    for i := 0 to FORM_INF_List.Count - 1 do
    begin
      FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i);
      Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i);
      if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='2') then
      begin
        Inc(X);
        OldName := S.Strings[n];
        NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編
        S.Strings[n] := '*'+S.Strings[n];
        S1.Add(OldName+','+NewName);
      end;
    end;
  end;}
  for i := 0 to S.Count - 1 do   //FormID沒設定的或附件
  begin
    if S.Strings[i][1] <> '*' then
    begin
      Inc(X);
      OldName := S.Strings[i];
      //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3);
      NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName);
      S.Strings[i] := '*'+S.Strings[i];
      S1.Add(OldName+','+NewName);
    end;
  end;
 
  S.Clear;
  for i := 0 to S1.Count - 1 do  //開始轉換檔名
  begin
    v := Pos(',',S1.Strings[i]);
    v1 := length(S1.Strings[i]);
    OldName := copy(S1.Strings[i],1,v-1);
    NewName := copy(S1.Strings[i],v+1,v1-v);
    //if FileExists(Path+OldName) then
    //begin
      //ReNameFile(Path+OldName,Path+NewName);
      S.Add(NewName);
      S.SaveToFile(Path+'scanlist.dat');
    //end;
  end;
  ReSortFileName2Scanlist(Path);
  finally
  S.Free;
  S1.Free;
  end;
end;
 
 
 
{ ==============================================================================
  方法名稱:DistinctDocinCase
  引用相依:LoadFileGetMD5, LoadFromFile
  方法描述:列出案件目錄下所有具備文件編號與版本的唯一組合。
============================================================================== }
Procedure TCB_IMGPSScanX.DistinctDocinCase(Path:String); //列出案件裡的Docno_版本
var
  i,n,v : Integer;
  S : TStringlist;
  FormCode,DocNo,Ver : String;
  Doc_Ver : String;
  Exists : Boolean;
begin
  S := TSTringlist.Create;
  try
    DocNo_VerinCase.Clear;
    S.LoadFromFile(Path+'Context.dat');
    for I := 0 to S.Count - 1 do
    begin
      if FWH_category='N' then
      begin
        if (ISExistImg(Path+S.Strings[i])) or (reSizeExistImgList.IndexOf(LoadFileGetMD5(Path+S.Strings[i]))<>-1)  then
        begin
          Continue;
        end;
      end;
      FormCode := FileName2FormCode(S.Strings[i]);
      DocNo := FormCode2DocNo(FormCode);
      Ver := FormCode2Version(FormCode);
      if (Docno <> '') and (Ver <> '') then
      begin
        Doc_Ver := DocNo+'_'+Ver;
        Exists := False;
        for n := 0 to DocNo_VerinCase.Count-1 do
        begin
          if Doc_Ver = DocNo_VerinCase.Strings[n] then
          begin
            Exists := True;
            Break;
          end;
        end;
        if not Exists then
          DocNo_VerinCase.Add(Doc_Ver);
      end;
    end;
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:DistinctDocNoinCase
  引用相依:LoadFromFile
  方法描述:列出案件目錄下所有實際存在的文件編號(DocNo)。
============================================================================== }
Procedure TCB_IMGPSScanX.DistinctDocNoinCase(Path:String); //列出案件裡的Docno
var
  i,n,v : Integer;
  S : TStringlist;
  FormCode,DocNo,Ver : String;
  Exists : Boolean;
begin
  S := TSTringlist.Create;
  try
    CaseDocNoList.Clear;
    S.LoadFromFile(Path+'Context.dat');
    for I := 0 to S.Count - 1 do
    begin
      FormCode := FileName2FormCode(S.Strings[i]);
      DocNo := FormCode2DocNo(FormCode);
      if (Docno <> '') then
      begin
        Exists := False;
        for n := 0 to CaseDocNoList.Count-1 do
        begin
          if DocNo = CaseDocNoList.Strings[n] then
          begin
            Exists := True;
            Break;
          end;
        end;
        if not Exists then
          CaseDocNoList.Add(DocNo);
      end;
    end;
  finally
  S.Free;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:ClearErrini
  引用相依:FileExists
  方法描述:清除指定案件的所有檢核輔助檔案(如 Checkerr.ini, OMRCheckOk 等),並將
            樹狀節點恢復為預設的影像索引狀態。
============================================================================== }
Procedure TCB_IMGPSScanX.ClearErrini(CaseID:String;CaseNode:TTreeNode); //清掉檢核檔案
var
  i : Integer;
begin
  if FileExists(ImageSavePath+CaseID+'\Checkerr.ini') then
    DeleteFile(ImageSavePath+CaseID+'\Checkerr.ini');
  if FileExists(ImageSavePath+CaseID+'\CheckMemo.dat') then
    DeleteFile(ImageSavePath+CaseID+'\CheckMemo.dat');
  {if FileExists(ImageSavePath+CaseID+'\ReSize.dat') then  //20110421拿掉  因為記錄會不見
    DeleteFile(ImageSavePath+CaseID+'\ReSize.dat');}
  if FileExists(ImageSavePath+CaseID+'\RemoveMemo.dat') then
    DeleteFile(ImageSavePath+CaseID+'\RemoveMemo.dat');
  if FileExists(ImageSavePath+CaseID+'\OMRCheckOk.dat') then
    DeleteFile(ImageSavePath+CaseID+'\OMRCheckOk.dat');
  CaseHelpBtn.Visible := False;
  CaseNode.ImageIndex := 2;
  CaseNode.SelectedIndex := 2;
end;
 
 
{ ==============================================================================
  方法名稱:SetCaseList
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:維護本地案件清單資料。支援對 CaseList.dat 執行加入、插入、刪除或修改案
            號操作,確保本地磁碟目錄與資料清單狀態同步。
============================================================================== }
Procedure TCB_IMGPSScanX.SetCaseList(Mode:Char;Index:Integer;text:String);  //'A:加入,I:插入,D:刪除,E:修改'
var
  i : Integer;
begin
  CaseList.Clear;
  if FileExists(ImageSavePath + 'CaseList.dat') then
    CaseList.LoadFromFile(ImageSavePath + 'CaseList.dat');
  case Mode of
    'A':begin
          CaseList.Add(Text);
        end;
    'I':begin
          CaseList.Insert(Index,Text);
        end;
    'E':begin
          CaseList.Strings[Index] := Text;
        end;
    'D':begin
          if Index <> -1 then
            CaseList.Delete(Index)
          Else if (text <> '') then
          begin
            for i := 0 to CaseList.Count - 1 do
            begin
              if Text = CaseList.Strings[i] then
              begin
                CaseList.Delete(i);
                Break;
              end;
            end;
          end;
          if CaseList.Count = 0 then
              DeleteFile(ImageSavePath + 'CaseList.dat');
        end;
  end;
  if CaseList.Count > 0 then
    CaseList.SaveToFile(ImageSavePath+'CaseList.dat');
end;
 
 
{ ==============================================================================
  方法名稱:SetDocNoList
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:維護案件的文件目錄清單(CaseDocNo.dat)與份數清單(CaseDocNo_Copies.dat
            )。根據 Mode 參數執行「加入 (A)」、「插入 (I)」、「修改 (E)」或「刪除 (D)」操作
            。刪除時支援透過索引或目錄名稱進行,並會同步更新異動記錄(SetRecordEdit
            edDocDir)。最後將更新後的清單存回檔案。
============================================================================== }
Procedure TCB_IMGPSScanX.SetDocNoList(Mode:Char;Index:Integer;CaseNo,DocDir,Copies:String);  //'A:加入,I:插入,D:刪除,E:修改'
var
  i : Integer;
  CaseDocNoList : TStringlist;
  CaseDocNo_copiesList : TStringlist;
begin
  CaseDocNoList := TStringlist.Create;
  CaseDocNo_CopiesList := TStringlist.Create;
  try
    CaseDocNoList.Clear;
    if FileExists(ImageSavePath+CaseNo+'\CaseDocNo.dat') then
      CaseDocNoList.LoadFromFile(ImageSavePath+CaseNo+'\CaseDocNo.dat');
    if FileExists(ImageSavePath+CaseNo+'\CaseDocNo_Copies.dat') then
      CaseDocNo_CopiesList.LoadFromFile(ImageSavePath+CaseNo+'\CaseDocNo_Copies.dat');
    case Mode of
      'A':begin
            CaseDocNoList.Add(DocDir);
            CaseDocNo_CopiesList.Add(Copies);
            SetRecordEditedDocDir('A',CaseNo,DocDir);
          end;
      'I':begin
            CaseDocNoList.Insert(Index,DocDir);
            CaseDocNo_CopiesList.Insert(Index,Copies);
          end;
      'E':begin
            CaseDocNoList.Strings[Index] := DocDir;
            CaseDocNo_CopiesList.Strings[Index] := Copies;
          end;
      'D':begin
            if Index <> -1 then
            begin
              //SetRecordEditedDocDir('D',CaseNo,CaseDocNoList.Strings[Index]);  //20140624 修改刪除文件時也記一筆異動,刪掉會無法通知前端網頁有異動
              SetRecordEditedDocDir('A',CaseNo,CaseDocNoList.Strings[Index]);  //20170912 要刪除  不然我寫不下去
 
              CaseDocNoList.Delete(Index);
              CaseDocNo_CopiesList.Delete(Index);
 
            end
            Else if (DocDir <> '') then
            begin
              for i := 0 to CaseDocNoList.Count - 1 do
              begin
                if DocDir = CaseDocNoList.Strings[i] then
                begin
                  //SetRecordEditedDocDir('D',CaseNo,CaseDocNoList.Strings[i]);  //20140624 修改刪除文件時也記一筆異動,刪掉會無法通知前端網頁有異動
                  SetRecordEditedDocDir('A',CaseNo,CaseDocNoList.Strings[i]);  //20170912 要刪除  不然我寫不下去
                  CaseDocNoList.Delete(i);
                  CaseDocNo_CopiesList.Delete(i);
                  Break;
                end;
              end;
            end;
            if ContextList.Count = 0 then
            begin
              DeleteFile(ImageSavePath+CaseNo+'\CaseDocNo.dat');
            end;
          end;
    end;
    //Showmessage('abc'+#13+ImageSavePath+CaseNo+'\CaseDocNo.dat'+#13+inttostr(CaseDocNoList.Count)+#13+CaseDocNoList.Text);
    if CaseDocNoList.Count >= 0 then
    begin
      CaseDocNoList.SaveToFile(ImageSavePath+CaseNo+'\CaseDocNo.dat');
      CaseDocNo_CopiesList.SaveToFile(ImageSavePath+CaseNo+'\CaseDocNo_Copies.dat');
      //Showmessage('存了');
    end;
  finally
  CaseDocNoList.Free;
  CaseDocNo_CopiesList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:SetContextList
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:維護特定文件目錄下的影像檔案清單(Context.dat)。支援「加入」、「插入」、「修
            改」與「刪除」模式。操作前會先從磁碟載入既有的清單,執行變動後再存回,並記
            錄該文件目錄已被異動。
============================================================================== }
Procedure TCB_IMGPSScanX.SetContextList(Mode:Char;Index:Integer;CaseNo,DocDir,FileName:String);  //'A:加入,I:插入,D:刪除,E:修改'
var
  i : Integer;
  //DocNo:String;
begin
  //DocNo := FormCode2DocNo(FileName2FormCode(FileName));
//ShowMessage('FileName='+FileName);
  if DocDir = '' then
    DocDir := AttName ; //附件
  ContextList.Clear;
  if FileExists(ImageSavePath+CaseNo+'\'+DocDir+'\Context.dat') then
    ContextList.LoadFromFile(ImageSavePath+CaseNo+'\'+DocDir+'\Context.dat');
  SetRecordEditedDocDir('A',CaseNo,DocDir);  //記錄文件有異動
  case Mode of
    'A':begin
          ContextList.Add(FileName);
        end;
    'I':begin
          ContextList.Insert(Index,FileName);
        end;
    'E':begin
          ContextList.Strings[Index] := FileName;
        end;
    'D':begin
          if Index <> -1 then
          begin
            ContextList.Delete(Index);
          end
          Else if (text <> '') then
          begin
            for i := 0 to ContextList.Count - 1 do
            begin
              if FileName = ContextList.Strings[i] then
              begin
                ContextList.Delete(i);
                Break;
              end;
            end;
          end;
          if ContextList.Count = 0 then
            DeleteFile(ImageSavePath+CaseNo+'\'+DocDir+'\Context.dat');
        end;
  end;
  if ContextList.Count > 0 then
  begin
    ContextList.SaveToFile(ImageSavePath+CaseNo+'\'+DocDir+'\Context.dat');
  end;
end;
 
 
{ ==============================================================================
  方法名稱:SetAttContextList
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:維護案件的附件檔案清單(AttContext.dat)。邏輯與 SetContextList 相似,針
            對附件目錄進行檔案名稱的「加入」、「插入」、「修改」與「刪除」管理,並將結果持
            久化至磁碟。
============================================================================== }
Procedure TCB_IMGPSScanX.SetAttContextList(Mode:Char;Index:Integer;CaseNo,FileName:String);  //'A:加入,I:插入,D:刪除,E:修改'
var
  i : Integer;
begin
  AttContextList.Clear;
  if FileExists(ImageSavePath+CaseNo+'\AttContext.dat') then
    AttContextList.LoadFromFile(ImageSavePath+CaseNo+'\AttContext.dat');
  case Mode of
    'A':begin
          AttContextList.Add(FileName);
        end;
    'I':begin
          AttContextList.Insert(Index,FileName);
        end;
    'E':begin
          AttContextList.Strings[Index] := FileName;
        end;
    'D':begin
          if Index <> -1 then
          begin
            AttContextList.Delete(Index);
          end
          Else if (text <> '') then
          begin
            for i := 0 to AttContextList.Count - 1 do
            begin
              if FileName = AttContextList.Strings[i] then
              begin
                AttContextList.Delete(i);
                Break;
              end;
            end;
          end;
          if AttContextList.Count = 0 then
            DeleteFile(ImageSavePath+CaseNo+'\AttContext.dat');
        end;
  end;
  if AttContextList.Count > 0 then
  begin
    AttContextList.SaveToFile(ImageSavePath+CaseNo+'\AttContext.dat');
  end;
end;
 
 
{ ==============================================================================
  方法名稱:checkCaseOMRDone
  引用相依:
  方法描述:檢查當前案件是否已完成 OMR 檢核。遍歷 NewTreeNode 中的所有項目,判斷其
             ImageIndex 是否皆為 7(代表已檢核通過的圖示索引),若有任何一項未達成
            則回傳 False。
============================================================================== }
Function TCB_IMGPSScanX.checkCaseOMRDone:Boolean;  //檢查案件是否完成OMR檢核
var
  i : Integer;
begin
  Result := True;
  for I := 0 to NewTreeNode.Count - 1 do
  begin
    if NewTreeNode.Item[i].ImageIndex <> 7 then
    begin
      Result := False;
      Break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:checkFormCodeIsCustom
  引用相依:
  方法描述:檢查指定的表單代碼(FormCode)是否為自定義文件。透過讀取 CustomDocNo.in
            i 設定檔中的 FormID 資訊,比對傳入的代碼是否與設定值一致。
============================================================================== }
function TCB_IMGPSScanX.checkFormCodeIsCustom(path, formcode: string): boolean;
var
  i:integer;
  ini : Tmeminifile;
  str1:String;
begin
//ShowMessage(path);
  ini := Tmeminifile.Create(Path+'CustomDocNo.ini');
  str1:=ini.ReadString(Copy(formcode,1,8),'FormID','');
//ShowMessage('str1'+str1);
  if str1 = formcode then
  begin
    Result:=True;
  end
  else
  begin
    Result := False;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:CheckCaseID_OK
  引用相依:
  方法描述:檢查樹狀結構中是否存在「未配號」的案件。遍歷所有節點,若節點文字包含「未
            配號」字樣則回傳 False。
============================================================================== }
Function TCB_IMGPSScanX.CheckCaseID_OK:Boolean;  //檢查是否有未配號的案件
var
  i,n : Integer;
begin
  Result := True;
  for i := 0 to NewTreeNode.Count - 1 do
  begin
    if Pos(_msg('未配號'),NewTreeNode.Item[i].Text) > 0 then
    begin
      Result := False;
      Break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CheckCaseAttach_OK
  引用相依:
  方法描述:檢查樹狀結構中是否存在「未歸類」的文件。遞迴遍歷案件下的所有子節點,若有
            任何節點文字包含「未歸類」則回傳 False。
============================================================================== }
Function TCB_IMGPSScanX.CheckCaseAttach_OK:Boolean;  //檢查是否有未歸類的案件
var
  i,j : Integer;
begin
  Result := True;
  for i := 0 to NewTreeNode.Count - 1 do
  begin
    for j := 0 to NewTreeNode.Item[i].Count - 1 do
    begin
      if Pos(_msg('未歸類'),NewTreeNode.Item[i].Item[j].Text) > 0 then
      begin
        Result := False;
        Break;
      end;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CreateEmptyCase
  引用相依:SaveToFile
  方法描述:產生一個空白的案件結構,主要用於重掃件。建立必要的目錄,並產生初始的 Co
            ntext.dat 與更新 CaseList.dat。
============================================================================== }
Procedure TCB_IMGPSScanX.CreateEmptyCase(Path,CaseID:String);  //產生空白案號(重掃件用)
var
  S : TStringlist;
begin
  S := TStringlist.Create;
  try
    S.SaveToFile(Path+CaseID+'\Context.dat');
    S.Add(FCaseID);
    S.SaveToFile(Path+'CaseList.dat')
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:InitScrollRec
  引用相依:
  方法描述:初始化影像捲軸記錄,將 1 到 8 號影像視窗的水平與垂直捲軸位置重設為 0。
============================================================================== }
Procedure TCB_IMGPSScanX.InitScrollRec;
var i : Integer;
begin
  for I := 1 to 8 do
  begin
    ScrollRec[i].HScroll := 0;
    ScrollRec[i].VScroll := 0;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:FormIDReplace
  引用相依:CopyFile, DirectoryExists, FileExists, LoadFromFile, RenameFile, Sav
            eToFile
  方法描述:將指定文件中的舊表單代碼替換為新代碼。首先決定目標目錄(考慮是否分份數
            、補件狀況),若目標目錄不存在則建立。接著將符合舊代碼的檔案複製到新目錄
            下並重新命名(產生新序號),同時更新新目錄的 Context.dat 與清單。最後刪
            除原目錄中的舊代碼檔案。
============================================================================== }
Procedure TCB_IMGPSScanX.FormIDReplace(CaseID,DocDir,OldFormID,NewFormID:String); //指定FormID更換成新的FormID
var
  i : Integer;
  OldFileList,NewFileList : TStringlist;
  NewDocNo,NewDocDir:String;
  FormID : String;
  OldFile,NewFile:String;
  Ext : String;
  ST1:TStringList;
begin
  ST1:=TStringList.Create;
  OldFileList := TStringlist.Create;
  NewFileList := TStringlist.Create;
  try
    NewDocNo := FormCode2DocNo(NewFormID);
    NewDocDir := FindLastestDocDir(CaseID,NewDocNo);
 
    /////20190319 Hong 原本的程式判斷怪怪的先Mark在下方,改用這段
    if DocNoNeedDiv(NewDocNo) then   //要分份數
    begin
      if ((FormCode2Page(NewFormID) = '01') and (GetDocDir_Page(CaseID,NewDocDir)>0)) or (NewDocDir = '') then
      begin
        NewDocDir := DocNo2DocNoDir(ImageSavePath + CaseID+'\',NewDocNo);
      end
      else
      begin //20171016  真對補件影響 所加的判斷
        ST1.Clear;
        if FileExists(ImageSavePath + CaseID+'\'+NewDocDir+'\Context.dat') then
        begin
          ST1.LoadFromFile(ImageSavePath + CaseID+'\'+NewDocDir+'\Context.dat');
          if (ST1.Count > 0) and ISExistImg(ImageSavePath + CaseID+'\'+NewDocDir+'\'+ST1.Strings[0]) then   //20181210 多增加判斷ST1>0 否則會有機會出現List out of bound  Hong
          begin
            NewDocDir := DocNo2DocNoDir(ImageSavePath + CaseID+'\',NewDocNo);
          end;
        end;
      end;
    end
    Else        //不分份數
    begin
      if NewDocNo <> '' then
        NewDocDir := NewDocNo
      else      //Attach 附件
        NewDocDir := DocNo2DocNoDir(ImageSavePath + CaseID+'\',NewDocNo);
    end;
 
    {if NewDocDir = '' then
    begin
      if DocNoNeedDiv(NewDocNo) then
      begin
        NewDocDir:=DocNo2DocNoDir(ImageSavePath + NowCaseno+'\',NewDocNo);
      end
      else
      begin
        NewDocDir := NewDocNo;
      end;
    end;
//ShowMessage('NewDocDir='+NewDocDir);
    if DocNoNeedDiv(NewDocNo) and (FormCode2Page(NewFormID)='01') then
    begin
      NewDocDir := DocNo2DocNoDir(ImageSavePath+CaseID+'\',NewDocNo);
    end
    else
    begin
      ST1.Clear;
      if FileExists(ImageSavePath + NowCaseno+'\'+NewDocDir+'\Context.dat') then
      begin
        ST1.LoadFromFile(ImageSavePath + NowCaseno+'\'+NewDocDir+'\Context.dat');
        if ISExistImg(ImageSavePath + NowCaseno+'\'+NewDocDir+'\'+ST1.Strings[0]) then
        begin
          NewDocDir := DocNo2DocNoDir(ImageSavePath + NowCaseno+'\',NewDocNo);
        end;
      end;
    end; }
    if Not DirectoryExists(ImageSavePath+CaseID+'\'+NewDocDir) then
    begin
      MkDir(ImageSavePath+CaseID+'\'+NewDocDir);
      SetDocNoList('A',-1,CaseID,NewDocDir,'1');
    end;
    if FileExists(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat') then
      OldFileList.LoadFromFile(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat');
    if FileExists(ImageSavePath+CaseID+'\'+NewDocDir+'\Context.dat') then
      NewFileList.LoadFromFile(ImageSavePath+CaseID+'\'+NewDocDir+'\Context.dat');
    for i := 0 to OldFileList.Count - 1 do
    begin
      OldFile := OldFileList.Strings[i];
      Ext := ExtractFileExt(OldFile);
      if FileName2FormCode(OldFile) = OldFormID then
      begin
        NewFile := Add_Zoo(NewFileList.Count+1,3)+'_'+NewFormID+Ext;
        CopyFile(PWideChar(ImageSavePath+CaseID+'\'+DocDir+'\'+OldFile),PWideChar(ImageSavePath+CaseID+'\'+NewDocDir+'\'+NewFile),False);
        NewFileList.Add(NewFile);
        SetContextList('A',-1,CaseID,NewDocDir,NewFile);
      end;
    end;
    DeleteFormCodeFile(CaseID,DocDir,OldFormID);
 
    {for i := 0 to S.Count - 1 do
    begin
      FormID := FileName2FormCode(S.Strings[i]);
      if FormID = OldFormID then
      begin
        OldFile := S.Strings[i];
        Ext := ExtractFileExt(OldFile);
        //NewFile := Copy(S.Strings[i],1,3)+'_'+NewFormID+Ext;
        NewFile := Add_Zoo(FileName2ScanPage(S.Strings[i]),3)+'_'+NewFormID+Ext;
        ReNameFile(Path+OldFile,Path+NewFile);
        S.Strings[i] := NewFile;
      end;
    end;
    S.SaveToFile(Path+'Context.dat');
    ContextList.LoadFromFile(Path+'Context.dat'); }
 
  finally
  OldFileList.Free;
  NewFileList.Free;
  ST1.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ShowFileReplace
  引用相依:RenameFile
  方法描述:將當前顯示清單(NowShowFileList)中的檔案更名為新的表單代碼。遍歷檔案,
            保留原序號但替換 FormID 部分,執行實體更名並同步更新全域的 ContextLis
            t 記錄。
============================================================================== }
Procedure TCB_IMGPSScanX.ShowFileReplace(Path,NewFormID:String);//顯示的影像換成新的FormID
var
  i,n : Integer;
  OldFile,NewFile:String;
  Ext : String;
begin
  for i := 0 to NowShowFileList.Count - 1 do
  begin
    OldFile := NowShowFileList.Strings[i];
    Ext := ExtractFileExt(OldFile);
    NewFile := Add_Zoo(FileName2ScanPage(OldFile),3)+'_'+NewFormID+Ext;
    ReNameFile(Path+OldFile,Path+NewFile);
    SetContextList('E',FileName2Index(OldFile),NowCaseno,NowDocNo,NewFile);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:PageReplaceFormID
  引用相依:LoadFromFile, RenameFile, SaveToFile
  方法描述:針對影像列表(PageLV)中選取的頁面進行表單代碼更換。先過濾出符合條件的
            檔案,再對選取項執行實體檔案更名(更新 FormID 部分),最後同步更新 Conte
            xt.dat 檔案內容。
============================================================================== }
Procedure TCB_IMGPSScanX.PageReplaceFormID(Path,NowFormID,NewFormID:String); //選取頁更換FormID
var
  i,n : Integer;
  S,S1 : TStringlist;
  OldFile,NewFile:String;
  Ext : String;
begin
  S := TStringlist.Create;
  S1 := TStringlist.Create;
  try
    S.LoadFromFile(Path+'Context.dat');
    for i := 0 to S.Count - 1 do
    begin
      if NowFormID = 'ALL' then
        S1.Add(S.Strings[i])
      Else if NowFormID = 'Err' then
      begin
        if not FormIDExists(FileName2FormCode(S.Strings[i]),False,0) then
          S1.Add(S.Strings[i])
      end
      Else
      begin
        if NowFormID = FileName2FormCode(S.Strings[i]) then
          S1.Add(S.Strings[i])
      end;
    end;
    for I := 0 to PageLV.Items.Count - 1 do
    begin
      if PageLV.Items.Item[i].Selected then
      begin
        OldFile := S1.Strings[i];
        Ext := ExtractFileExt(OldFile);
        //NewFile := Copy(S1.Strings[i],1,3)+'_'+NewFormID+Ext;
        NewFile := Add_Zoo(FileName2ScanPage(S1.Strings[i]),3)+'_'+NewFormID+Ext;
        ReNameFile(Path+OldFile,Path+NewFile);
        for n := 0 to S.Count - 1 do
        begin
          if OldFile = S.Strings[n] then
            S.Strings[n] := NewFile;
        end;
      end;
    end;
    S.SaveToFile(Path+'Context.dat');
    ContextList.LoadFromFile(Path+'Context.dat');
  finally
  S.Free;
  S1.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ModeNeedCheck
  引用相依:
  方法描述:判斷目前的掃瞄模式是否需要執行 OMR 檢核。
============================================================================== }
Function TCB_IMGPSScanX.ModeNeedCheck(OMRMode,ScanMode:String):Boolean; //掃瞄模式是否要做檢核
begin
  Result := False;
  if Pos(ScanMode,OMRMode) > 0 then
    Result := True;
end;
 
 
{ ==============================================================================
  方法名稱:GetCasePage
  引用相依:FileExists, LoadFromFile
  方法描述:計算案件的總影像頁數。遍歷案件下所有的文件目錄(CaseDocNo.dat),讀取每
            個目錄的 Context.dat 並累加檔案數量。過程中會考慮入庫/非入庫文件的權
            限與顯示過濾條件,最後也包含附件目錄的計數。
============================================================================== }
Function TCB_IMGPSScanX.GetCasePage(Path,CaseID:String):Integer;
var
  DocDirList,FileList,ST1 :TStringlist;
  iDocDir,iDocNo : String;
  i,n,Count : Integer;
begin
  Count := 0;
  DocDirList := TStringlist.Create;
  FileList := TStringlist.Create;
  ST1:=TStringList.Create;
  try
    if FileExists(Path+CaseID+'\CaseDocNo.dat') then
      DocDirList.LoadFromFile(Path+CaseID+'\CaseDocNo.dat');
    //Showmessage(DocDirList.Text);
    for i := 0 to DocDirList.Count - 1 do
    begin
      iDocDir := DocDirList.Strings[i];
      iDocno := DocNoDir2DocNo(iDocDir);
      {if (((FIs_In_Wh  = 'Y') and (not DocNoIs_In_WH(iDocNo))) or   //入庫掃描不看非入庫文件
         ((FIs_In_Wh  = 'N') and (DocNoIs_In_WH(iDocNo)))) and
         ((iDocNo <> 'Attach') and (Copy(iDocNo,1,5)<>'ZZZZZ')) then     //非入庫掃描不看入庫文件
      begin
        Continue;
      end;}
      //if not DocNoAppear(iDocNo) then Continue; //20170817 先註解
 
      FileList.Clear;
      if FileExists(Path+CaseID+'\'+iDocDir+'\Context.dat') then
      begin
        FileList.LoadFromFile(Path+CaseID+'\'+iDocDir+'\Context.dat');
 
        if (FWH_category='N') and (FIs_In_Wh='Y') then
        begin
          ST1.Clear;
          for n := 0 to FileList.Count - 1 do
          begin
            if ISExistImg(Path+CaseID+'\'+iDocDir+'\'+FileList.Strings[n]) then
            begin
              ST1.Add(FileList.Strings[n]);
            end;
          end;
 
          for n := 0 to ST1.Count - 1 do
          begin
            if (FileList.IndexOf(ST1.Strings[n])<>-1) and (not DocNoIs_In_WH(iDocNo)) then
            begin
              FileList.Delete(FileList.IndexOf(ST1.Strings[n]));
            end;
          end;
        end
        Else
          if not DocNoAppear(iDocNo) then Continue; //20180925 Hong覺得應該要加這段
      end;
 
 
      Count := Count+ FileList.Count;
    end;
    if FileExists(Path+CaseID+'\'+AttName+'\Context.dat') then
    begin
      FileList.LoadFromFile(Path+CaseID+'\'+AttName+'\Context.dat');
      Count := Count+ FileList.Count;
    end;
 
    Result := Count;
  finally
  DocDirList.Free;
  FileList.Free;
  ST1.free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GetFormIDPage
  引用相依:
  方法描述:在指定的檔案清單中,計算符合特定表單代碼(FormID)的影像頁數。
============================================================================== }
Function TCB_IMGPSScanX.GetFormIDPage(FileList:TStringlist;FormID:String):Integer;
var
  i,Cnt : Integer;
begin
  Cnt := 0;
  for i := 0 to FileList.Count - 1 do
  begin
    if FormID = FileName2FormCode(FileList.Strings[i]) then
    begin
      inc(Cnt);
    end;
  end;
  Result := Cnt;
end;
 
 
{ ==============================================================================
  方法名稱:SetFile2Case
  引用相依:LoadFromFile, SaveToFile
  方法描述:將指定的檔案名稱加入到案件的主 Context.dat 清單中。
============================================================================== }
Procedure TCB_IMGPSScanX.SetFile2Case(CaseID,FileName:String);
var
  S :TStringlist;
begin
  S := TStringlist.Create;
  try
    S.LoadFromFile(ImageSavePath+CaseID+'\Context.dat');
    S.Add(FileName);
    S.SaveToFile(ImageSavePath+CaseID+'\Context.dat');
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:WriteResize
  引用相依:FileExists, GetTag, LoadFromFile, SaveToFile
  方法描述:產生影像縮放記錄檔(Resize.dat)。載入影像後比對原始標記(Tag)中的長寬資
            訊與實際 Graphic 的長寬,若有變動則將差異記錄至文字檔中。
============================================================================== }
Procedure TCB_IMGPSScanX.WriteResize(ImgName,TxtName:String); //產生Resize.dat
var
  TagTxt : String;
  RecHeight,RecWidth : String;
  ImgHeight,ImgWidth : String;
  S : TStringlist;
  v,v1:Integer;
begin
  ImageScrollBox1.LoadFromFile(ImgName,1);
  ImgHeight := Inttostr(ImageScrollBox1.Graphic.Height);
  ImgWidth := Inttostr(ImageScrollBox1.Graphic.Width);
  Try
    TagTxt := GetTag(ImgName);
  Except
    TagTxt := '';
  End;
  if TagTxt <> '' then
  begin
    S := TStringlist.Create;
    try
      S.CommaText := TagTxt;
      if S.Count = 2 then
      begin
        v := Pos(':',S.Strings[0]);
        v1 := length(S.Strings[0]);
        RecHeight := Copy(S.Strings[0],v+1,v1-v);
        v := Pos(':',S.Strings[1]);
        v1 := length(S.Strings[1]);
        RecWidth := Copy(S.Strings[1],v+1,v1-v);
      end;
      S.Clear;
      if FileExists(TxtName) then
        S.LoadFromFile(TxtName);
      if (RecHeight <> '') and (RecWidth <> '') and ((RecHeight<>ImgHeight) or (RecWidth<>ImgWidth)) then
        S.Add(ExtractfileName(ImgName)+',原長:'+RecHeight+',原寬:'+RecWidth+',長變動:'+ImgHeight+',寬變動:'+ImgWidth);
      S.SaveToFile(TxtName);
    finally
    S.Free;
    end;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:GetCase_PageCount
  引用相依:FileExists, LoadFromFile
  方法描述:獲取所有案件的總數量與總頁數。讀取 CaseList.dat 取得案件清單,逐一計算
            各案件目錄與附件目錄下的影像檔案數。針對非入庫且當次掃瞄的特殊情況,會
            額外檢查 EditedDocDir.dat 以精確計算實際變動的頁數。
============================================================================== }
Function TCB_IMGPSScanX.GetCase_PageCount(var CaseCount,PageCount:Integer):Boolean; //取出案件的數量及頁數
var
  i,n,k: Integer;
  CaseList,DocList,FileList,ST1 : TStringlist;
begin
  Result := False;
  CaseCount := 0;
  PageCount := 0;
  CaseList := TStringlist.Create;
  DocList := TStringlist.Create;
  FileList := TStringlist.Create;
  ST1:= TStringlist.Create;
  try
    ImageSavePath := ImagePath;
    CaseList.Clear;
    if FileExists(ImageSavePath + 'CaseList.dat') then
      CaseList.LoadFromFile(ImageSavePath + 'CaseList.dat');
    CaseCount :=  CaseCount+CaseList.Count;
//ShowMessage('ImageSavePath='+ImageSavePath+#10#13+'CaseList.Count='+IntToStr(CaseList.Count));
    for i := 0 to CaseList.Count - 1 do
    begin
      DocList.Clear;
      If FileExists(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo.dat') Then
        DocList.LoadFromFile(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo.dat');
//ShowMessage('DocList='+DocList.Text);
      for n := 0 to DocList.Count - 1 do
      begin
//ShowMessage(DocList.Strings[n]+','+BoolToStr(DocNoAppear(DocNoDir2DocNo(DocList.Strings[n])),true));
        if not DocNoAppear(DocNoDir2DocNo(DocList.Strings[n])) then Continue;
        FileList.Clear;
        If FileExists(ImageSavePath+CaseList.Strings[i]+'\'+DocList.Strings[n]+'\Context.dat') Then
          FileList.LoadFromFile(ImageSavePath+CaseList.Strings[i]+'\'+DocList.Strings[n]+'\Context.dat');
        PageCount := PageCount+FileList.Count;
      end;
      //Showmessage(inttostr(PageCount));
      FileList.Clear;
      If FileExists(ImageSavePath+CaseList.Strings[i]+'\'+Attname+'\Context.dat') Then
          FileList.LoadFromFile(ImageSavePath+CaseList.Strings[i]+'\'+Attname+'\Context.dat');
      //Showmessage(ImageSavePath+CaseList.Strings[i]+'\'+Attname+'\Context.dat');
//Showmessage('FileList='+FileList.Text);
      PageCount := PageCount+FileList.Count;
//Showmessage('PageCount='+inttostr(PageCount));
      if (FWH_category='N') and (FIs_In_Wh='Y') then  //20170912 針對非入庫並當次掃描做頁數計算
      begin
        if FileExists(ImageSavePath+NowCaseno+'\EditedDocDir.dat') then
        begin
          ST1.LoadFromFile(ImageSavePath+NowCaseno+'\EditedDocDir.dat');
          for n := 0 to ST1.Count - 1 do
          begin
            if ST1.Strings[n]=AttName then  Continue;
//ShowMessage(ST1.Strings[n]+','+BoolToStr(DocNoIs_In_WH(DocNoDir2DocNo(ST1.Strings[n])),true));
            if not DocNoIs_In_WH(DocNoDir2DocNo(ST1.Strings[n])) then
            begin
 
              FileList.Clear;
              if FileExists(ImageSavePath+CaseList.Strings[i]+'\'+ST1.Strings[n]+'\Context.dat') then
              begin
                FileList.LoadFromFile(ImageSavePath+CaseList.Strings[i]+'\'+ST1.Strings[n]+'\Context.dat');
                for k := 0 to FileList.Count - 1 do
                begin
                  if not ISExistImg(ImageSavePath+CaseList.Strings[i]+'\'+ST1.Strings[n]+'\'+FileList.Strings[k]) then
                    PageCount := PageCount+1;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
  Finally
  CaseList.Free;
  DocList.Free;
  FileList.Free;
  ST1.Free
  end;
  Result := True;
end;
 
 
{ ==============================================================================
  方法名稱:FindNoSaveBarCode
  引用相依:
  方法描述:檢查目前的條碼資訊中是否包含被標記為「不儲存影像」的條碼。遍歷所有辨識
            到的條碼,並與排除清單(NoSaveBarCodeList)進行比對,若匹配則回傳 True。
============================================================================== }
Function TCB_IMGPSScanX.FindNoSaveBarCode : Boolean; //找是否有不要儲存影像的條碼
var
  i,n : Integer;
begin
  Result := False;
  for i := 1 to MpsBarcodeinf.Count do
  begin
    for n := 0 to NoSaveBarCodeList.Count - 1 do
    begin
      if MpsBarcodeinf.Text[i] = NoSaveBarCodeList.Strings[n] then
      begin
        Result := True;
        Break;
      end;
    end;
    if Result then
      Break;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:WriteCaseIndex
  引用相依:SaveToFile
  方法描述:將案件的信用註記狀態(Case_loandoc)寫入到指定路徑下的 CaseIndex.dat 
            檔案中。
============================================================================== }
Procedure TCB_IMGPSScanX.WriteCaseIndex(Path:String);
Var
  S : TStringlist;
begin
  if Path = '' then Exit;
  S := TStringlist.Create;
  try
    try
      S.Add(Case_loandoc);
      S.SaveToFile(Path+'CaseIndex.dat');
    except on E: Exception do
    end;
 
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ReadCaseIndex
  引用相依:FileExists, LoadFromFile
  方法描述:從磁碟讀取案件索引檔(CaseIndex.dat)。載入信用註記狀態,並據此更新畫面
            上 AddCredit1RG 選項組的選取狀態(Y 設為第一項,N 設為第二項)。若檔案不
            存在但有預設值,則自動建立檔案。
============================================================================== }
Procedure TCB_IMGPSScanX.ReadCaseIndex(Path:String);
Var
  S : TStringlist;
begin
  AddCredit1RG.ItemIndex := -1;
  S := TStringlist.Create;
  try
    if FileExists(Path+'CaseIndex.dat') then
    begin
      S.LoadFromFile(Path+'CaseIndex.dat');
      Case_loandoc := S.Strings[0];
    end;
    if (Case_loandoc = '') and (FLoanDoc_Value <> '') then
    begin
      Case_loandoc := FLoanDoc_Value;
      WriteCaseIndex(Path);
    end;
    if Case_loandoc = 'Y' then
      AddCredit1RG.ItemIndex := 0
    Else if Case_loandoc = 'N' then
      AddCredit1RG.ItemIndex := 1;
 
  finally
  S.Free;
  end;
 
end;
 
 
 
{ ==============================================================================
  方法名稱:ReduceLogFile
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:防止日誌檔案過大。檢查 IMGPSCheck.log,若行數超過 100,000 行,則自動刪
            除最前面的 10,000 行記錄並重新存檔。
============================================================================== }
procedure TCB_IMGPSScanX.ReduceLogFile; //20171011 必免log檔掌太大
var
  ST1:TStringlist;
  I:integer;
begin
  ST1:=TStringList.Create;
  if FileExists(LngPath+'IMGPSCheck.log') then
  begin
    ST1.LoadFromFile(LngPath+'IMGPSCheck.log');
    if ST1.count>100000 then
    begin
      for I := 0 to 10000 do
      begin
        ST1.Delete(0);
      end;
      ST1.SaveToFile(LngPath+'IMGPSCheck.log');
    end;
  end;
  ST1.Free;
end;
 
 
{ ==============================================================================
  方法名稱:ClearCaseIndex
  引用相依:
  方法描述:重設案件索引相關的 UI 狀態,將信用註記選項設為不可用且取消選取。
============================================================================== }
Procedure TCB_IMGPSScanX.ClearCaseIndex;
begin
  AddCredit1RG.Enabled := False;
  AddCredit1RG.ItemIndex := -1;
end;
 
 
{ ==============================================================================
  方法名稱:GetSelectImageFile
  引用相依:
  方法描述:取得當前所有被選取的影像檔案路徑。遍歷畫面上的 TShape 元件(選取框),透
            過名稱關聯找到對應的影像捲軸盒(ISB),並將其載入的檔名加入到 NowSelect
            FileList 清單中。
============================================================================== }
Procedure TCB_IMGPSScanX.GetSelectImageFile;
var
  i : Integer;
  FormID,FormName,DocNo : String;
  PreNode2Name : String;
  iFormID : String;
  iISBName : String;
  iISB : TImageScrollBox;
begin
  NowSelectFileList.Clear;
  for i := 0 to ComponentCount -1 do
  begin
    if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then
    begin
      iISBName := ShapeName2PreViewISBName(TShape(Components[i]));
      iISB := TImageScrollBox(FindComponent(iISBName));
      NowSelectFileList.Add(iISB.FileName);
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GetDocNoDir
  引用相依:DirectoryExists
  方法描述:根據文件編號產生下一個可用的目錄名稱(用於區分份數)。若文件編號不為空,
            會遞增序號並檢查磁碟目錄是否存在,直到找到未使用的名稱(格式如 DocNo_1
            );若編號為空則回傳附件目錄名稱。
============================================================================== }
Function TCB_IMGPSScanX.GetDocNoDir(Path,DocNo:String):String; //取出目前DocNo的份數
var
  i : Integer;
  iDocNo : String;
begin
  if (DocNo <> '') then
  begin
    i := 0;
    Repeat
    begin
      inc(i);
      iDocNo := Format('%s_%d',[DocNo,i]);
    end;
    until not DirectoryExists(Path+iDocNo);
    Result := iDocNo;
  end
  Else
  begin
    Result := AttName;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CheckFormIDExists
  引用相依:
  方法描述:檢查特定的表單代碼(FormID)是否已經存在於樹狀結構中指定文件的子節點中
            。
============================================================================== }
Function TCB_IMGPSScanX.CheckFormIDExists(DocNoNode:TTreeNode;FormID:String):Boolean; //檢查FormID是否存在文件裡
var
  i : Integer;
begin
  Result := False;
  for i := 0 to DocNoNode.Count - 1 do
  begin
    if FormID = Node3FormID(DocNoNode.Item[i]) then
    begin
      Result := True;
      break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:DocNo2DocNoDir
  引用相依:DirectoryExists
  方法描述:類似 GetDocNoDir,但產生的目錄名稱格式為 DocNo(1)。透過循環檢查目錄是
            否存在,自動產生下一個可用的份數目錄名稱。
============================================================================== }
Function TCB_IMGPSScanX.DocNo2DocNoDir(Path,DocNo:String):String;    //DocNo轉成DocNo(份數)目錄
var
  i : Integer;
  iDocNo : String;
begin
  if (DocNo <> '') then
  begin
    i := 0;
    Repeat
    begin
      inc(i);
      iDocNo := Format('%s(%d)',[DocNo,i]);
    end;
    until not DirectoryExists(Path+iDocNo);
    Result := iDocNo;
  end
  Else
  begin
    Result := AttName;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:DocNoDir2DocNo
  引用相依:
  方法描述:將包含份數括號的目錄名稱(如 A001(2))還原為原始的文件編號(如 A001)。排
            除附件目錄後,尋找左括號的位置並擷取前面的字串。
============================================================================== }
Function TCB_IMGPSScanX.DocNoDir2DocNo(DocNoDir:String):String; //DocNo(份數)目錄轉成DocNo
var
  v,ln : Integer;
begin
  if (DocNoDir <> 'Attach') and (DocNoDir <> 'S_Attach') then
  begin
    v := Pos('(',DocNoDir);
    if v > 0 then
      Result := Copy(DocNoDir,1,v-1)
    else
      Result := DocNoDir;
  end
  Else
    Result := DocNoDir
end;
 
 
{ ==============================================================================
  方法名稱:DocNoDir2Index
  引用相依:LoadFromFile
  方法描述:將文件目錄名稱轉換為其在 CaseDocNo.dat 清單中的索引位置。
============================================================================== }
Function TCB_IMGPSScanX.DocNoDir2Index(Path,DocNoDir:String):Integer; //DocNo(份數)目錄轉成index
var
  i : Integer;
  CaseNo_List : TStringlist;
begin
  Result := -1;
  CaseNo_List := TStringlist.Create;
  try
    CaseNo_List.LoadFromFile(Path+'CaseDocNo.dat');
    for i := 0 to CaseNo_List.Count - 1 do
    begin
      if DocNoDir = CaseNo_List.Strings[i] then
      begin
        Result := i;
        Break;
      end;
    end;
  finally
  CaseNo_List.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ParserPoint
  引用相依:
  方法描述:解析代表影像十字點座標的字串。將包含四個端點(左上、左下、右上、右下)座標
            及長寬資訊的字串拆解,並轉換為 TPoint 結構存入全域變數中,若字串格式不
            符則全部重設為 (0,0)。
============================================================================== }
Procedure TCB_IMGPSScanX.ParserPoint(S:String); //解析十字點的字串
var
  PointList : TStringlist;
  Rect : TRect;
begin
  PointList := TStringlist.Create;
  try
    PointList.Text := S;
    IF PointList.Count <> 6 Then
    begin
      UpLPoint := Str2Point('0,0');
      UpRPoint := Str2Point('0,0');
      DownLPoint := Str2Point('0,0');
      DownRPoint := Str2Point('0,0');
      Point_Width := '0';
      Point_Height := '0';
    end
    Else
    begin
      UpLPoint := Str2Point(PointList[0]);
      DownLPoint := Str2Point(PointList[1]);
      UpRPoint := Str2Point(PointList[2]);
      DownRPoint := Str2Point(PointList[3]);
      Point_Width := PointList[4];
      Point_Height := PointList[5];
    end;
  finally
  PointList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CheckScanDenialTime
  引用相依:
  方法描述:檢查目前時間是否已超過系統設定的「禁止掃瞄時間」。
============================================================================== }
Function TCB_IMGPSScanX.CheckScanDenialTime:Boolean;
Var
  NowTime : String;
begin
  NowTime := GetBalance2Time(Balance);
  NowTime := Copy(NowTime,1,2)+':'+Copy(NowTime,3,2)+':'+Copy(NowTime,5,2);
  Result := True;
  if ScanDenialTime <> '' then
  begin
    if StrtoTime(NowTime) >= StrtoTime(ScanDenialTime) then
      Result := False;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:FormID2Anchor
  引用相依:
  方法描述:根據表單代碼(FormID)從 FORM_INF_List 中查詢對應的定位模式(ANCHOR 模
            式),並回傳轉換後的模式字串(NONE/ANCHOR/FRAME)。
============================================================================== }
Function TCB_IMGPSScanX.FormID2Anchor(FormID:String):String;  //用FormID取出十字模式
var
  Anchor : String;
begin
  Result := 'NONE';
  IF FindSQLData(FORM_INF_List,'T1.ANCHOR','T1.FORM_ID',FormID,0,FindResult) then
  begin
    ANCHOR := UpperCase(GetFindResult('T1.ANCHOR'));
  end;
  Result := Index2Anchor(Anchor);
end;
 
 
{ ==============================================================================
  方法名稱:Index2Anchor
  引用相依:
  方法描述:將數值型的定位模式索引(0, 1, 2)轉換為易讀的模式名稱字串。
============================================================================== }
Function TCB_IMGPSScanX.Index2Anchor(Anchor:String):String;   //十字模式 0->NONE;1->ANCHOR;2->FRAME
begin
  if Anchor = '0' then
    Result := 'NONE'
  else if Anchor = '1' then
    Result := 'ANCHOR'
  else if Anchor = '2' then
    Result := 'FRAME';
end;
 
 
{ ==============================================================================
  方法名稱:ScanDuplexCBClick
  引用相依:
  方法描述:處理雙面掃瞄勾選框點擊事件,同步更新全域的 ScanDuplex 變數。
============================================================================== }
procedure TCB_IMGPSScanX.ScanDuplexCBClick(Sender: TObject);
begin
  ScanDuplex := ScanDuplexCB.Checked;
  //R_W_ScanIni('W');       //user要求改成預設後不能改
end;
 
 
{ ==============================================================================
  方法名稱:ScanGrayCBClick
  引用相依:ifBlackWhite, ifGray256, ifTrueColor
  方法描述:根據掃瞄勾選框狀態,設定掃瞄色彩模式(灰階、全彩或黑白)。
============================================================================== }
procedure TCB_IMGPSScanX.ScanGrayCBClick(Sender: TObject);
begin
 
  if ScanGrayCB.Checked then
  begin
    ScanColor:=ifGray256;
  end
  else
  begin
    if FScanColor = 0 then
    begin
      ScanColor := ifBlackWhite;
    end;
 
    if FScanColor = 1 then
    begin
      //ScanColor := ifGray256 ;
      ScanColor := ifBlackWhite; //
    end;
 
 
    if FScanColor = 2 then
    begin
      ScanColor := ifTrueColor ;
    end;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:GetFormatID
  引用相依:FileExists, LoadFromFile
  方法描述:從案件索引檔(CaseIndex.dat)中獲取案件的 FormatID(主鍵值)。目前實作為
            存根,包含讀取邏輯但未回傳特定欄位。
============================================================================== }
Function TCB_IMGPSScanX.GetFormatID(CaseID: string):String;
Var
  S : TStringlist;
  FormatID : String;
begin
  Result := '';
  S := TStringlist.Create;
  try
    if FileExists(ImageSavePath+CaseID+'\CaseIndex.dat') then
    begin
      S.LoadFromFile(ImageSavePath+CaseID+'\CaseIndex.dat');
      //Format_ID := S.Strings[5];    //主鍵值 (報價單號or續保單號or保單號碼or保險證號or原案件受編)
      //Result := Format_ID;
      //Handle_No := S.Strings[0];    //經辦代號
      //Cen_Uid := S.Strings[1];      //被保人ID
      //Cen_Cliname := S.Strings[2];  //被保人姓名
      //Cen_Platno := S.Strings[3];   //車號
      //Case_Priority := S.Strings[4];//案件等級
    end;
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:MemoInfoTransfer
  引用相依:
  方法描述:註記代碼與類別名稱的轉換函數。支援「代碼轉名稱」或「名稱轉代碼」兩種模式,
            若無匹配代碼則預設為「自行輸入」。
============================================================================== }
Function TCB_IMGPSScanX.MemoInfoTransfer(Mode,Str:String;ID_S,Name_S:TStringlist):String;  //註記代碼註記類別轉換  Mode 'ID':代碼轉名稱;'NAME':名稱轉代碼
var
  i : Integer;
begin
  if Mode = 'ID' then
  begin
    Result := _Msg('自行輸入');
    for i := 0 to ID_S.Count - 1 do
    begin
      if Str = ID_S.Strings[i] then
      begin
        Result := Name_S.Strings[i];
        Break;
      end;
    end;
  end
  else if Mode = 'NAME' then
  begin
    Result := '00';
    for i := 0 to Name_S.Count - 1 do
    begin
      if Str = Name_S.Strings[i] then
      begin
        Result := ID_S.Strings[i];
        Break;
      end;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:SetSQLData
  引用相依:
  方法描述:將 SQL 查詢結果格式化後塞入目標字串清單。此方法會先清除目標清單 (ToLi
            st),第一行加入欄位定義字串 (ColumeStr),隨後將來源清單 (FromList) 中
            扣除標題後的資料列依序填入,用於更新系統本地的資料快取。
============================================================================== }
Procedure TCB_IMGPSScanX.SetSQLData(ColumeStr:String;FromList,ToList:TStringlist); //把SQL值塞入
var
  i : Integer;
begin
  ToList.Clear;
  ToList.Add(ColumeStr);
  For i := 1 to FromList.Count -1 do
  begin
    ToList.Add(FromList.Strings[i]);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GetSQLData
  引用相依:
  方法描述:從結構化字串清單中提取特定欄位的值。邏輯如下:
            1. 解析 TableList 的第一行(欄位定義)以確定目標欄位 (Colname) 的索引
            位置。
            2. 讀取指定行 (colNo) 的資料字串,該字串使用 '!@!' 作為欄位分隔符。
            3. 透過循環將資料拆分並存入臨時清單,最後返回對應欄位索引位置的數值內
            容。若找不到欄位或索引超出範圍,則返回空字串。
============================================================================== }
Function TCB_IMGPSScanX.GetSQLData(TableList:TStringlist;Colname:String;colNo:Integer):String; //依欄位及索引取值
var
  i,col,v,v1 : Integer;
  ColStr,DataStr: TStringList;
  TmpStr : String;
  P1,p2 : Integer;
begin
  Result := '';
  ColStr := TStringList.Create;
  DataStr := TSTringList.Create;
  ColStr.CommaText := TableList.Strings[0];
  TmpStr := TableList.Strings[ColNo];
  //DataStr.Text:=StringReplace(TmpStr,'!@!',#13,[rfReplaceAll]);
 
  While Length(Tmpstr) > 0 do
  begin
    v:= Pos('!@!',TmpStr);
    v1 := Length(TmpStr);
    If v > 0 Then
    begin
      DataStr.Add(Copy(TmpStr,1,v-1));
      TmpStr := Copy(TmpStr,v+3,V1-(V-2));
    end
    Else
    begin
      DataStr.Add(TmpStr);
      TmpStr := '';
    end;
  end;
  For i := 0 to ColStr.Count-1 do
  begin
    IF ColStr.Strings[i] = ColName Then
    begin
      Result := '';
      If (DataStr.Count > 0) and (i<=DataStr.Count-1) Then
        Result := DataStr.Strings[i];
      //If (DataStr.Count > 0) and (i<=DataStr.Count-1) Then
      //begin
        {if i = 0 then
        begin
          P1 := 1;
          p2 := PosN('!@!',TmpStr,1)-1;
        end
        else
        begin
          P1 := PosN('!@!',TmpStr,i)+3;
          p2 := PosN('!@!',TmpStr,i+1)-p1;
        end;
 
 
        Result :=Copy(tmpstr,p1,p2);}
      //end;
        //Result := DataStr.Strings[i];
 
      Break;
    end;
  end;
  ColStr.Free;
  DataStr.Free;
end;
 
 
{ ==============================================================================
  方法名稱:FindSQLData
  引用相依:
  方法描述:在資料快取清單中搜尋符合鍵值的紀錄。核心邏輯:
            1. 支援多個鍵值比對 (KeyColumeStr 與 KeyStr 可包含多個欄位)。
            2. 若 ColNo 為 0,則從頭搜尋清單;若非 0 則僅檢查該指定行。
            3. 搜尋時會調用 GetSQLData 提取欄位值並與目標鍵值比對。
            4. 一旦匹配成功,會將 ColumeStr 中指定的所有欄位名稱及其對應數值(格式
            為「欄位名,數值」)填入 ResultList 中並返回 True。若搜尋無結果則返回 Fal
            se。
============================================================================== }
Function TCB_IMGPSScanX.FindSQLData(TableList:TStringlist;ColumeStr,KeyColumeStr,KeyStr:String;ColNo:Integer;Var ResultList:TStringlist):Boolean; //找指定的資料
Var i,n,Findindex : Integer;
    ColList,KeyColList,KeyList : TStringlist;
    Cols,Keycols,keys :String;
    Find:Boolean;
begin
  ResultList.Clear;
  if (KeyStr = '') or (TableList.Count <= 1) then
  begin
    Result := False;
    Exit;
  end;
 
  ColList := TStringlist.Create;
  KeyColList := TStringlist.Create;
  KeyList := TStringlist.Create;
  try
    ColList.CommaText := ColumeStr;
    KeyColList.CommaText := KeyColumeStr;
    KeyList.CommaText := KeyStr;
    if ColNo = 0 then
    begin
      for i := 1 to TableList.Count -1 do  //找key對不對
      begin
        Findindex := i;
        for n := 0 to KeyColList.Count - 1 do
        begin
          Find := True;
          Keycols := KeyColList.Strings[n];
          keys := KeyList.Strings[n];
          //Showmessage(keys);
          //Showmessage(TableList.Strings[i]);
          if GetSQLData(TableList,Keycols,i) = keys then //對.繼續
          //if Pos('!@!'+keys+'!@!','!@!'+TableList.Strings[i]+'!@!') >0 then  //在資料列前後加!@! 用pos的方式來改善速度  //20130521發現找資料會有問題
            Continue
          Else   //不對.離開
          begin
            Find := False;
            Break;
          end;
        end;
        if Find then Break;  // 找到了離開
      end;
    end
    Else
    begin
      i := ColNo;
      Findindex := i;
      for n := 0 to KeyColList.Count - 1 do
      begin
        Find := True;
        Keycols := KeyColList.Strings[n];
        keys := KeyList.Strings[n];
        //if GetSQLData(TableList,Keycols,i) = keys then //對.繼續
        if Pos('!@!'+keys+'!@!','!@!'+TableList.Strings[i]+'!@!') >0 then  //在資料列前後加!@! 用pos的方式來改善速度
            Continue
        Else   //不對.離開
        begin
          Find := False;
          Break;
        end;
      end;
    end;
    if Find then //有找到key
    begin
      for n := 0 to ColList.Count -1 do
      begin
        Cols := ColList.Strings[n];
        ResultList.Add(Cols+','+GetSQLData(TableList,Cols,Findindex));
      end;
    end;
  finally
  Result := Find;
  ColList.Free;
  KeyColList.Free;
  KeyList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GetFindResult
  引用相依:
  方法描述:從資料查詢結果(FindResult)中,根據指定的欄位名稱(Col)提取對應的值。
============================================================================== }
Function TCB_IMGPSScanX.GetFindResult(Col:String):String;
var
  i,v,v1 : Integer;
  S,RCol,RValue : String;
begin
  Result := '';
  for I := 0 to FindResult.Count - 1 do
  begin
    S := FindResult.Strings[i];
    v := Pos(',',S);
    v1 := length(S);
    RCol := copy(S,1,v-1);
    RValue := Copy(S,v+1,v1-v);
    if Col =RCol then
      Result := RValue;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ClearView
  引用相依:
  方法描述:清空指定的影像顯示區域。將索引從 stkv 到 8 的 TImageScrollBox 檔名重
            設為空,並清空對應的標籤文字,最後釋放預覽資源並將焦點設回 ISB1。
============================================================================== }
procedure TCB_IMGPSScanX.ClearView(stkv:Integer);
var i:integer;
    ISB : TImageScrollBox;
    lb : TLabel;
begin
  For i:= stkv to 8 do
  begin
    ISB := TImageScrollBox(FindComponent('ISB'+intToStr(i)));
    ISB.FileName := '';
    Lb := TLabel(FindComponent('Lb'+intToStr(i)));
    Lb.Caption := '';
  end;
  FreePreViewISB;
  ISB1Click(ISB1);
end;
 
 
{ ==============================================================================
  方法名稱:initParameter
  引用相依:ifBlackWhite, ifGray256, ifTrueColor
  方法描述:初始化掃瞄相關參數。設定檔案大小限制(預設 5MB)、DPI(預設 300)以及掃瞄
            顏色模式(黑白、灰階、全彩),並同步更新 UI 狀態(如 ScanGrayCB)。
============================================================================== }
procedure TCB_IMGPSScanX.initParameter;
begin
 
//  if FCaseNoLength=0 then
//  begin
//
//  end;
 
  if FFileSizeLimit = 0 then
  begin
    FFileSizeLimit := 5*1024;
  end;
 
 
  if FImgDPI=0 then
  begin
    FImgDPI := 300;
    ScanDpi := FImgDPI;
  end
  else
  begin
    //FImgDPI := StrToInt(Value);
    ScanDpi := FImgDPI;
  end;
 
  if FScanColor = 0 then
  begin
    ScanColor := ifBlackWhite;
  end;
 
  if FScanColor = 1 then
  begin
    ScanColor := ifGray256 ;
    ScanGrayCB.Checked:=True;
  end;
 
  if FScanColor = 2 then
  begin
    ScanColor := ifTrueColor ;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:PrtLbClick
  引用相依:LoadFromFile
  方法描述:處理「列印」按鈕點擊。首先產生上傳用的暫存影像結構,接著開啟 TPrintForm 
            供使用者勾選欲列印的文件。確認後呼叫 PrintImg 進行實體列印,並記錄操作
            日誌。
============================================================================== }
procedure TCB_IMGPSScanX.PrtLbClick(Sender: TObject);
var
    Width          : Double;
    Height         : Double;
    i : Integer;
    DocDirList,FileList :TStringlist;
    iDocDir,iDocNo : String;
    PrtDialog : TPrintDialog;
    S : String;
begin
  ShowText := _Msg('列印中,請稍候');
  DataLoading(True,True);
  Case2upload(NowCaseNo);   //產生原影像結構
 
 
  //ontextList.LoadFromFile(ImageSavePath+NowCaseNo+'\Upload\Context.dat');
 
  PrintForm := TPrintForm.create(Self);
  DocDirList := TStringlist.Create;
  FileList := TStringlist.Create;
  try
    FileList.LoadFromFile(ImageSavePath+NowCaseNo+'\Upload\Context.dat');
    DocDirList.LoadFromFile(ImageSavePath+NowCaseNo+'\Upload\DocDir.dat');
 
    InitialLanguage(PrintForm);  //載入多國語言
    PrintForm.CheckListBox1.Items.Clear;
    For i := 0 to FileList.Count - 1 do
    begin
      iDocDir := DocDirList.Strings[i];
      iDocno := DocNoDir2DocNo(iDocDir);
 
      if not DocNoAppear(iDocNo) then Continue;
 
      PrintForm.CheckListBox1.Items.Add(FileList.Strings[i]);
      if CheckFormID_Prt(FileName2FormCode(FileList.Strings[i])) then
        PrintForm.CheckListBox1.Checked[i] := True;
      PrintForm.ListBox1.Items.Add(Add_Zoo(i+1,3))
    end;
    If (PrintForm.ShowModal = mrOK) then
    begin
      S := '';
      for I := 0 to PrintForm.CheckListBox1.Count -1 do
      begin
        if PrintForm.CheckListBox1.Checked[i] then
        begin
          if S = '' then
            S := S+PrintForm.CheckListBox1.Items[i]
          Else
            S := S+#13+PrintForm.CheckListBox1.Items[i];
        end;
      end;
      if S = '' then
      begin
        Showmessage(_msg('尚未選擇欲列印文件'));
        Exit;
      end
      Else
      begin
        PrintImg(S,FUserID,ServerDate,ImageSavePath+NowCaseNo+'\Upload\');
        If not Writelog(NowCaseNo) then
        begin
          //Showmessage('false');
        end;
      end;
    end;
  finally
  DataLoading(False,False);
  PrintForm.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:UseOldCaseLbClick
  引用相依:CopyFile, DirectoryExists, FileExists, LoadFromFile, SaveToFile
  方法描述:處理「使用舊件」功能。開啟 TOldCaseInfoForm 讓使用者選擇舊有案件的文件。
            選定後,將舊件影像複製到新案件目錄下,自動產生新序號檔名,建立關聯記錄(
            UseCase.dat),並同步更新新案件的文件清單與樹狀統計。
============================================================================== }
procedure TCB_IMGPSScanX.UseOldCaseLbClick(Sender: TObject);
var
  i,n : Integer;
  CaseID,Year,BS_No,IS_Old : String;
  OldCaseInfoForm : TOldCaseInfoForm;
  OldCaseInfoList,Caseinfolist,FileList,DocNoList,iFileList,iDocNoList,iDocNo_CopiesList : TStringlist;
  OldDocdir,OldDocNo,OldDocName,NewDocDir,FileName : String;
  OldPath,NewPath,OldFile,NewFile:String;
  Oldcopies:Integer;
begin
  OldCaseInfoForm := TOldCaseInfoForm.Create(Self);
  OldCaseInfoList := TStringlist.Create;
  Caseinfolist := TStringlist.Create;
  FileList := TStringlist.Create;
  DocNoList := TStringlist.Create;
  iDocNo_CopiesList := TStringlist.Create;
  iFileList := TStringlist.Create;
  iDocNoList := TStringlist.Create;
  OldCaseInfoForm.OldDocDirList := TStringlist.Create;
  OldCaseInfoForm.OldDocNameList := TStringlist.Create;
  OldCaseInfoForm.IN_WH_DocNoList := TStringlist.Create;
  OldCaseInfoForm.OldCopiesList := TStringlist.Create;
  try
    InitialLanguage(OldCaseInfoForm); //載入多國語言
    OldCaseInfoForm.Notebook1.ActivePage := 'CaseInfo';
    OldCaseInfoForm.ImageSavePath := ImageSavePath;
    OldCaseInfoForm.CaseID := NowCaseNo;
    OldCaseInfoForm.Furl := Furl;
    OldCaseInfoForm.Fdata := FData;
    OldCaseInfoForm.FVerify := FVerify;
    OldCaseInfoForm.FReWrite := FReWrite;
    OldCaseInfoForm.FOldCaseInfo := FOldCaseInfo;
 
    //OldCaseInfoList  案件編號@#,年度@#,業務別@#,是否舊件@#,文件編號[份數]@#,文件編號[份數] tab 案件編號@#,年度@#,業務別@#,是否舊件@#,文件編號[份數]@#,文件編號[份數]
    OldCaseInfoList.StrictDelimiter := true;
    OldCaseInfoList.Delimiter := #9;
    OldCaseInfoList.DelimitedText := FOldCaseInfo;
    //Showmessage(FOldCaseInfo);
    //Showmessage(OldCaseInfoList.Text);
    OldCaseInfoForm.IN_WH_DocNoList.Assign(IN_WH_DocNoList);
    OldCaseInfoForm.FIs_In_Wh := FIs_In_Wh;
    for i := 0 to OldCaseInfoList.Count - 1 do
    begin
      Caseinfolist:=SplitString('@#,',OldCaseInfoList.Strings[i]);
      //Caseinfolist.Delimiter := '_';
      //Caseinfolist.DelimitedText := OldCaseInfoList.Strings[i];
      CaseID := Caseinfolist.Strings[0];
      Year := Caseinfolist.Strings[1];
      BS_No := Caseinfolist.Strings[2];
      IS_Old := Caseinfolist.Strings[3];
      With OldCaseInfoForm.OldCaseLV.Items.Add do
      begin
        Caption := CaseID;
        SubItems.Add(Year);
        SubItems.Add(BS_No);
        SubItems.Add(IS_Old);
      end;
    end;
 
    if OldCaseInfoForm.ShowModal = MrOk then
    begin
      OldPath := ImageSavePath+NowCaseNo+'\'+OldCaseInfoForm.UseCaseID+'\';
      NewPath := ImageSavePath+NowCaseNo+'\';
 
      iDocNoList.Clear;
      if FileExists(NewPath+'CaseDocNo.dat') then
        iDocNoList.LoadFromFile(NewPath+'CaseDocNo.dat');
      if FileExists(NewPath+'CaseDocNo_Copies.dat') then
        iDocNo_CopiesList.LoadFromFile(NewPath+'CaseDocNo_Copies.dat');
 
      for i := 0 to OldCaseInfoForm.OldDocDirList.Count - 1 do
      begin
        FileList.LoadFromFile(OldPath+'Context.dat');
        DocNoList.LoadFromFile(OldPath+'DocDir.dat');
 
 
        OldDocName := OldCaseInfoForm.OldDocNameList.Strings[i];
        OldDocDir := OldCaseInfoForm.OldDocDirList.Strings[i];
        OldDocNo := DocNoDir2DocNo(OldDocDir);
        if Copy(OldDocNo,1,5)<>'ZZZZZ' then
        begin
          if DocNoNeedDiv(OldDocNo) then
            NewDocDir := DocNo2DocNoDir(NewPath,OldDocNo)
          else
            NewDocDir := OldDocNo;
        end
        Else
        begin
          NewDocDir := GetNewCustomDocNo(NewPath,OldDocName);
        end;
        SetRecordEditedDocDir('A',NowCaseNo,NewDocDir);
        iFileList.Clear;
        if FileExists(NewPath+NewDocDir+'\Context.dat') then
          iFileList.LoadFromFile(NewPath+NewDocDir+'\Context.dat');
 
        if Not DirectoryExists(NewPath+NewDocDir) then
        begin
 
 
          iDocNoList.Add(NewDocDir);
          Oldcopies := GetDocDirCopies(NowCaseNo+'\'+OldCaseInfoForm.UseCaseID,OldDocDir); //舊案的CaseID 放在新案CaseID目錄裡
          if FileExists(ImageSavePath+NowCaseNo+'\'+OldCaseInfoForm.UseCaseID+'\CaseDocNo_Copies.dat') then
            iDocNo_CopiesList.Add(inttostr(Oldcopies))
          else
          begin
            OldCopies := GetDocDircopies_Rec(OldPath,OldCaseInfoForm.UseCaseID,OldDocDir);
            iDocNo_CopiesList.Add(inttostr(Oldcopies));
            //iDocNo_CopiesList.Add('1');
          end;
          MkDir(NewPath+NewDocDir);
        end;
        SetUseCase('A',NewPath,NewDocDir,OldCaseInfoForm.UseCaseID,'');  //NewDocDir 從哪來的
        SetUseCase('A',OldPath,OldDocDir,'',NowCaseNo);      //OldDocDir 去哪了
        StringtoFile('Y',OldPath+'UseCase.dat');  //要上傳
        for n := 0 to DocNoList.Count - 1 do
        begin
          if OldDocDir = DocNoList.Strings[n] then
          begin
            OldFile := FileList.Strings[n];
            if Copy(NewDocDir,1,5)<>'ZZZZZ' then
              NewFile := Add_Zoo(iFileList.Count+1,3)+FileName2NoQuene_Filename(OldFile)
            Else
              NewFile := Add_Zoo(iFileList.Count+1,3)+'_'+GetCustomFormID(NewPath,NewDocDir)+ExtractFileExt(OldFile);
 
            iFileList.Add(NewFile);
            CopyFile(PwideChar(OldPath+OldFile),Pwidechar(NewPath+NewDocDir+'\'+NewFile),False);
           end;
        end;
        iFileList.SaveToFile(NewPath+NewDocDir+'\Context.dat');
      end;
 
      iDocNoList.SaveToFile(NewPath+'CaseDocNo.dat');
      iDocNo_CopiesList.SaveToFile(NewPath+'CaseDocNo_Copies.dat');
      DrawDocItem2(MyTreeNode1,NowCaseNo);
      //MyTreeNode1.Text := Format('%s-%d'+_Msg('頁'),[NowCaseno,GetCasePage(ImageSavePath,NowCaseNo)]);
      MyTreeNode1.Text := Format(_Msg('%s-%d頁'),[NowCaseno,GetCasePage(ImageSavePath,NowCaseNo)]);
      NewTreeNodeRefresh;
      ClearErrini(NowCaseno,MyTreeNode1);  //清掉檢核記錄
    end;
  finally
  OldCaseInfoForm.OldDocDirList.Free;
  OldCaseInfoForm.OldDocNameList.Free;
  OldCaseInfoForm.OldCopiesList.Free;
  OldCaseInfoList.Free;
  Caseinfolist.Free;
  FileList.Free;
  DocNoList.Free;
  iDocNo_CopiesList.Free;
  iFileList.Free;
  iDocNoList.Free;
  OldCaseInfoForm.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:LastInitFormidListCreate
  引用相依:LoadFromFile
  方法描述:從 FormCode_Name.dat 檔案中提取表單代碼(底線前的部分),並將其加入到 L
            astInitFormidList 清單中。
============================================================================== }
procedure TCB_IMGPSScanX.LastInitFormidListCreate(path: string);
var
  i:integer;
  ST1:TStringList;
  str1:string;
begin
//ShowMessage('path='+path);
  ST1:=TStringList.Create;
  ST1.LoadFromFile(path+'FormCode_Name.dat');
  for I := 0 to ST1.Count - 1 do
  begin
    if (Pos('_',St1.Strings[i])<>1) and (Pos('_',St1.Strings[i])<>-1) then
    begin
      str1:=Copy(ST1.Strings[i],1,Pos('_',St1.Strings[i])-1);
      LastInitFormidList.Add(str1);
    end;
  end;
 
  ST1.Free;
end;
 
 
{ ==============================================================================
  方法名稱:LoadFileGetMD5
  引用相依:LoadFileGetMD5, TIdHashMessageDigest5
  方法描述:計算指定檔案的 MD5 雜湊值。方法會以唯讀模式開啟檔案串流 (TFileStream)
            ,利用 TIdHashMessageDigest5 元件處理串流內容,並返回以十六進位字串表
            示的 MD5 值。此功能主要用於確認影像檔案在傳輸或處理前後的完整性與一致
            性,防止資料受損或被重複處理。
============================================================================== }
function TCB_IMGPSScanX.LoadFileGetMD5(const filename: string): string;
var
  Stream: TFileStream;
  //Buffer: array[0..1023] of AnsiChar;
  Buffer: array[0..1023] of AnsiChar;
  TempStr: string;
  i: Integer;
  idmd5:TIdHashMessageDigest5;  //import IdHashMessageDigest, idHash
 
begin
  idmd5 := TIdHashMessageDigest5.Create;
 
  try
    Stream := TFileStream.Create(filename, fmOpenRead);
    Stream.Read(Buffer[0], SizeOf(Buffer));
 
    result := idmd5.HashStreamAsHex(Stream) ;
  finally
    idmd5.Free;
    Stream.Free;
 
  end;
end;
 
 
{ ==============================================================================
  方法名稱:LoadImgFile
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:載入當前所有的影像案件至樹狀結構。清空舊有節點後,讀取 CaseList.dat,為
            每個案件建立父節點,並呼叫 DrawDocItem2 繪製子文件與表單。同時會根據 O
            MR 檢核狀態設定對應的案件圖示。
============================================================================== }
procedure TCB_IMGPSScanX.LoadImgFile;  //載入新件及替換件
Var
  i,v,v1,m : Integer;
  CasePage : integer;
  TempName : String;
  BarName : String;
  DocName : String;
  //S : String;
begin
  ClearView(1);
  PageLV.Clear;
  AttListBox.Items.Clear;
  AddAttFileLB.Enabled := False;
  DelAttFileLB.Enabled := False;
  DisplayPath := '';
  ClearCaseIndex;
  CaseHelpBtn.Visible := False;
  //Del_Sub_NothingPath(ImageSavePath);  //清掉案件目錄是空的
  TreeView1.Items.Clear;
  NewTreeNode := nil;
  MyTreenode1 := nil;
  MyTreenode2 := nil;
  MyTreenode3 := nil;
  NewTreeNode := TreeView1.Items.Add(nil,Format(_Msg('%s-共%d筆共%d頁'),[FModeName,0,0]));
  NewTreenode.ImageIndex := 0;
  NewTreenode.SelectedIndex := 0;
  Del_Sub_NothingPath(ImageSavePath);  //清掉案件目錄是空的
  GetCase_PageCount(CaseCount,PageCount);
  CaseList.Clear;
  if FileExists(ImageSavePath + 'CaseList.dat') then
    CaseList.LoadFromFile(ImageSavePath + 'CaseList.dat');
  for i := 0 to CaseList.Count - 1 do
  begin
    CaseDocNoList.Clear;
    if FileExists(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo.dat') then
      CaseDocNoList.LoadFromFile(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo.dat');
    if not FileExists(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo_Copies.dat') then
    begin
      CaseDocNo_CopiesList.Clear;
      for m := 0 to CaseDocNoList.Count - 1 do
      begin
        CaseDocNo_CopiesList.Add('1');
        CaseDocNo_CopiesList.SaveToFile(ImageSavePath+CaseList.Strings[i]+'\CaseDocNo_Copies.dat');
      end;
    end;
 
    CasePage := GetCasePage(ImageSavePath,CaseList.Strings[i]);
//ShowMessage('CasePage='+IntToStr(CasePage));
    MytreeNode1 := TreeView1.Items.AddChild(NewTreeNode,Format(_Msg('%s-%d頁'),[CaseList.Strings[i],CasePage]));
    MytreeNode1.ImageIndex := 1;
    MytreeNode1.SelectedIndex := 1;
    DrawDocItem2(MytreeNode1,CaseList.Strings[i]); //長出文件名稱的樹並傳回是否有申請書的影像
    if Pos(_Msg('未配號'),CaseList.Strings[i]) > 0 then
    begin
      MytreeNode1.ImageIndex := 5;
      MytreeNode1.SelectedIndex := 5;
    end;
    If FileExists(ImageSavePath+CaseList.Strings[i]+'\OMRCheckOk.dat') Then
    begin
      MytreeNode1.ImageIndex := 7;
      MytreeNode1.SelectedIndex := 7;
      CaseHelpBtn.Visible := False;
    end
    Else IF FileExists(ImageSavePath+CaseList.Strings[i]+'\Checkerr.ini') Then
    begin
      MyTreenode1.ImageIndex := 5;
      MyTreenode1.SelectedIndex := 5;
 
      //AllEnforceLb.Visible := True; //全部強迫送件
    end;
  end;
  MyTreenode1 := nil;
  MyTreenode2 := nil;
  If NewTreeNode <> nil Then
  begin
    TreeView1.Selected := NewTreeNode;
    NewTreeNode.Expand(False);
  end;
  IF (NewTreeNode <> nil) and (NewTreeNode.Count > 0) Then
  begin
    GetCase_PageCount(CaseCount,PageCount);
    v := Pos('-',NewTreeNode.Text);
    NewTreeNode.Text := Format(_Msg('%s-共%d筆共%d頁'),[Copy(NewTreeNode.Text,1,v-1),CaseCount,PageCount]);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:LoadImgFile1
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:載入影像檔案的另一種實作版本。包含更細緻的 Context_DocNo.dat 管理,若
            檔案不存在會自動掃描 ContextList 並根據 FormCode 產生對應的文件編號
            記錄。主要用於特定的資料結構載入。
============================================================================== }
procedure TCB_IMGPSScanX.LoadImgFile1;  //載入新件及替換件
Var
  i,n,v,v1,m : Integer;
  p : integer;
  iCaseNo,iDocNo : String;
  TempName : String;
  BarName : String;
  DocName : String;
  //S : String;
begin
  ClearView(1);
  PageLV.Clear;
  DisplayPath := '';
  ClearCaseIndex;
  CaseHelpBtn.Visible := False;
  //Del_Sub_NothingPath(ImageSavePath);  //清掉案件目錄是空的
  TreeView1.Items.Clear;
  NewTreeNode := nil;
  MyTreenode1 := nil;
  MyTreenode2 := nil;
  MyTreenode3 := nil;
  NewTreeNode := TreeView1.Items.Add(nil,Format(_Msg('%s-共%d筆共%d頁'),[FModeName,0,0]));
  NewTreenode.ImageIndex := 0;
  NewTreenode.SelectedIndex := 0;
 
  Del_Sub_NothingPath(ImageSavePath);  //清掉案件目錄是空的
  GetCase_PageCount(CaseCount,PageCount);
  CaseList.Clear;
  if FileExists(ImageSavePath + 'CaseList.dat') then
    CaseList.LoadFromFile(ImageSavePath + 'CaseList.dat');
  for n := 0 to CaseList.Count - 1 do
  begin
    iCaseNo := CaseList.Strings[n];
    CaseDocNoList.Clear;
    if FileExists(ImageSavePath+CaseList.Strings[n]+'\DocNoList.dat') then
      CaseDocNoList.LoadFromFile(ImageSavePath+CaseList.Strings[n]+'\DocNoList.dat');
 
    for m := 0 to CaseDocNoList.Count - 1 do
    begin
      iDocNo := CaseDocNoList.Strings[i];
      MytreeNode1 := TreeView1.Items.AddChild(NewTreeNode,Format(_Msg('%s-%d頁'),[CaseList.Strings[n],p]));
      MytreeNode1.ImageIndex := 1;
      MytreeNode1.SelectedIndex := 1;
    end;
 
 
    ContextList.Clear;
    Context_DocnoList.Clear;
    If FileExists(ImageSavePath+CaseList.Strings[n]+'\Context.dat') Then
    begin
      ContextList.LoadFromFile(ImageSavePath+CaseList.Strings[n]+'\Context.dat');
      if FileExists(ImageSavePath+CaseList.Strings[n]+'\Context_DocNo.dat') then
        Context_DocnoList.LoadFromFile(ImageSavePath+CaseList.Strings[n]+'\Context_DocNo.dat')
      else
      begin
        for m := 0 to ContextList.Count - 1 do
        begin
          Context_DocnoList.Add(FormCode2DocNo(FileName2FormCode(ContextList.Strings[m])));
        end;
        Context_DocnoList.SaveToFile(ImageSavePath+CaseList.Strings[n]+'\Context_DocNo.dat');
      end;
      Cust_DocNoList.Clear;
      if FileExists(ImageSavePath+CaseList.Strings[n]+'\CustomDocNo.dat') then
        Cust_DocNoList.LoadFromFile(ImageSavePath+CaseList.Strings[n]+'\CustomDocNo.dat');
 
      P := ContextList.Count;
      MytreeNode1 := TreeView1.Items.AddChild(NewTreeNode,Format(_Msg('%s-%d頁'),[CaseList.Strings[n],p]));
      MytreeNode1.ImageIndex := 1;
      MytreeNode1.SelectedIndex := 1;
      //DrawDocItem1(MytreeNode1,Doc_Inf_List,CaseList.Strings[n]); //長出文件名稱的樹並傳回是否有申請書的影像
      DrawDocItem2(MytreeNode1,CaseList.Strings[n]); //長出文件名稱的樹並傳回是否有申請書的影像  20140820改
 
      if Pos(_Msg('未配號'),CaseList.Strings[n]) > 0 then
      begin
        MytreeNode1.ImageIndex := 5;
        MytreeNode1.SelectedIndex := 5;
      end;
      If FileExists(ImageSavePath+CaseList.Strings[n]+'\OMRCheckOk.dat') Then
      begin
        MytreeNode1.ImageIndex := 7;
        MytreeNode1.SelectedIndex := 7;
        CaseHelpBtn.Visible := False;
      end
      Else IF FileExists(ImageSavePath+CaseList.Strings[n]+'\Checkerr.ini') Then
      begin
        MyTreenode1.ImageIndex := 5;
        MyTreenode1.SelectedIndex := 5;
 
        //AllEnforceLb.Visible := True; //全部強迫送件
      end;
    end;
  end;
 
 
  MyTreenode1 := nil;
  MyTreenode2 := nil;
  If NewTreeNode <> nil Then
  begin
    TreeView1.Selected := NewTreeNode;
    NewTreeNode.Expand(False);
  end;
  ContextList.Clear;
  IF (NewTreeNode <> nil) and (NewTreeNode.Count > 0) Then
  begin
    GetCase_PageCount(CaseCount,PageCount);
    v := Pos('-',NewTreeNode.Text);
    NewTreeNode.Text := Format(_Msg('%s-共%d筆共%d頁'),[Copy(NewTreeNode.Text,1,v-1),CaseCount,PageCount]);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:LoadAttFile
  引用相依:FileExists, LoadFromFile
  方法描述:載入指定案件的附件檔案。讀取 AttContext.dat,將附件檔名解碼後加入到 At
            tListBox 列表中。
============================================================================== }
procedure TCB_IMGPSScanX.LoadAttFile(CaseID:String); //載入附加檔案
var
  AttContextList : TStringlist;
  i : Integer;
begin
  AttListBox.Clear;
  AttContextList := TStringlist.Create;
  try
    if FileExists(ImageSavePath+CaseID+'\AttContext.dat') then
    begin
      AttContextList.LoadFromFile(ImageSavePath+CaseID+'\AttContext.dat');
    end;
    for i := 0 to AttContextList.Count - 1 do
    begin
      AttListBox.Items.Add(UTF8Decode(HTTPDEcode(AttContextList.Strings[i])));
    end;
  finally
  AttContextList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:logTimeString
  引用相依:
  方法描述:產生帶有當前日期時間與案件編號的日誌前綴字串。
============================================================================== }
function TCB_IMGPSScanX.logTimeString: String;
begin
Result:=FormatDateTime('yyyymmdd hh:mm:ss',now) +'  caseNo='+NowCaseno+'  ';
end;
 
 
{ ==============================================================================
  方法名稱:FindDivFormCode
  引用相依:
  方法描述:檢查特定的表單代碼是否具有「分案」屬性。從 FORM_INF_List 中查詢該表單的
             DIVISION 欄位,判斷是否包含目前的作業模式(如 NSCAN/ISCAN)。
============================================================================== }
Function TCB_IMGPSScanX.FindDivFormCode(FormCode:String):Boolean; //找有沒有分案的條碼
var
  i : Integer;
  DelBarCode : String;
  S : TStringlist;
  iMode : String;
begin
  Result := False;
  iMode := FMode;
  S := TStringlist.Create;
  try
    IF FindSQLData(FORM_INF_List,'T1.FORM_ID,T1.DIVISION','T1.FORM_ID',FormCode,0,FindResult) then
    begin
      S.CommaText := GetFindResult('T1.DIVISION');
      for i := 0 to S.Count - 1 do   //可能有多組
      begin
        if S.Strings[i] = iMode then
        begin
          Result := True;
          Break;
        end;
      end;
    end;
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CheckAvailable
  引用相依:FileExists, dnFile, dnFile_Get, upFile
  方法描述:檢查元件的使用授權。透過 HTTPS 下載掃瞄授權檔,並驗證 MacID、註冊數量與
            使用期限。若尚未註冊且仍有額度,則自動進行註冊並上傳新的授權檔至伺服器
            。最後在狀態列顯示註冊資訊。
============================================================================== }
Function TCB_IMGPSScanX.CheckAvailable:Boolean; //檢查是否可使用元件
var
  SendData : String;
  Msg:String;
  Nowcount,Totalcount,Lic_Idx : Integer;
  MacID,IPStr,LegalDate :String;
begin
  Result := False;
  /////下載MPSLIC_SCAN.lic //////
  SendData:='data='+HTTPEncode(UTF8Encode(FData))+'&verify='+FVerify+'&work_no=PLN&file=MPSLIC_SCAN.lic';
  if not dnFile_Get(HTTPSClient,Furl,'service/imgpsc/IMGPSC04/sample',SendData,LngPath+'MPSLIC_SCAN.lic',FReWrite,Memo1,False,DownImgStatus) then
  begin
    Showmessage(_Msg('檢查註冊檔案時,網路發生錯誤!!')+_Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason);
    Exit;
  end;
  /////下載MPSLIC_SCAN.lic ///
 
  if CheckLicensebyIP_new(LngPath+'MPSLIC_SCAN.lic',MacID,IPStr,LegalDate,Msg,Nowcount,Totalcount,Lic_Idx) then  //檢查是否己註冊過
  begin
    if (LegalDate <> '') and (ServerDate>LegalDate) and (Lic_Idx>(Totalcount)) then
    begin
      Showmessage(_Msg('已經超過可使用期限及超出授權數請連絡廠商'));
      Result := False;
      //Exit;
    end
    else
      Result := True;
  end
  Else
  begin
    if Msg <> '' then
    begin
      Showmessage(Format(_Msg('註冊檔有問題,請連絡廠商 錯誤原因:%s'),[Msg]));
      Result := false;
      Exit;
    end
    Else
    begin
      if (LegalDate <> '') and (ServerDate>LegalDate) and (NowCount =0 )  then
      begin
        Lic_Idx := 0;
        Showmessage(_Msg('已經超過可使用期限請連絡廠商'));
        Result := False;
        //Exit;
      end
      //else if (LegalDate = '') and (Nowcount >= Totalcount+10) then  //超過註冊數量
      else if ((LegalDate = '') or ((LegalDate <> '') and (ServerDate>LegalDate)) ) and (Nowcount >= Totalcount) then  //超過註冊數量  20150717 yuu說拿掉送的10個
      begin
        Lic_Idx := 0;
        Showmessage(_Msg('已經超過授權數請連絡廠商'));
        Result := False;
      end
      Else  //未超過註冊數量要寫入註冊檔
      begin
        {if Messagedlg(_Msg('您尚未註冊授權是否要進行註冊??'),MtConfirmation,[mbyes,mbcancel],0) = mrcancel then
        begin
          Result := False;
          Exit;
        end;}
        ShowText := _Msg('授權中,請稍候');
        AddLicense(LngPath+'MPSLIC_SCAN.lic',MacID,IPStr,Msg);
        Nowcount := Nowcount + 1;
        DataLoading(True,True);
 
        /////上傳MPSLICSCAN.lic ////
        SendData:='data='+HTTPEncode(UTF8Encode(FData))+'@verify='+FVerify+'@work_no=PLN@file_name=MPSLIC_SCAN.lic';
        if not upFile(HTTPSClient,FUrl,'service/imgpsc/IMGPSC02/sample',SendData,'file',LngPath+'MPSLIC_SCAN.lic',FReWrite,Memo1,False) then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_MSg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason+')');
          DataLoading(False,False);
          Exit;
        end;
        if memo1.Lines.Strings[0] = '1' then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_Msg('錯誤原因:')+memo1.Lines.Strings[1]);
          DataLoading(False,False);
          Exit;
        end
        Else if Pos('<script type="text/javascript" src="scripts/CW00/login.js"></script>',Memo1.Lines.Text) > 0 then
        begin
          Showmessage(_Msg('檢查註冊時,網路發生錯誤!!')+_Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入'));
          DataLoading(False,False);
          Exit;
        end;
        /////上傳MPSLICSCAN.lic /////
        //Sleep(30000);    //第一次註冊睡30秒  先不睡
        Result := True;
      end;
    end;
  end;
  if FileExists(LngPath+'MPSLIC_SCAN.lic') then
    DeleteFile(LngPath+'MPSLIC_SCAN.lic');
  if LegalDate = '' then
    StatusBar1.Panels[4].Text := Format(_Msg('註冊號:%s 剩餘註冊數:%s'),[MacID,inttostr(Totalcount-Nowcount)]);
  if LegalDate <> '' then
    StatusBar1.Panels[4].Text := '*'+Format(_Msg('註冊號:%s 剩餘註冊數:%s'),[MacID+'('+inttostr(Lic_Idx)+')',inttostr(Totalcount-Nowcount)]);
end;
 
 
{ ==============================================================================
  方法名稱:SmoothCBClick
  引用相依:Image_Smooth
  方法描述:處理「影像平滑化」勾選框。若勾選,則對 ISB1 的影像執行平滑化處理並重新繪
            製。
============================================================================== }
procedure TCB_IMGPSScanX.SmoothCBClick(Sender: TObject);
begin
  if SmoothCB.Checked then
  begin
    Image_Smooth(ISB1.Graphic);
    ISB1.Redraw(True);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:Case2Mask
  引用相依:DirectoryExists, FieldMask, FileExists, FindPoint, LoadFromFile, Sav
            eAnnotation, Str2Dir, _DelTree
  方法描述:產生案件的遮罩影像(用於遮蔽敏感個資)。讀取 Context.dat,針對每張影像尋
            找定位點,並依據對應表單的 XML 定義執行區域遮罩,最後存入指定目錄。
============================================================================== }
Function TCB_IMGPSScanX.Case2Mask(SoPath,DePath:String):Boolean;//產生遮罩影像  20170639 發現沒用到
var
  XT : TXMLTool;
  i : Integer;
  S : TStringlist;
  SiteList : TStringlist;
  FormID : String;
  ColEName : String;
  FileName : String;
  nodename : String;
  Site : String;
  Anchor : String;
begin
  Result := False;
  if DirectoryExists(DePath) then
    _DelTree(DePath);
  Str2Dir(DePath);
  DeleteFile(SoPath+'MaskImg.zip');
  SiteList := TStringlist.Create;
  S := TStringlist.Create;
  XT := TXMLTool.Create;
  try
    S.LoadFromFile(SoPath+'Context.dat');
    for I := 0 to S.Count - 1 do
    begin
      SiteList.Clear;
      ImageScrollBox1.LoadFromFile(SoPath+S.Strings[i],1);
 
      FormID := FileName2FormCode(S.Strings[i]);
      Anchor := FormID2Anchor(FormID);
      //ParserPoint(CropMpsV.FindPoint(Anchor));
      FindPoint(ImageScrollBox1.Graphic,UpLPoint,UpRPoint,DownLPoint,Anchor);
      if FileExists(CheckXmlPath+FWork_no+'\'+FormID+'.xml') then  //沒有Xml就不用遮罩
      begin
        XT.LoadFromFile(CheckXmlPath+FWork_no+'\'+FormID+'.xml');
        if XT.SubNodes['/form/settype10/'].First then
        Repeat
          ColEName := XT.SubNodes['/form/settype10/'].NodeName;
          if XT.SubNodes['/form/settype10/'+ColEName+'/'].First then
          Repeat
            nodename := XT.SubNodes['/form/settype10/'+ColEName+'/'].NodeName;
            If nodename <> '@coldesc' then
            begin
              Site := XT.Node['/form/settype10/'+ColEName+'/'+nodename+'/'].Attributes['colxy'];
              SiteList.Add(Site);
              Result := True;  //有設定
            end
            Else
            begin
              //ColCName := XT['/form/settype1/'+ColEName+'/'+nodename+'/'];
            end;
          Until not XT.SubNodes['/form/settype10/'+ColEName+'/'].Next;
        Until not XT.SubNodes['/form/settype10/'].Next ;
        FieldMask(ImageScrollBox1,SiteList.Text,'Mask',UpLPoint);
      end;
      SaveAnnotation(ImageScrollBox1,DePath+S.Strings[i]);
    end;
  finally
  SiteList.Free;
  S.Free;
  XT.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:DelAttFileLBClick
  引用相依:
  方法描述:處理「刪除附件電子檔」點擊。確認使用者選取的檔案後,從磁碟刪除實體檔案並
            呼叫 SetAttContextList 移除清單記錄。完成後重新載入附件清單並提示。
============================================================================== }
procedure TCB_IMGPSScanX.DelAttFileLBClick(Sender: TObject);
var
  AttFile : String;
  SelectCount : Integer;
  i : Integer;
begin
  SelectCount := 0;
  for i := 0 to AttListBox.Items.Count - 1 do
  begin
    if AttListBox.Selected[i] then
      inc(SelectCount);
  end;
  if SelectCount = 0 then
  begin
    Showmessage(_Msg('請選擇要刪除的電子檔'));
    Exit;
  end;
 
  if SelectCount > 0 then
  begin
    if Messagedlg(Format(_Msg('是否刪除這%d筆??'),[SelectCount]),MtConfirmation,[mbyes,mbcancel],0) = mrcancel then Exit;
    for i := 0 to AttListBox.Items.Count - 1 do
    begin
      if AttListBox.Selected[i] then
      begin
        AttFile :=  HTTPEncode(UTF8Encode(AttListBox.Items.Strings[i]));
        DeleteFile(ImageSavePath+NowCaseNo+'\'+AttFile);
        SetAttContextList('D',-1,NowCaseno,AttFile);
      end;
    end;
  end;
  LoadAttFile(NowCaseNo);
  Showmessage(_msg('刪除完成'));
end;
 
 
{ ==============================================================================
  方法名稱:CheckFormID_Prt
  引用相依:
  方法描述:查詢指定表單(FormID)是否被設定為預設列印。透過 FORM_INF_List 檢核 IS_
            PRINT 欄位是否為 'Y'。
============================================================================== }
Function TCB_IMGPSScanX.CheckFormID_Prt(FormID:String):Boolean; //傳入的FormID是否預設列印
begin
  Result := False;
  If FindSQLData(FORM_INF_List,'T1.IS_PRINT','T1.FORM_ID',FormID,0,FindResult) Then
  begin
    if GetFindResult('T1.IS_PRINT') = 'Y' Then
      Result := True;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:PrintImg
  引用相依:TDibGraphic
  方法描述:執行影像列印的核心程序。開啟列印對話框供選擇印表機,隨後遍歷檔案清單,
            逐一載入影像、套用浮水印後發送至印表機。支援多頁列印於同一個任務或分頁
            處理。
============================================================================== }
procedure TCB_IMGPSScanX.PrintImg(FileName, LoginID, Datetime,
  Path: WideString);
var
  PrintMode      : TEnvisionPrintMode;
  GraphicPrinter : TDibGraphicPrinter;
  PrtDialog : TPrintDialog;
  S : TStringlist;
  i,Pages,Page : Integer;
  Prt_String : String;
  Prt_H : Integer;
  procedure PrintWithManualPrintJob(LoginID,DateTime:String;Pages,Page:Integer);
  begin
      If Page = 1 Then
      begin
        { if UsePrintJob is False, Printer.BeginDoc and Printer.EndDoc must be
          called by the user. This allows printing multiple images in the
          same job (or page). }
        GraphicPrinter.UsePrintJob := False;
 
        { if UsePrintJob is False, the print job name that appears in the
          print manager must be specified in using the Title property of the
          Printer object. Otherwise, if UsePrintJob is True, the Title
          property of the TDibGraphicPrinter object is used to specify the
          job name. }
        Printer.Title := _Msg('影像列印');
      end;
 
      IF (Page mod 2) = 1 Then
        Printer.BeginDoc
      Else
        Printer.NewPage;
 
      ImageScrollBox1.DisplayedGraphic.Canvas.Font.Size := 24;
 
      //ImageScrollBox1.DisplayedGraphic.Canvas.TextOut(20,20, _Msg('列印人員:')+LoginID+' '+_Msg('列印分行:')+FUserUnit+' '+_Msg('列印日期:')+DateTime);
 
      GraphicPrinter.Print(ImageScrollBox1.DisplayedGraphic);
 
 
      { this shows how to print text on a page.
      Printer.Canvas.TextOut(10,10, 'Envision Image Library');
      }
      If ((Page mod 2) = 0) or (Page = pages) Then
        Printer.EndDoc;
  end;
 
  procedure PrintWithAutoPrintJob;
  begin
      GraphicPrinter.UsePrintJob := True;
      GraphicPrinter.Title       := _Msg('影像列印');
      GraphicPrinter.Print(ImageScrollBox1.Graphic);
  end;
 
begin
  S := TStringlist.Create;
  GraphicPrinter := TDibGraphicPrinter.Create;
  PrtDialog := TPrintDialog.Create(self);
  //PrtDialog.Copies:=99;
  try
    IF PrtDialog.Execute Then
    begin
      S.Text := FileName;
      Pages := S.Count;
 
      for i := 0 to S.Count -1 do
      begin
        ImageScrollBox1.LoadFromFile(Path+S.Strings[i],1);
        watermark2(Image1.Picture.Bitmap,70,'',ImageScrollBox1.DisplayedGraphic);
        PrintWithManualPrintJob(LoginID,DateTime,Pages,i+1);
      end;
    end;
 
  Finally
  PrtDialog.Free;
  GraphicPrinter.Free;
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:FindLastestDocDir
  引用相依:FileExists, LoadFromFile
  方法描述:針對指定的文件編號,從 CaseDocNo.dat 中反向尋找最新的份數目錄名稱(例
            如 A001(2))。
============================================================================== }
Function TCB_IMGPSScanX.FindLastestDocDir(CaseID,DocNo:String):String; //找出最新的DocDir
var
  i : Integer;
  DocNoList,FileList : TStringlist;
begin
  Result := '';
  DocNoList := TStringlist.Create;
  FileList := TStringlist.Create;
  try
  if FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then
    DocNoList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
  for i := DocNoList.Count-1 downto 0 do
  begin
    if Copy(DocNoList.Strings[i],1,length(DocNo)) = DocNo then
    begin
      Result := DocNoList.Strings[i];
      Break;
    end;
  end;
  finally
  DocNoList.Free;
  FileList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:FindLastestDocDirForPage
  引用相依:FileExists, LoadFromFile
  方法描述:類似 FindLastestDocDir,但額外呼叫 DocNoIsExistImg 確保該目錄下確實存
            在影像檔案,若為空目錄則不視為有效結果。
============================================================================== }
Function TCB_IMGPSScanX.FindLastestDocDirForPage(CaseID,DocNo,formid:String):String; //找出最新的DocDir  20180207  排除隱藏的資料夾
var
  i,j:integer;
  DocNoList,FileList : TStringlist;
  Imglist: TStringlist;
  DirIsHide:Boolean;
begin
  Result := '';
  DocNoList := TStringlist.Create;
  FileList := TStringlist.Create;
  imglist := TStringlist.Create;
  try
  if FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then
    DocNoList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
 
  for i := DocNoList.Count-1 downto 0 do
  begin
    if Copy(DocNoList.Strings[i],1,length(DocNo)) = DocNo then
    begin
//ShowMessage(ImageSavePath+CaseID+'\'+DocNoList.Strings[i]);
      if not DocNoIsExistImg(ImageSavePath+CaseID+'\'+DocNoList.Strings[i]+'\') then
      begin
//ShowMessage('DDDDD');
        Result := '';
        Break;
      end
      else
      begin
        Result := DocNoList.Strings[i];
        Break;
      end;
    end;
  end;
  finally
    DocNoList.Free;
    FileList.Free;
    imglist.Free;
  end;
 
end;
 
 
 
{ ==============================================================================
  方法名稱:SortDocDir_FormID
  引用相依:FileExists, LoadFromFile, RenameFile, SaveToFile
  方法描述:對文件目錄內的影像檔案依表單代碼(FormID)進行重新排序。先提取所有檔案
            的 FormID 並排序,依序產生新檔名進行更名,最後更新 Context.dat 檔案順
            序。
============================================================================== }
Procedure TCB_IMGPSScanX.SortDocDir_FormID(CaseID,DocDir:String); //將DocDir裡的文件編號排序
var
  i,n,v,ln : Integer;
  Exists:Boolean;
  FileList,SortFileList,FormIDList : TStringlist;
  FormID,iFormID:String;
  OldName,NewName : String;
begin
  FileList := TStringlist.Create;
  SortFileList := TStringlist.Create;
  FormIDList := TStringlist.Create;
  try
    if FileExists(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat') then
    begin
      FileList.LoadFromFile(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat');
      ////取出FormID/////
      for i := 0 to FileList.Count - 1 do
      begin
        FormID := FileName2FormCode(FileList.Strings[i]);
        if (FormID = 'Attach') or (FormID = 'S_Attach') then Continue;   //附件離開
        Exists := False;
        for n := 0 to FormIDList.Count - 1 do //查一下FORMID是否已經存在了
        begin
          if FormID = FormIDList.Strings[n] then
          begin
            Exists := True;
            Break;
          end;
        end;
        if not Exists then
          FormIDList.Add(FormID);
      end;
      FormIDList.Sort;
      //排序後產要更名的清單
      for i := 0 to FormIDList.Count - 1 do
      begin
        iFormID := FormIDList.Strings[i];
        for n := 0 to FileList.Count - 1 do
        begin
          if FileName2FormCode(FileList.Strings[n]) = iFormID then
          begin
            SortFileList.Add(FileList.Strings[n]+','+'@'+Add_Zoo(SortFileList.Count+1,3)+'_'+iFormID+ExtractFileExt(FileList.Strings[n]));
          end;
        end;
      end;
      FileList.Clear;
      //更名成新順序的檔名
      for i := 0 to SortFileList.Count - 1 do
      begin
        v := Pos(',',SortFileList.Strings[i]);
        ln := Length(SortFileList.Strings[i]);
        OldName := Copy(SortFileList.Strings[i],1,v-1);
        NewName := Copy(SortFileList.Strings[i],v+1,ln-v);
        RenameFile(ImageSavePath+CaseID+'\'+DocDir+'\'+OldName,ImageSavePath+CaseID+'\'+DocDir+'\'+NewName);
        FileList.Add(NewName);
      end;
      //去掉@開頭
      for i := 0 to FileList.Count - 1 do
      begin
        OldName := FileList.Strings[i];
        NewName := StringReplace(OldName,'@','',[rfReplaceAll]);
        ReNameFile(ImageSavePath+CaseID+'\'+DocDir+'\'+OldName,ImageSavePath+CaseID+'\'+DocDir+'\'+NewName);
        FileList.Strings[i] := NewName;
      end;
      FileList.SaveToFile(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat');
    end;
  finally
  FileList.Free;
  SortFileList.Free;
  FormIDList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GotoAttach
  引用相依:
  方法描述:將樹狀結構的焦點跳轉至案件的附件節點。
============================================================================== }
Procedure TCB_IMGPSScanX.GotoAttach(OldLevel:Integer);
var
  i : Integer;
begin
  for i := 0 to MyTreeNode1.Count - 1 do
  begin
    if Pos('Attach',MyTreeNode1.Item[i].Text) > 0 then
    begin
      if OldLevel = 2 then
      begin
        TreeView1.Selected := MyTreeNode1.Item[i];
      end
      else if OldLevel = 3 then
      begin
        TreeView1.Selected := MyTreeNode1.Item[i].Item[0];
      end;
      Break;
    end;
  end;
  //TreeView1click(nil);
end;
 
 
{ ==============================================================================
  方法名稱:SetDocDirtoSelected
  引用相依:
  方法描述:在樹狀結構中自動選取符合指定目錄名稱的節點。
============================================================================== }
Procedure TCB_IMGPSScanX.SetDocDirtoSelected(CaseNode:TTreeNode;DocDir:String);
var
  i : Integer;
begin
  for i := 0 to CaseNode.Count - 1 do
  begin
    if Pos(DocDir+'{',CaseNode.Item[i].Text) > 0 then
    begin
      TreeView1.Selected := CaseNode.Item[i];
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CheckSelectImg_UseCase
  引用相依:
  方法描述:檢查當前選取的影像所在的文件目錄是否已被其他程序引用(UseKey 標記為 '
            T')。
============================================================================== }
Function TCB_IMGPSScanX.CheckSelectImg_UseCase(Path,CaseID:String):Boolean; //檢查選擇的影像是否有包含被引用的影像
var
  i : Integer;
  iISBName : String;
  iISB : TImageScrollBox;
  ImgPath,DocDir : String;
begin
  Result := False;
  for i := 0 to ComponentCount -1 do
  begin
    if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then
    begin
      //Showmessage(Components[i].Name);
      iISBName := ShapeName2PreViewISBName(TShape(Components[i]));
      iISB := TImageScrollBox(FindComponent(iISBName));
      ImgPath := ExtractFilePath(iISB.FileName);
      DocDir := Path2DocDir(ImgPath,CaseID);
      if GetUseCase('T',Path,DocDir) <> '' then
        Result := True;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ISExistImg
  引用相依:LoadFileGetMD5
  方法描述:透過 MD5 雜湊值比對,檢查指定的影像檔案是否已存在於 ExistImgList 清單
            中。
============================================================================== }
function TCB_IMGPSScanX.ISExistImg(const filename: string): boolean;
begin
  if ExistImgList.IndexOf(LoadFileGetMD5(filename))<>-1 then
  begin
    Result:=True;
  end
  else
  begin
    Result:=False;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:MoveImage
  引用相依:LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:執行影像頁面的位置移動。先對目錄下所有檔案進行臨時更名(加上 @ 標記),
            根據選取狀態重新排列清單順序,最後更新 Context.dat 並重新排序實體檔案
            。
============================================================================== }
Procedure TCB_IMGPSScanX.MoveImage(Path:String;mp:Integer); //移動頁數
var
  i,n,inx:Integer;
  FList,D_Flist:TStringlist;
begin
  FList := TStringlist.Create;
  D_Flist := TStringlist.Create;
  try
    FList.LoadFromFile(Path+'Context.dat');
    //Showmessage(Path);
    //Showmessage(Flist.Text);
    for i := 0 to FList.Count - 1 do
    begin
      Renamefile(Path+Flist.Strings[i],path+'@'+Flist.Strings[i]);
      Flist.Strings[i]:= '@'+Flist.Strings[i];
    end;
 
    for i := 0 to ComponentCount -1 do
    begin
      if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then
      begin
        inx := strtoint(Copy(TShape(Components[i]).Name,3,length(TShape(Components[i]).Name)-2));
        D_Flist.Add(Flist.Strings[inx-1]);
        //Renamefile(Path+Flist.Strings[inx-1],path+'@'+Flist.Strings[inx-1]);
      end;
    end;
    //Showmessage('aa');
    for i := 0 to D_Flist.Count -1 do
    begin
      for n := 0 to FList.Count - 1 do
      begin
        //if Flist.Strings[n]=StringReplace(D_Flist.Strings[i],'@','',[rfReplaceAll]) then
        if Flist.Strings[n]=D_Flist.Strings[i] then
        begin
          Flist.Delete(n);
          Break;
        end;
      end;
    end;
    //Showmessage('bb');
    for i := 0 to D_Flist.Count - 1 do
    begin
      Flist.Insert(mp-1+i,D_Flist.Strings[i]);
    end;
 
    Flist.SaveToFile(Path+'Context.dat');
    //Showmessage(Flist.Text);
    //Showmessage('CC');
    ReSortFileName(Path);
    TreeView1click(self);
 
 
  finally
  FList.Free;
  D_Flist.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:MoveImage_Drag
  引用相依:LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:處理影像拖拉移動。邏輯與 MoveImage 相似,但針對單一來源索引移動至目標
            索引的情境進行排列。
============================================================================== }
Procedure TCB_IMGPSScanX.MoveImage_Drag(Path:String;fp,tp:Integer); //拖拉移動頁數
var
  i,n,inx:Integer;
  FList,D_Flist:TStringlist;
begin
  FList := TStringlist.Create;
  D_Flist := TStringlist.Create;
  try
    FList.LoadFromFile(Path+'Context.dat');
    for i := 0 to FList.Count - 1 do
    begin
      Renamefile(Path+Flist.Strings[i],path+'@'+Flist.Strings[i]);
      Flist.Strings[i]:= '@'+Flist.Strings[i];
    end;
 
    D_Flist.Add(Flist.Strings[fp-1]);
 
    {for i := 0 to ComponentCount -1 do
    begin
      if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then
      begin
        inx := strtoint(Copy(TShape(Components[i]).Name,3,length(TShape(Components[i]).Name)-2));
        D_Flist.Add(Flist.Strings[inx-1]);
        //Renamefile(Path+Flist.Strings[inx-1],path+'@'+Flist.Strings[inx-1]);
      end;
    end;}
    //Showmessage('aa');
    for i := 0 to D_Flist.Count -1 do
    begin
      for n := 0 to FList.Count - 1 do
      begin
        //if Flist.Strings[n]=StringReplace(D_Flist.Strings[i],'@','',[rfReplaceAll]) then
        if Flist.Strings[n]=D_Flist.Strings[i] then
        begin
          Flist.Delete(n);
          Break;
        end;
      end;
    end;
    //Showmessage('bb');
    for i := 0 to D_Flist.Count - 1 do
    begin
      Flist.Insert(tp-1+i,D_Flist.Strings[i]);
    end;
 
    Flist.SaveToFile(Path+'Context.dat');
    //Showmessage(Flist.Text);
    //Showmessage('CC');
    ReSortFileName(Path);
    TreeView1click(self);
 
 
  finally
  FList.Free;
  D_Flist.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:PriorPage
  引用相依:
  方法描述:跳轉至上一頁影像。根據當前頁碼尋找前一個影像捲軸盒組件(ISB),若存在則
            觸發其點擊事件。
============================================================================== }
Procedure TCB_IMGPSScanX.PriorPage(Page:Integer); //上一頁
var
  iISB : TImageScrollBox;
begin
  iISB := TImageScrollBox(FindComponent(ISBName+inttostr(Page-1)));
  if iISB <> nil then
  begin
    ISBClick(iISB);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:NextPage
  引用相依:
  方法描述:跳轉至下一頁影像。根據當前頁碼尋找下一個影像捲軸盒組件(ISB),若存在則
            觸發其點擊事件。
============================================================================== }
Procedure TCB_IMGPSScanX.NextPage(Page:Integer); //下一頁
var
  iISB : TImageScrollBox;
begin
  iISB := TImageScrollBox(FindComponent(ISBName+inttostr(Page+1)));
  if iISB <> nil then
  begin
    ISBClick(iISB);
  end;
end;
 
 
{ ==============================================================================
  方法名稱:view_image_FormCode
  引用相依:LoadFromFile
  方法描述:根據表單代碼(FormCode)顯示對應的影像。支援顯示全部影像(ShowAll)或指定
            表單的影像。若是顯示全部,會重置視窗並建立縮圖;若指定特定表單,則遍歷 C
            ontextList 尋找匹配的檔案,載入至影像捲軸盒(ISB),並設定縮放模式(zmFit
            toPage 或指定百分比)與捲軸位置,最後更新頁碼標籤資訊。
============================================================================== }
procedure TCB_IMGPSScanX.view_image_FormCode(Path,FormCode:String;stpage,stview:integer); //用FormCode來找影像
var i,p:integer;
    ISB : TImageScrollBox;
    lb : TLabel;
    v ,v1 : Integer;
    page : Integer;
    List_FormCode,Err_FormCode: String;
    iFormID : String;
begin
   ShowText := _Msg('影像顯示中,請稍候');
   DataLoading(True,True);
 
   IF FormCode = 'ShowAll' then  //顯示所有的影像 (因為附件會傳空字串,所以用ShowAll)
   begin
     ClearView(1);
     CreatePreViewISB(ContextList.Count);
     For i := Stpage-1 to ContextList.Count -1 do
     begin
       ISB := TImageScrollBox(FindComponent(ISBName+intToStr(stview+i)));
       ISB.AntiAliased := True;
       if ISB.ZoomPercent > 100  then
         ISB.AntiAliased := False;
       ISB.LoadFromFile(Path+ContextList.Strings[i],1);
 
       {GetScrollData(ISB,HS,VS,iRate);
       if iRate = 0 then
         ISB.ZoomMode := zmFittoPage
       Else
         ISB.ZoomPercent := iRate;
       ISB.HorzScrollBar.Position := HS;
       ISB.VertScrollBar.Position := VS;
 
       List_FormCode := FileName2FormCode(ContextList.Strings[i]);
       lb := TLabel(FindComponent('lb'+intToStr(stview)));
       lb.Caption := Format(_Msg('第%s頁'),[Add_Zoo(i+1,3)]);
       If List_FormCode = '' Then
         lb.Caption := lb.Caption+'('+FormCode2FormName(List_FormCode)+')'
       Else
         lb.Caption := lb.Caption+'('+FormCode2FormName(List_FormCode)+'-'+List_FormCode+')';
       Inc(Stview);
       If ((VMode = 0) and (Stview>1))
            or ((VMode = 1) and ((Stview>2)))
            or ((VMode = 2) and ((Stview>4)))
            or ((VMode = 3) and ((Stview>6)))
            or ((VMode = 4) and ((Stview>8))) Then
              break;
       }
     end;
     FitPreViewISB;
   end
   Else  //顯示指定FormCode的影像
   begin
     If (TreeView1.Selected <> nil) Then
     begin
       If Stpage = 0 Then
         Stpage := 1;
       Page := 0;
       ClearView(stview);
       If Stpage > ContextList.Count Then Exit;
       For i := 0 to ContextList.Count -1 do
       begin
         List_FormCode := FileName2FormCode(ContextList.Strings[i]);
         {iFormID := GetMainFormID(List_FormCode);
         if iFormID <> '' then
           List_FormCode := iFormID;}
 
         Err_FormCode := 'NoCode';
         if (List_Formcode <> '') and (not FormIDExists(List_Formcode,False,0)) then
           Err_FormCode := 'Err';
         IF (List_FormCode = FormCode) or (Err_FormCode=Formcode) or (FormCode2DocNo(List_FormCode) = FormCode) Then
         begin
           Inc(Page);
           IF Page< Stpage Then
             Continue;
           ISB := TImageScrollBox(FindComponent('ISB'+intToStr(stview)));
           ISB.AntiAliased := True;
           if ISB.ZoomPercent > 100  then
             ISB.AntiAliased := False;
           ISB.LoadFromFile(Path+ContextList.Strings[i],1);
 
           GetScrollData(ISB,HS,VS,iRate);
           if iRate = 0 then
             ISB.ZoomMode := zmFittoPage
           Else
             ISB.ZoomPercent := iRate;
           ISB.HorzScrollBar.Position := HS;
           ISB.VertScrollBar.Position := VS;
           {if not SortMode then
           begin
             SetScrollData(MPSViewX,MPSViewX.HorzScrollBarPos,MPSViewX.VertScrollBarPos,MPSViewX.ZoomPercent);
           end;}
           //MPSViewX.ImageZoomMode := zmFullpage;
           //MPSViewX.AntiAliased := True;
           lb := TLabel(FindComponent('lb'+intToStr(stview)));
           lb.Caption := Format(_Msg('第%s頁'),[Add_Zoo(i+1,3)]);
           If List_FormCode = '' Then
             lb.Caption := lb.Caption+'('+FormCode2FormName(NowCaseno,List_FormCode)+')'
           Else
             lb.Caption := lb.Caption+'('+FormCode2FormName(NowCaseNo,List_FormCode)+'-'+List_FormCode+')';
           Inc(Stview);
         end;
         If ((VMode = 0) and (Stview>1))
            or ((VMode = 1) and ((Stview>2)))
            or ((VMode = 2) and ((Stview>4)))
            or ((VMode = 3) and ((Stview>6)))
            or ((VMode = 4) and ((Stview>8))) Then
              break;
       end;
     end;
   end;
   ISB1Click(ISB1);
 
 
   DataLoading(False,False);
end;
 
 
{ ==============================================================================
  方法名稱:view_image_DocNo
  引用相依:DirectoryExists, DpiResize, FileExists, LoadFromFile
  方法描述:根據文件代號(DocNo)或表單代號(FormID)顯示影像。函式包含三種模式:顯示
            案件內所有影像(ShowAll)、顯示指定文件夾(如 Attach)下的影像,以及顯示指
            定文件代號下特定表單的影像。處理過程中會檢查在席狀態(In_WH)、執行影像 
            DPI 調整、建立縮圖預覽視窗,並逐一載入檔案至對應的 ISB 元件中,最後自動
            點擊首張影像以進行預覽。
============================================================================== }
procedure TCB_IMGPSScanX.view_image_DocNo(Path,DocNo,FormID:String;Pages:integer); //用DocNo來找影像
var i,n,p:integer;
    ISB : TImageScrollBox;
    lb : TLabel;
    v ,v1 : Integer;
    List_DocNo,Trans_DocNo,List_FormCode,Form_Page: String;
    iDocNo : String;
    iGroupNo,page,Ct,int1 : Integer;
    ST1:TStringList;
begin
   ShowText := _Msg('影像顯示中,請稍候');
   DataLoading(True,True);
ST1:=TStringList.Create;
//Display1.Lines.Clear;
   IF DocNo = 'ShowAll' then  //顯示所有的影像 (因為附件會傳空字串,所以用ShowAll)
   begin
     ClearView(1);
     if GetCasePage(ImageSavePath,NowCaseno) > 30 then
     begin
       DataLoading(False,False);
       Exit;
     end;
     CreatePreViewISB(GetCasePage(ImageSavePath,NowCaseno));
//Showmessage(inttostr(GetCasePage(ImageSavePath,NowCaseno)));
     Ct := 0;
     For i := 0 to CaseDocNoList.Count-1 do
     begin
 
       if (FWH_category='N') and (FIs_In_Wh='Y') then
       begin
         if FileExists(ImageSavePath+NowCaseno+'\EditedDocDir.dat') then
         begin
           ST1.LoadFromFile(ImageSavePath+NowCaseno+'\EditedDocDir.dat');
         end;
       end;
 
       iDocNo := CaseDocNoList.Strings[i];
//ShowMessage('ST1.Count='+IntToStr(ST1.Count));
       if ST1.Count<>0 then
       begin
         if ST1.IndexOf(iDocNo)<>-1 then
         begin
         end
         else
         begin
           if not DocNoAppear(DocNoDir2DocNo(iDocNo)) then continue;  //20170817 這不能被註解
         end;
       end
       else
       begin
         if not DocNoAppear(DocNoDir2DocNo(iDocNo)) then continue;  //20170817 這不能被註解
       end;
       ContextList.Clear;
       if FileExists(Path+iDocNo+'\Context.dat') then
         ContextList.LoadFromFile(Path+iDocNo+'\Context.dat');
//ShowMessage('ContextList='+ContextList.Text);
       for n := 0 to ContextList.Count - 1 do
       begin
 
         if (FWH_category='N') and (FIs_In_Wh='Y') then
         begin
           if ISExistImg(Path+iDocNo+'\'+ContextList.Strings[n]) then
           begin
 
             if not DocNoIs_In_WH(Copy(iDocNo,1,8)) then
             begin
               Continue;
             end;
           end;
         end;
 
         inc(Ct);
         ISB := TImageScrollBox(FindComponent(ISBName+intToStr(Ct)));
         ISB.AntiAliased := True;
         if ISB.ZoomPercent > 100  then
           ISB.AntiAliased := False;
         ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[n],1);
 
         DpiResize(ISB.Graphic,36,False);
         ISB.Redraw(true);
 
       end;
 
     end;
     //if DirectoryExists(Path+'Attach') then
     if DirectoryExists(Path+AttName) then
     begin
       //iDocNo := 'Attach';
       iDocNo := AttName;
       ContextList.Clear;
       if FileExists(Path+iDocNo+'\Context.dat') then
         ContextList.LoadFromFile(Path+iDocNo+'\Context.dat');
       for n := 0 to ContextList.Count - 1 do
       begin
         inc(Ct);
         ISB := TImageScrollBox(FindComponent(ISBName+intToStr(Ct)));
         ISB.AntiAliased := True;
         if ISB.ZoomPercent > 100  then
           ISB.AntiAliased := False;
         ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[n],1);
       end;
     end;
 
     FitPreViewISB;
 
   end
   Else if (DocNo <> '') and (FormID = '') then  //顯示指定DocNo+組別的影像  附件傳 Attach
   begin                               //顯示 文件層下的影像
     iDocNo := DocNo;
     ContextList.Clear;
     if FileExists(Path+iDocNo+'\Context.dat') then
       ContextList.LoadFromFile(Path+iDocNo+'\Context.dat');
 
//ShowMessage('ContextList.Count='+IntToStr(ContextList.Count));
     CreatePreViewISB(ContextList.Count);
//ShowMessage(IntToStr(ContextList.Count));
     int1:=0;
//ShowMessage(BoolToStr(DocNoIs_In_WH(Copy(iDocNo,1,8)),true));
     For i := 0 to ContextList.Count -1 do
     begin
       if (FWH_category='N') and (FIs_In_Wh='Y')  then
       begin
         if ISExistImg(Path+iDocNo+'\'+ContextList.Strings[i]) then
         begin
 
           if not DocNoIs_In_WH(Copy(iDocNo,1,8)) and ( iDocNo<>'Attach') then
           begin
             inc(int1);
             Continue;
           end;
         end;
       end;
//ShowMessage(Path+iDocNo+'\'+ContextList.Strings[i]);
       ISB := TImageScrollBox(FindComponent(ISBName+intToStr(i+1-int1)));
       ISB.AntiAliased := True;
       if ISB.ZoomPercent > 100  then
         ISB.AntiAliased := False;
       ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[i],1);
       DpiResize(ISB.Graphic,36,False);
       ISB.Redraw(true);
     end;
     FitPreViewISB;
   end
   Else if (FormID <> '') {and (FormID <> 'Attach')} then  //顯示指定FormID的影像
   begin
     If (TreeView1.Selected <> nil) Then
     begin
       iDocNo := DocNo;
       ContextList.Clear;
       if FileExists(Path+iDocNo+'\Context.dat') then
         ContextList.LoadFromFile(Path+iDocNo+'\Context.dat');
       iGroupNo := 0;
       page := 0;
       Ct := 0;
       CreatePreViewISB(Pages);
//ShowMessage('formID page'+IntToStr(Pages)+', ContextList='+ContextList.Text);
       For i := 0 to ContextList.Count -1 do
       begin
         if FileName2FormCode(ContextList.Strings[i]) = FormID then
         begin
           if (FWH_category='N') and (FIs_In_Wh='Y') then
           begin
//ShowMessage(Path+iDocNo+'\'+ContextList.Strings[i]);
//ShowMessage(BoolToStr(ISExistImg(Path+iDocNo+'\'+ContextList.Strings[i]),true));
             if ISExistImg(Path+iDocNo+'\'+ContextList.Strings[i]) then
             begin
               if not DocNoIs_In_WH(FormCode2DocNo(FormID)) then
                 Continue;
             end;
           end;
           inc(Ct);
           ISB := TImageScrollBox(FindComponent(ISBName+intToStr(Ct)));
//ShowMessage(ISB.Name);
           ISB.AntiAliased := True;
           if ISB.ZoomPercent > 100  then
             ISB.AntiAliased := False;
           ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[i],1);
           DpiResize(ISB.Graphic,36,False);
           ISB.Redraw(true);
 
           //NowShowFileList.Add(ContextList.Strings[i]);
         end;
       end;
       FitPreViewISB;
     end;
   end;
   
   if FindComponent(ISBName+'1') <> nil then
   begin
     ISBClick(TImageScrollBox(FindComponent(ISBName+'1')));
   end;
   ISB1Click(ISB1);
   DataLoading(False,False);
end;
 
 
{ ==============================================================================
  方法名稱:CB1Click
  引用相依:
  方法描述:處理核取方塊點擊,設定是否要在掃描時顯示 TWAIN 使用者介面(TwainShowUI
            )。
============================================================================== }
procedure TCB_IMGPSScanX.CB1Click(Sender: TObject);
begin
  TwainShowUI := CB1.Checked;
end;
 
 
{ ==============================================================================
  方法名稱:ViewModeBtnMouseEnter
  引用相依:
  方法描述:當滑鼠進入檢視模式按鈕時,顯示該按鈕的 Hint 文字作為工具提示(Tooltip)
            。
============================================================================== }
procedure TCB_IMGPSScanX.ViewModeBtnMouseEnter(Sender: TObject);
begin
  AddToolTip(TBitBtn(Sender).Parent.Handle,nil,0,Pchar(TBitBtn(Sender).Hint),nil,0,0);
end;
 
 
{ ==============================================================================
  方法名稱:Set_caseid
  引用相依:
  方法描述:設定內部變數 FCaseID 的值。
============================================================================== }
procedure TCB_IMGPSScanX.Set_caseid(const Value: WideString);
begin
  FCaseID := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_data
  引用相依:
  方法描述:設定內部變數 FData 的值。
============================================================================== }
procedure TCB_IMGPSScanX.Set_data(const Value: WideString);
begin
  FData := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_mode
  引用相依:
  方法描述:設定作業模式(FMode),並將傳入的字串轉換為大寫。
============================================================================== }
procedure TCB_IMGPSScanX.Set_mode(const Value: WideString);
begin
  FMode := UpperCase(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_rewrite
  引用相依:
  方法描述:設定是否強制覆蓋檔案的標記(FReWrite)。
============================================================================== }
procedure TCB_IMGPSScanX.Set_rewrite(const Value: WideString);
begin
  FReWrite := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_url
  引用相依:
  方法描述:設定後端伺服器的基礎 URL 路徑。
============================================================================== }
procedure TCB_IMGPSScanX.Set_url(const Value: WideString);
begin
  FUrl := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_userid
  引用相依:
  方法描述:設定當前登入的使用者代號。
============================================================================== }
procedure TCB_IMGPSScanX.Set_userid(const Value: WideString);
begin
  FUserID := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_username
  引用相依:
  方法描述:設定當前登入的使用者名稱。
============================================================================== }
procedure TCB_IMGPSScanX.Set_username(const Value: WideString);
begin
  FUserName := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_verify
  引用相依:
  方法描述:設定 API 呼叫所需的驗證字串。
============================================================================== }
procedure TCB_IMGPSScanX.Set_verify(const Value: WideString);
begin
  FVerify := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_language
  引用相依:FileExists
  方法描述:設定語系代碼並執行初始化。會自動修正語系格式(如 zh-tw 轉 zh_tw),若語
            言檔存在則觸發介面語系切換。
============================================================================== }
procedure TCB_IMGPSScanX.Set_language(const Value: WideString);
begin
  FLanguage := lowercase(Value);
  if FLanguage='zh-tw' then
  begin
    FLanguage:='zh_tw'
  end;
  if FileExists(LngPath+'Language.lng') then
  begin
    InitialLanguage(Self);  //載入多國語言
  end;
end;
 
 
{ ==============================================================================
  方法名稱:Set_modename
  引用相依:
  方法描述:設定作業模式的顯示名稱。
============================================================================== }
procedure TCB_IMGPSScanX.Set_modename(const Value: WideString);
begin
  FModeName := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_userunit
  引用相依:
  方法描述:設定使用者所屬的單位代碼。
============================================================================== }
procedure TCB_IMGPSScanX.Set_userunit(const Value: WideString);
begin
  FUserUnit := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_work_no
  引用相依:
  方法描述:設定當前的業務別(WORK_NO)。
============================================================================== }
procedure TCB_IMGPSScanX.Set_work_no(const Value: WideString);
begin
  FWork_no := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_loandoc_enable
  引用相依:
  方法描述:設定信用註記功能是否啟用。根據參數(Y/I)動態切換 AddCredit1RG 元件的可
            用性與可見度。
============================================================================== }
procedure TCB_IMGPSScanX.Set_loandoc_enable(const Value: WideString);
begin
  FLoanDoc_Enable := Value;
  if FLoanDoc_Enable = 'Y' then
    AddCredit1RG.Enabled := True;
  if FLoanDoc_Enable = 'I' then
  begin
    AddCredit1RG.Visible := False;
    Panel5.Visible := False;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:Set_loandoc_value
  引用相依:
  方法描述:設定信用註記的具體數值。
============================================================================== }
procedure TCB_IMGPSScanX.Set_loandoc_value(const Value: WideString);
begin
  FLoanDoc_Value := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_useproxy
  引用相依:
  方法描述:設定系統是否使用 Proxy 代理伺服器進行網路連線。
============================================================================== }
procedure TCB_IMGPSScanX.Set_useproxy(const Value: WideString);
begin
  FUseProxy := UpperCase(Value);
  if FUseProxy = 'Y' then
    UseProxy := True;  //要不要用Proxy
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_c_docnamelist
  引用相依:
  方法描述:設定預設的文件名稱清單。
============================================================================== }
procedure TCB_IMGPSScanX.Set_c_docnamelist(const Value: WideString);
begin
  FC_DocNameList := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_c_docnolist
  引用相依:
  方法描述:設定預設的文件代號清單。
============================================================================== }
procedure TCB_IMGPSScanX.Set_c_docnolist(const Value: WideString);
begin
  FC_DocNoList := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_fixfilelist
  引用相依:
  方法描述:設定固定的檔案清單字串。
============================================================================== }
procedure TCB_IMGPSScanX.Set_fixfilelist(const Value: WideString);
begin
  FFixFileList := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_is_in_wh
  引用相依:
  方法描述:設定是否為在席(In-Warehouse)作業模式。
============================================================================== }
procedure TCB_IMGPSScanX.Set_is_in_wh(const Value: WideString);
begin
  FIs_In_Wh := UpperCase(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Set_oldcaseinfo
  引用相依:
  方法描述:設定舊案件的相關資訊字串。
============================================================================== }
procedure TCB_IMGPSScanX.Set_oldcaseinfo(const Value: WideString);
begin
  FOldCaseInfo := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Get_c_docnamelist
  引用相依:
  方法描述:獲取預設文件名稱清單的存根函式,目前未實作回傳內容。
============================================================================== }
function TCB_IMGPSScanX.Get_c_docnamelist: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_c_docnolist
  引用相依:
  方法描述:獲取預設文件代號清單的存根函式,目前未實作回傳內容。
============================================================================== }
function TCB_IMGPSScanX.Get_c_docnolist: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_caseid
  引用相依:
  方法描述:獲取內部案件編號(FCaseID)。
============================================================================== }
function TCB_IMGPSScanX.Get_caseid: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_data
  引用相依:
  方法描述:獲取內部資料字串(FData)。
============================================================================== }
function TCB_IMGPSScanX.Get_data: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_fixfilelist
  引用相依:
  方法描述:獲取固定的檔案清單字串(FFixFileList)。
============================================================================== }
function TCB_IMGPSScanX.Get_fixfilelist: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_is_in_wh
  引用相依:
  方法描述:獲取是否為在席作業模式的標記(FIs_In_WH)。
============================================================================== }
function TCB_IMGPSScanX.Get_is_in_wh: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_language
  引用相依:
  方法描述:獲取當前設定的語系代碼(FLanguage)。
============================================================================== }
function TCB_IMGPSScanX.Get_language: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_loandoc_enable
  引用相依:
  方法描述:獲取信用註記功能是否啟用的狀態。
============================================================================== }
function TCB_IMGPSScanX.Get_loandoc_enable: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_loandoc_value
  引用相依:
  方法描述:獲取當前設定的信用註記數值。
============================================================================== }
function TCB_IMGPSScanX.Get_loandoc_value: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_mode
  引用相依:
  方法描述:獲取當前作業模式(FMode)。
============================================================================== }
function TCB_IMGPSScanX.Get_mode: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_modename
  引用相依:
  方法描述:獲取作業模式的顯示名稱(FModeName)。
============================================================================== }
function TCB_IMGPSScanX.Get_modename: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_oldcaseinfo
  引用相依:
  方法描述:獲取舊案件的相關資訊字串(FOldCaseInfo)。
============================================================================== }
function TCB_IMGPSScanX.Get_oldcaseinfo: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_rewrite
  引用相依:
  方法描述:獲取是否強制覆蓋檔案的標記(FReWrite)。
============================================================================== }
function TCB_IMGPSScanX.Get_rewrite: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_url
  引用相依:
  方法描述:獲取後端伺服器的基礎 URL(FUrl)。
============================================================================== }
function TCB_IMGPSScanX.Get_url: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_useproxy
  引用相依:
  方法描述:獲取是否使用 Proxy 代理伺服器的設定。
============================================================================== }
function TCB_IMGPSScanX.Get_useproxy: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_userid
  引用相依:
  方法描述:獲取當前登入的使用者代號(FUserID)。
============================================================================== }
function TCB_IMGPSScanX.Get_userid: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_username
  引用相依:
  方法描述:獲取當前登入的使用者名稱(FUserName)。
============================================================================== }
function TCB_IMGPSScanX.Get_username: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_userunit
  引用相依:
  方法描述:獲取使用者所屬的單位代碼(FUserUnit)。
============================================================================== }
function TCB_IMGPSScanX.Get_userunit: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_verify
  引用相依:
  方法描述:獲取 API 驗證字串(FVerify)。
============================================================================== }
function TCB_IMGPSScanX.Get_verify: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_work_no
  引用相依:
  方法描述:獲取當前的業務別代碼(FWork_No)。
============================================================================== }
function TCB_IMGPSScanX.Get_work_no: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_printyn
  引用相依:
  方法描述:獲取是否預設列印的標記(FPrintyn)。
============================================================================== }
function TCB_IMGPSScanX.Get_printyn: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_printyn
  引用相依:
  方法描述:設定是否預設列印的標記,並將傳入值轉換為大寫。
============================================================================== }
procedure TCB_IMGPSScanX.Set_printyn(const Value: WideString);
begin
  FPrintyn := UpperCase(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Get_is_oldcase
  引用相依:
  方法描述:獲取是否為舊件處理模式的標記(FIs_OldCase)。
============================================================================== }
function TCB_IMGPSScanX.Get_is_oldcase: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_is_oldcase
  引用相依:
  方法描述:設定是否為舊件處理模式,並將傳入值轉換為大寫。
============================================================================== }
procedure TCB_IMGPSScanX.Set_is_oldcase(const Value: WideString);
begin
  FIs_OldCase := UpperCase(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Get_custdocyn
  引用相依:
  方法描述:獲取是否支援自定義文件的標記(FCustDocYN)。
============================================================================== }
function TCB_IMGPSScanX.Get_custdocyn: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_custdocyn
  引用相依:
  方法描述:設定是否支援自定義文件,並將傳入值轉換為大寫。
============================================================================== }
procedure TCB_IMGPSScanX.Set_custdocyn(const Value: WideString);
begin
  FCustDocYN := UpperCase(Value);
end;
 
 
{ ==============================================================================
  方法名稱:Get_casenolength
  引用相依:
  方法描述:獲取案件編號的長度限制。
============================================================================== }
function TCB_IMGPSScanX.Get_casenolength: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_filesizelimit
  引用相依:
  方法描述:獲取單一影像檔案的大小限制(KB)。
============================================================================== }
function TCB_IMGPSScanX.Get_filesizelimit: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_imgdpi
  引用相依:
  方法描述:獲取掃描影像的 DPI 設定值。
============================================================================== }
function TCB_IMGPSScanX.Get_imgdpi: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_scancolor
  引用相依:
  方法描述:獲取掃描顏色模式的索引值。
============================================================================== }
function TCB_IMGPSScanX.Get_scancolor: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_casenolength
  引用相依:
  方法描述:設定案件編號的長度限制。若傳入值為空字串則設為 0;否則將字串轉換為整數
            後賦值給 FCaseNoLength 與全域變數 CaseIDLength。
============================================================================== }
procedure TCB_IMGPSScanX.Set_casenolength(const Value: WideString);
begin
  if Value ='' then
  begin
    FCaseNoLength := 0 ;
    CaseIDLength := FCaseNoLength;
  end
  else
  begin
    FCaseNoLength := StrToInt(Value) ;
    CaseIDLength := FCaseNoLength;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_filesizelimit
  引用相依:
  方法描述:設定影像檔案的大小限制(KB)。若傳入值為空,則預設為 5120 KB (5MB);否則
            將字串轉換為整數後賦值給 FFileSizeLimit。
============================================================================== }
procedure TCB_IMGPSScanX.Set_filesizelimit(const Value: WideString);
begin
//ShowMessage(Value);
  FFileSizeLimit:=0;
  if Value ='' then
  begin
    FFileSizeLimit := 5*1024;
  end
  else
  begin
    FFileSizeLimit := StrToInt(Value);
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_imgdpi
  引用相依:
  方法描述:設定掃描 DPI。若傳入值為空,則預設為 300 DPI;否則將字串轉整數後賦值給 
            FImgDPI,並同步更新全域變數 ScanDpi 與 Def_ScanDpi。
============================================================================== }
procedure TCB_IMGPSScanX.Set_imgdpi(const Value: WideString);
begin
  if Value ='' then
  begin
    FImgDPI := 300;
    ScanDpi := FImgDPI;
  end
  else
  begin
    FImgDPI := StrToInt(Value);
    ScanDpi := FImgDPI;
    Def_ScanDpi := FImgDPI;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_scancolor
  引用相依:ifBlackWhite, ifGray256, ifTrueColor
  方法描述:設定掃描色彩模式。將傳入的數值字串轉為整數。0 代表黑白(ifBlackWhite),1
             代表灰階(ifGray256),2 代表全彩(ifTrueColor)。此函式會同步更新 FScanC
            olor 與全域變數 ScanColor,確保掃描器使用正確的色彩模式。
============================================================================== }
procedure TCB_IMGPSScanX.Set_scancolor(const Value: WideString);
begin
  if value='' then
  begin
    FScanColor := 0;
    ScanColor := ifBlackWhite;
  end
  else
  begin
    FScanColor := StrToInt(Value);
    ScanColor := ifBlackWhite;
  end;
 
  if FScanColor = 1 then
  begin
    ScanColor := ifGray256 ;
  end;
 
  if FScanColor = 2 then
  begin
    ScanColor := ifTrueColor ;
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_imgdelete
  引用相依:
  方法描述:獲取影像刪除權限的標記(FImgDelete)。
============================================================================== }
function TCB_IMGPSScanX.Get_imgdelete: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_imgdelete
  引用相依:
  方法描述:設定影像刪除權限。
============================================================================== }
procedure TCB_IMGPSScanX.Set_imgdelete(const Value: WideString);
begin
  FImgDelete:=Value;
end;
 
 
{ ==============================================================================
  方法名稱:Get_check_main_form
  引用相依:
  方法描述:獲取是否檢查主表單的標記(FCheck_main_form)。
============================================================================== }
function TCB_IMGPSScanX.Get_check_main_form: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Get_isExternal
  引用相依:
  方法描述:獲取是否為外部呼叫模式的標記(FIsExternal)。
============================================================================== }
function TCB_IMGPSScanX.Get_isExternal: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_check_main_form
  引用相依:
  方法描述:設定是否檢查主表單。
============================================================================== }
procedure TCB_IMGPSScanX.Set_check_main_form(const Value: WideString);
begin
  FCheck_main_form := Value;
end;
 
 
{ ==============================================================================
  方法名稱:Set_isExternal
  引用相依:
  方法描述:設定是否為外部呼叫模式。
============================================================================== }
procedure TCB_IMGPSScanX.Set_isExternal(const Value: WideString);
begin
  FIsExternal:=Value;
end;
 
 
{ ==============================================================================
  方法名稱:Get_WH_CATEGORY
  引用相依:
  方法描述:獲取倉庫類別資訊(FWH_category)。
============================================================================== }
function TCB_IMGPSScanX.Get_WH_CATEGORY: WideString;
begin
 
end;
 
 
{ ==============================================================================
  方法名稱:Set_WH_CATEGORY
  引用相依:
  方法描述:設定倉庫類別(WH_CATEGORY)。此範圍除包含 setter 實作外,亦涵蓋了組件的 
            initialization 初始區段,負責註冊 ActiveForm 工廠並設定多組授權金鑰(L
            icenseKey),確保 OCX 運作環境與權限正確初始化。
============================================================================== }
procedure TCB_IMGPSScanX.Set_WH_CATEGORY(const Value: WideString);
begin
  FWH_category:=Value;
end;
 
initialization
  TActiveFormFactory.Create(
    ComServer,
    TActiveFormControl,
    TCB_IMGPSScanX,
    Class_CB_IMGPSScanX,
    1,
    '',
    OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
    tmApartment);
 
  {SetLicenseKey('5B4451E676A1D2976FBB0F3BB18341336AF114C80B5ABAE7F6926B1CAF671F44' +
  'BD2F098CCEDA922F6389BFAE398DA6AEE67F97EEA0C17234C20D75C12173DBDA' +
  '594924D56DD8E342F454389C836AD880BB4352CA3BE62C4933B1BA3828E7462C' +
  '60514F2ECDAD322E6128D841F12D24DA00B623106D3F08EBCAA917D8A97CAA34' +
  '3D65F2DA567316457395BF9123EE53DF235D181F191A5712DBB27735284AA92D' +
  '5DFA0C8308308505F384707E900C6063F53F1BFF4C6972607955D1AE517B19D0' +
  '82CDD16301885403AD229D57BAEF98C056F31430861E5F68F339D658D72E1F92' +
  '63899412EC2D07891FE3AFD35F3E4A4390B2F0A8A1BF1B7D6160E5F1CC009B17'); }
  SetLicenseKey('4B2CF65E8C2A86CE8A0DD0F6A7DB03BC0B0126168B48AE4C27EBD78CAE75CF0F' +
   'A612190861E0D99F6FAE3ED97AC1941B5E97843CFFCF705A3787989072D4EB2C' +
   'AE6CAB3F5B69B86616ACC8A37AD6A2AB21C7BDD5C9AE1EDF9E4193D353805C9A' +
   '403631CE8A3D0803FEBB1BE4C209CE7A63B1298EF080EB34B8628CED567D2B68' +
   'E777FAC58E2E32B7411FC217A04336231D1E861A93474759DAA6EDF53F6EB632' +
   'A3055229A52F3053FB844754741409022DDE3DFB19473510F2BE63328E74BE20' +
   'A6A29AA24878F91ADA9DF8CE1F320AF4DAF58EBF95D9BE761D70EEA274E19475' +
   '1C15948B184264C5C49E60493F3BCD2FFAE2CA8B021D00B96F45550C5F050D8A');
 
 
  SetLicenseKey('A6A94A8D91B08A9D58F300C0573EA9EF1B9DB0BF69B90E13B958DB4CB6B44F5A' +
  '4EE9CB22C9A68C2D07ED52ED4D13C755D890E4074996755361E6CDE2A6F1B563' +
  '5DDC8999AC4D71FB092EA9F1F87BFA25694FBF0D6D250087D2B39629713FCCB0' +
  'D0A83135BC14FC63A4E8331CFF9E24C45C2D9CFD837EB70BAFDB79A75B7B97D5' +
  'E9EB271685118C29D90A7C85E7793908989E295DA50021C795A448366026E975' +
  'F49EA75B721B80427B99E5CF24A225FB498C07946ED7B806B483654C00D85C66' +
  'E34215CA3EDEF1D4C3F5896090E97E1E2C9752BA2D5B49EE58CF19A0D374077F' +
  '6D13B90B6FED22D9EBC3AD6CDC76E595E08725BF2E12B8EF30A524A2E00504DF');
end.