curtis
17小時前 5577f3ba7b9f0319c9b32d7080165207726d1f81
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
{ ==============================================================================
  方法名稱:CreateCaseNeedData
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:掃描案件目錄下的 Context.dat 影像清單,自動推導並產生該案件所需的 Doc
            Dir.dat、CaseDocNo.dat 及份數清單,用於修復或重建案件結構。
============================================================================== }
Procedure  TCB_IMGPSScanX.CreateCaseNeedData(Path:String);
var
  FileList,DocNoList,CaseDocNoList,CaseDocNo_CopiesList : TStringlist;
  i,n : Integer;
  Docno : String;
  Exists : Boolean;
begin
  FileList := TStringlist.Create;
  DocNoList := TStringlist.Create;
  CaseDocNoList := TStringlist.Create;
  CaseDocNo_CopiesList := TStringlist.Create;
  try
    if FileExists(Path+'Context.dat') then
    begin
      FileList.LoadFromFile(Path+'Context.dat');
      for i := 0 to FileList.Count - 1 do
      begin
        Docno := FormCode2DocNo(FileName2FormCode(FileList.Strings[i]));
//ShowMessage('Docno='+Docno);
        DocNoList.Add(DocNo);
        Exists := False;
        for n := 0 to CaseDocNoList.Count - 1 do
        begin
          if Docno = CaseDocNoList.Strings[n] then
            Exists := True;
        end;
        if not Exists then
        begin
          CaseDocNoList.Add(DocNo);
          CaseDocNo_CopiesList.Add('1');
        end;
      end;
//ShowMessage('CreateCaseNeedData  DocNoList='+DocNoList.Text);
      DocNoList.SaveToFile(Path+'DocDir.dat');
      CaseDocNoList.SaveToFile(Path+'CaseDocNo.dat');
      CaseDocNo_CopiesList.SaveToFile(Path+'CaseDocNo_Copies.dat')
    end;
 
  finally
  FileList.Free;
  DocNoList.Free;
  CaseDocNoList.Free;
  CaseDocNo_CopiesList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:Case2upload
  引用相依:CopyFile, DirectoryExists, FileExists, LoadFromFile, SaveToFile, Str
            2Dir, _DelTree
  方法描述:準備案件上傳用的資料夾結構。將分散在各文件子目錄下的影像檔案複製到單
            一的 Upload 目錄下並重新編號檔名,同時產生彙整後的索引檔與附件。
============================================================================== }
Procedure TCB_IMGPSScanX.Case2upload(CaseID:String);
var
  i,n:Integer;
  OldPath,NewPath,DocDir : String;
  OldFile,NewFile,AttFile : String;
  DocNoList,FileList:TStringlist;
  iFileList,iFile_DocNoList :TStringlist;
  iDocDirList : TStringlist;
  iAttFileList : TStringlist;
begin
  DocNoList := TStringlist.Create;
  FileList := TStringlist.Create;
  iFileList := TStringlist.Create;
  iFile_DocNoList := TStringlist.Create;
  iDocDirList := TStringlist.Create;
  iAttFileList := TStringlist.Create;
  try
    OldPath := ImageSavePath+CaseID+'\';
    NewPath := ImageSavePath+CaseID+'\Upload\';
    if DirectoryExists(NewPath) then
      _DelTree(NewPath);
    str2dir(NewPath);
    CopyFile(PWideChar(OldPath+'CaseDocNo.dat'),PWideChar(NewPath+'CaseDocNo.dat'),False);
    CopyFile(PWideChar(OldPath+'CaseDocNo_Copies.dat'),PWideChar(NewPath+'CaseDocNo_Copies.dat'),False);
    CopyFile(PWideChar(OldPath+'CustomDocNo.ini'),PWideChar(NewPath+'CustomDocNo.ini'),False);
    CopyFile(PWideChar(OldPath+'CaseIndex.dat'),PWideChar(NewPath+'CaseIndex.dat'),False);
    CopyFile(PWideChar(OldPath+'In_Wh.dat'),PWideChar(NewPath+'In_Wh.dat'),False);
    CopyFile(PWideChar(OldPath+'UseCase.ini'),PWideChar(NewPath+'UseCase.ini'),False);
 
    if FileExists(OldPath+'CaseDocNo.dat') then
    begin
      DocNoList.LoadFromFile(OldPath+'CaseDocNo.dat');
    end
    else
    begin
      DocNoList.SaveToFile(OldPath+'CaseDocNo.dat');
      CopyFile(PWideChar(OldPath+'CaseDocNo.dat'),PWideChar(NewPath+'CaseDocNo.dat'),False);
    end;
 
    for i := 0 to DocNoList.Count-1 do
    begin
      DocDir := DocNoList.Strings[i];
      OldPath := ImageSavePath+CaseID+'\'+ DocDir+'\';
 
      FileList.Clear;
      if FileExists(OldPath+'Context.dat') then
      begin
        FileList.LoadFromFile(OldPath+'Context.dat');
        for n := 0 to FileList.Count - 1 do
        begin
          OldFile := FileList.Strings[n];
          NewFile := Add_Zoo(iFileList.Count+1,3)+FileName2NoQuene_Filename(OldFile);
          CopyFile(PWideChar(OldPath+OldFile),PWideChar(NewPath+NewFile),False);
          iFileList.Add(NewFile);
          iFile_DocNoList.Add(DocNoDir2DocNo(DocDir));
          iDocDirList.Add(DocDir);
        end;
      end;
    end;
    if DirectoryExists(ImageSavePath+CaseID+'\Attach') then
    begin
      DocDir := 'Attach';
      OldPath := ImageSavePath+CaseID+'\'+ DocDir+'\';
 
      FileList.Clear;
      if FileExists(OldPath+'Context.dat') then
      begin
        FileList.LoadFromFile(OldPath+'Context.dat');
        for n := 0 to FileList.Count - 1 do
        begin
          OldFile := FileList.Strings[n];
          NewFile := Add_Zoo(iFileList.Count+1,3)+FileName2NoQuene_Filename(OldFile);
          CopyFile(PWideChar(OldPath+OldFile),PWideChar(NewPath+NewFile),False);
          iFileList.Add(NewFile);
          iFile_DocNoList.Add(DocNoDir2DocNo(DocDir));
          iDocDirList.Add(DocDir);
        end;
      end;
    end;
 
    if DirectoryExists(ImageSavePath+CaseID+'\S_Attach') then
    begin
      DocDir := 'S_Attach';
      OldPath := ImageSavePath+CaseID+'\'+ DocDir+'\';
 
      FileList.Clear;
      if FileExists(OldPath+'Context.dat') then
      begin
        FileList.LoadFromFile(OldPath+'Context.dat');
        for n := 0 to FileList.Count - 1 do
        begin
          OldFile := FileList.Strings[n];
          NewFile := Add_Zoo(iFileList.Count+1,3)+FileName2NoQuene_Filename(OldFile);
          CopyFile(PWideChar(OldPath+OldFile),PWideChar(NewPath+NewFile),False);
          iFileList.Add(NewFile);
          iFile_DocNoList.Add(DocNoDir2DocNo(DocDir));
          iDocDirList.Add(DocDir);
        end;
      end;
    end;
    OldPath := ImageSavePath+CaseID+'\';
    if FileExists(OldPath+'AttContext.dat') then
    begin
      iAttFileList.LoadFromFile(OldPath+'AttContext.dat');
      for n := 0 to iAttFileList.Count - 1 do
      begin
        AttFile := iAttFileList.Strings[n];
        CopyFile(PWideChar(OldPath+AttFile),PWideChar(NewPath+AttFile),False);
      end;
      iAttFileList.SaveToFile(NewPath+'AttContext.dat');
    end;
 
 
    iFileList.SaveToFile(NewPath+'Context.dat');
    iFile_DocNoList.SaveToFile(NewPath+'Context_DocNo.dat');
    iDocDirList.SaveToFile(NewPath+'DocDir.dat');
 
  finally
  iFileList.Free;
  iAttFileList.Free;
  iFile_DocNoList.Free;
  DocNoList.Free;
  FileList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:Download2Case
  引用相依:CopyFile, DirectoryExists, FileExists, LoadFromFile, SaveToFile
  方法描述:將下載或匯入的案件結構還原回本系統的多層級目錄結構。包含建立文件子目
            錄、檔案複製並重新編號、以及重建各類索引與份數設定檔。
============================================================================== }
Procedure TCB_IMGPSScanX.Download2Case(SoDir,DeDir:String);
var
  i,n : Integer;
  DocDir:String;
  OldFile,NewFile,AttFile:String;
  DocNoList,FileList : TStringlist;
  iFileList,iFile_DocDirList :TStringlist;
  iAttFileList :TStringlist;
  AA,AA2,AA3,AA4:Boolean;
begin
 
  if (not FileExists(SoDir+'CaseDocNo.dat')) or (not FileExists(SoDir+'DocDir.dat')) then   //截畫面會沒這些檔
  begin
//ShowMessage('產生必要的文字檔');
    CreateCaseNeedData(SoDir);   //產生必要的文字檔
  end;
 
  AA:=CopyFile(PWideChar(SoDir+'CaseDocNo.dat'),PWideChar(DeDir+'CaseDocNo.dat'),False);
  AA2:=CopyFile(PWideChar(SoDir+'CaseDocNo_Copies.dat'),PWideChar(DeDir+'CaseDocNo_Copies.dat'),False);
  AA3:=CopyFile(PWideChar(SoDir+'CustomDocNo.ini'),PWideChar(DeDir+'CustomDocNo.ini'),False);
  AA4:=CopyFile(PWideChar(SoDir+'UseCase.ini'),PWideChar(DeDir+'UseCase.ini'),False);
//ShowMessage(BoolToStr(AA)+#10#13+BoolToStr(AA2)+#10#13+BoolToStr(AA3)+#10#13+BoolToStr(AA4));
  if FileExists(SoDir+'DocDir.dat') then     //20170222 新加
  begin
    CopyFile(PWideChar(SoDir+'DocDir.dat'),PWideChar(DeDir+'DocDir.dat'),False);
  end;
 
 
  DocNoList := TStringlist.Create;
  FileList := TStringlist.Create;
  iFileList := TStringlist.Create;
  iFile_DocDirList := TStringlist.Create;
  iAttFileList := TStringlist.Create;
  try
    //if Not FileExists(SoDir+'Context.dat') then  Exit;
    //iFileList.LoadFromFile(SoDir+'Context.dat');
    //if iFileList.Count = 0 then Exit;
    if FileExists(SoDir+'Context.dat') then
      iFileList.LoadFromFile(SoDir+'Context.dat');
    if FileExists(SoDir+'DocDir.dat') then
      iFile_DocDirList.LoadFromFile(SoDir+'DocDir.dat');
    if iFileList.Count <> iFile_DocDirList.Count then
    begin
      for i := 0 to iFileList.Count - 1 do
      begin
        if i > iFile_DocDirList.Count -1 then
        begin
          iFile_DocDirList.Add(FormCode2DocNo(FileName2FormCode(iFileList.Strings[i])));
        end;
      end;
    end;
    if FileExists(SoDir+'CaseDocNo.dat') then
      DocNoList.LoadFromFile(SoDir+'CaseDocNo.dat');
    if FileExists(DeDir+'CaseDocNo_Copies.dat') then
      CaseDocNo_CopiesList.LoadFromFile(DeDir+'CaseDocNo_Copies.dat');
    {for i := 0 to DocNoList.Count - 1 do
    begin
      DocDir := DocNoList.Strings[i];
      MkDir(DeDir+DocDir);
    end;}
//ShowMessage('DocNoList='+DocNoList.Text);
 
    for i := DocNoList.Count - 1 downto 0 do
    begin
      DocDir := DocNoList.Strings[i];
      if not DirectoryExists(DeDir+DocDir) then
      begin
        MkDir(DeDir+DocDir);
        if not FileExists(DeDir+DocDir+'\Context.dat') then
          StringtoFile('',DeDir+DocDir+'\Context.dat');
      end
      else
      begin
//ShowMessage('GGG');
        DocNoList.Delete(i);
        DocNoList.SaveToFile(DeDir+'CaseDocNo.dat');
        if i <= CaseDocNo_CopiesList.Count-1  then
        begin
//ShowMessage('KKKK');
          CaseDocNo_CopiesList.Delete(i);
          CaseDocNo_CopiesList.SaveToFile(DeDir+'CaseDocNo_Copies.dat');
        end;
      end;
    end;
  //20170221 先註解起來  因為他在補充掃瞄時好像會有顯示的問題
 
    for i := 0 to iFileList.Count - 1 do
    begin
      OldFile := iFileList.Strings[i];
      DocDir := iFile_DocDirList.Strings[i];
      if (DocDir = 'Attach') or (DocDir = 'S_Attach') then
      begin
        if not DirectoryExists(DeDir+DocDir) then
          MkDir(DeDir+DocDir);
      end;
 
      FileList.Clear;
      if FileExists(DeDir+DocDir+'\Context.dat') then
      begin
        FileList.LoadFromFile(DeDir+DocDir+'\Context.dat');
      end;
      NewFile := Add_Zoo(FileList.Count+1,3)+FileName2NoQuene_Filename(OldFile);
      CopyFile(PWideChar(SoDir+OldFile),PWideChar(DeDir+DocDir+'\'+NewFile),False);
      FileList.Add(NewFile);
      FileList.SaveToFile(DeDir+DocDir+'\Context.dat');
    end;
 
    for i := DocNoList.Count -1 downto 0 do
    begin
      if (DocNoList.Strings[i] = 'Attach') or (DocNoList.Strings[i] = 'S_Attach') then
      begin
        DocNoList.Delete(i);
        DocNoList.SaveToFile(DeDir+'CaseDocNo.dat');
      end;
    end;
 
    {if (DocNoList.Count > 0) and ((DocNoList.Strings[DocNoList.Count-1] = 'Attach') or (DocNoList.Strings[DocNoList.Count-1] = 'S_Attach')) then
    begin
      DocNoList.Delete(DocNoList.Count-1);
      DocNoList.SaveToFile(DeDir+'CaseDocNo.dat');
    end; }
    CaseDocNo_CopiesList.Clear;
 
    if FileExists(DeDir+'CaseDocNo_Copies.dat') then
      CaseDocNo_CopiesList.LoadFromFile(DeDir+'CaseDocNo_Copies.dat');
    if DocNoList.Count > CaseDocNo_CopiesList.Count then
    begin
      for i := 0 to DocNoList.Count - 1 do
      begin
        if i > CaseDocNo_CopiesList.Count-1 then
        begin
          CaseDocNo_CopiesList.Add('1');
          //CaseDocNo_CopiesList.SaveToFile(DeDir+'CaseDocNo_Copies.dat');
        end;
      end;
    end;
    CaseDocNo_CopiesList.SaveToFile(DeDir+'CaseDocNo_Copies.dat');
    {if (not FileExists(DeDir+'CaseDocNo_Copies.dat') then
    begin
      CaseDocNo_CopiesList.Free;
      for i := 0 to DocNoList.Count - 1 do
      begin
        CaseDocNo_CopiesList.Add('1');
        CaseDocNo_CopiesList.SaveToFile(DeDir+'CaseDocNo_Copies.dat');
      end;
    end;}
    if FileExists(SoDir+'AttContext.dat') then
    begin
      iAttFileList.LoadFromFile(SoDir+'AttContext.dat');
      for i := 0 to iAttFileList.Count - 1 do
      begin
        AttFile := iAttFileList.Strings[i];
        CopyFile(PWideChar(SoDir+AttFile),PWideChar(DeDir+AttFile),False);
      end;
      iAttFileList.SaveToFile(DeDir+'AttContext.dat');
    end;
 
 
    if FMode='ESCAN' then
    begin
      InitExistImgList(DeDir);
    end;
 
 
  finally
  iFileList.Free;
  FileList.Free;
  DocNoList.Free;
  iFile_DocDirList.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:GetCaseFormID
  引用相依:LoadFromFile
  方法描述:從案件目錄的 Context.dat 檔案中搜尋並回傳該案件的主表單代碼(FormID)。
            程序會遍歷影像清單,提取各檔案的表單代碼,並排除特定的分案頁代碼,直到
            找到符合條件的主表單代碼為止。
============================================================================== }
Function TCB_IMGPSScanX.GetCaseFormID(Path:String):String;  //取案件的主FormID
var i,n : Integer;
    FileFormID : String;
begin
  Result := '';
  ContextList.LoadFromFile(Path+'Context.dat');
  for I := 0 to ContextList.Count - 1 do
  begin
    FileFormID := FileName2FormCode(ContextList.Strings[i]);
 
    if DivPageFormIDList.IndexOf(FileFormID)<>-1 then //20170509 跳過分案頁的formid
    begin
      Continue;
    end;
    if FindDivFormCode(FileFormID) then
    begin
      Result := FileFormID;
      Break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CreateFormID_FormName
  引用相依:SaveToFile
  方法描述:遍歷 ContextList,提取每個檔案的表單代號與名稱並格式化為「代號_名稱」,
            最後存成 FormCode_Name.dat 供上傳使用。
============================================================================== }
Procedure TCB_IMGPSScanX.CreateFormID_FormName(Path,CaseID:String);  //產生FormID_FormName.dat
var i : Integer;
    S : TStringlist;
    FormID : String;
    FormName : String;
begin
  S := TStringlist.Create;
  try
    for I := 0 to ContextList.Count - 1 do
    begin
      FormID := FileName2FormCode(ContextList.Strings[i]);
      FormName := FormCode2FormName(CaseID,FormID);
      S.Add(FormID+'_'+FormName);
    end;
    S.SaveToFile(Path + 'FormCode_Name.dat',TEnCoding.UTF8);
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CreateDocNo_DocName
  引用相依:SaveToFile
  方法描述:產生包含文件代號與名稱的對應檔 DocNo_Name.dat。首先執行案件內文件去重
            ,接著遍歷 CaseDocNoList 取得對應名稱,針對不需分組的文件會在名稱前加
            上星號標記,最後將結果以 UTF-8 編碼儲存。
============================================================================== }
Procedure TCB_IMGPSScanX.CreateDocNo_DocName(Path,CaseID:String);  //產生DocNo_DocName.dat
var
  i : Integer;
  S : TStringlist;
  Doc_Name : String;
begin
  S := TStringlist.Create;
  try
    DistinctDocNoinCase(Path);
    for i := 0 to CaseDocNoList.Count - 1 do
    begin
      Doc_Name := CaseDocNoList.Strings[i]+'_'+DocNo2DocName(CaseID,CaseDocNoList.Strings[i]);
      if not DocnoNeedGroup(CaseDocNoList.Strings[i]) Then  //不用分組的加*號給智豪
        Doc_Name := '*'+Doc_Name;
      S.Add(Doc_Name);
    end;
    S.SaveToFile(Path+'DocNo_Name.dat',TEnCoding.UTF8);
  finally
  S.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CreateIn_WH
  引用相依:FileExists, LoadFromFile, SaveToFile
  方法描述:產生在席文件清單檔 In_Wh.dat。讀取案件的文件目錄清單後,比對全域的在席
            文件清單(IN_WH_DocNoList),若文件代號匹配或屬於特定系統目錄(ZZZZZ),則
            將其加入清單並儲存,用於標記需留存實體的文件。
============================================================================== }
Procedure TCB_IMGPSScanX.CreateIn_WH(CaseID:String);  //產生In_WH.dat
var
  i,n : Integer;
  DocDirList,In_WH_List : TStringlist;
  iDocNo : String;
begin
  DocDirList := TStringlist.Create;
  In_WH_List := TStringlist.Create;
  try
    if FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then
      DocDirList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
    for i := 0 to DocDirList.Count - 1 do
    begin
      iDocNo := DocNoDir2DocNo(DocDirList.Strings[i]);
      for n := 0 to IN_WH_DocNoList.Count - 1 do
      begin
        if (iDocNo = IN_WH_DocNoList.Strings[n]) or (Copy(iDocNo,1,5)='ZZZZZ') then
        begin
          In_WH_List.Add(DocDirList.Strings[i]);
          Break;
        end;
      end;
    end;
    In_WH_List.SaveToFile(ImageSavePath+CaseID+'\In_Wh.dat');
 
  finally
  DocDirList.Free;
  In_WH_List.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:CreateDocNo_Info
  引用相依:FileExists, LoadFromFile
  方法描述:產生案件內標準文件(非自訂)的彙總資訊字串。方法讀取 CaseDocNo.dat,針對
            每個非 'ZZZZZ' 開頭的文件編號,計算其在案件中的總份數、累計總頁數,並檢
            查編輯狀態(異動旗標)。結果以「編號[Tab]份數[Tab]頁數[Tab]狀態」的格式逐
            行組成,作為案件上傳時與伺服器比對資料完整性的核心依據。
============================================================================== }
Function TCB_IMGPSScanX.CreateDocNo_Info(CaseID:String):String; //產生 DocNo[tab]份數[tab]總頁數[tab]是否異動[換行]DocNo[tab]份數[tab]總頁數[tab]是否異動
var
  i,n : Integer;
  DocDirList,DocDir_CopiesList,FileList,C_DocNoList : TStringlist;
  DocNo,iDocDir,iDocNo,iEdit:String;
  icopys,ipages : integer;
  S,S1 : TStringlist;
  Str : String;
begin
  DocDirList := TStringlist.Create;
  DocDir_CopiesList := TStringlist.Create;
  FileList := TStringlist.Create;
  C_DocNoList := TStringlist.Create;
  try
    Str := '';
    if Not FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then Exit;
 
    DocDirList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
 
    if DocDirList.Count =0 then exit;//20170222 新加
 
 
    DocDir_CopiesList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo_Copies.dat');
    while DocDirList.Count > 0 do
    begin
      iDocDir := DocDirList.Strings[0];
      DocNo := DocNoDir2DocNo(iDocDir);
      if Copy(iDocDir,1,5) <> 'ZZZZZ' then   //不為自定文件
      begin
        //icopys := 1;
        icopys := GetDocNoCount(CaseID,DocNo);
        ipages := GetDocDir_Page(CaseID,iDocDir);
        iEdit := GetDocNoEdit(CaseID,DocNo,'');
        for i := DocDirList.Count - 1 downto 1 do
        begin
          iDocDir := DocDirList.Strings[i];
          iDocNo := DocNoDir2DocNo(iDocDir);
          if iDocNo = DocNo then
          begin
            //inc(icopys);
            ipages := ipages + GetDocDir_Page(CaseID,iDocDir);
            DocDirList.Delete(i);
          end;
        end;
        if str = '' then
          Str := Format('%s'+#9+'%d'+#9+'%d'+#9+'%s',[DocNo,iCopys,iPages,iEdit])
        else
          Str := Str+#13#10+ Format('%s'+#9+'%d'+#9+'%d'+#9+'%s',[DocNo,iCopys,iPages,iEdit]);
      end;
      DocDirList.Delete(0);
    end;
 
 
  finally
  DocDirList.Free;
  DocDir_CopiesList.Free;
  FileList.Free;
  C_DocNoList.Free;
  end;
  Result := Str;
 
  {S := TStringlist.Create;
  S1 := TStringlist.Create;
  try
    S.LoadFromFile(Path+'Context.dat');
    S1.LoadFromFile(Path+'Context_DocNo.dat');
    for i := 0 to CaseDocNoList.Count - 1 do
    begin
      iDocNo := CaseDocNoList.Strings[i];
      iCopys := GetDocNo_Count(Path,iDocNo);
      iPages := GetDocNo_Page(Path,iDocNo);
      if str = '' then
        Str := Format('%s,%d,%d',[iDocNo,iCopys,iPages])
      else
        Str := Str+';'+ Format('%s,%d,%d',[iDocNo,iCopys,iPages]);
    end;
    Result := Str;
 
  finally
  S.Free;
  S1.Free;
  end; }
end;
 
 
{ ==============================================================================
  方法名稱:CreateCustDocNo_Info
  引用相依:FileExists, LoadFromFile
  方法描述:產生案件內自訂文件的彙總資訊字串。方法專門處理代碼開頭為 'ZZZZZ' 的文
            件目錄,透過 GetCustomDocName 取得使用者定義的文件名稱,並彙整其總份數
            、總頁數與編輯異動狀態。最終格式與標準文件一致,但首位欄位改為顯示自訂
            名稱,確保自訂類別的文件也能正確被伺服器識別與儲存。
============================================================================== }
Function TCB_IMGPSScanX.CreateCustDocNo_Info(CaseID:String):String; //產生自訂文件 DocName[tab]份數[tab]總頁數[tab]是否異動[#13#10]DocName[tab]份數[tab]總頁數[tab]是否異動
var
  i,n : Integer;
  DocDirList,FileList : TStringlist;
  DocNo,DocName,iDocDir,iDocNo,iEdit:String;
  icopys,ipages : integer;
  S,S1 : TStringlist;
  Str : String;
begin
  DocDirList := TStringlist.Create;
  FileList := TStringlist.Create;
  try
    Str := '';
    if Not FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then Exit;
    DocDirList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
//ShowMessage(DocDirList.Text);
    while DocDirList.Count > 0 do
    begin
      iDocDir := DocDirList.Strings[0];
      DocNo := DocNoDir2DocNo(iDocDir);
      if Copy(iDocDir,1,5) = 'ZZZZZ' then   //是自定文件
      begin
        //icopys := 1;
        DocName := GetCustomDocName(ImageSavePath+CaseID+'\',DocNo);
        icopys := GetDocNoCount(CaseID,DocNo);
        ipages := GetDocDir_Page(CaseID,iDocDir);
        iEdit := GetDocNoEdit(CaseID,DocNo,DocName);
        for i := DocDirList.Count - 1 downto 1 do
        begin
          iDocDir := DocDirList.Strings[i];
          iDocNo := DocNoDir2DocNo(iDocDir);
          if iDocNo = DocNo then
          begin
            //inc(icopys);
            ipages := ipages + GetDocDir_Page(CaseID,iDocDir);
            DocDirList.Delete(i);
          end;
        end;
        DocName := GetCustomDocName(ImageSavePath+CaseID+'\',DocNo);
        if str = '' then
          Str := Format('%s'+#9+'%d'+#9+'%d'+#9+'%s',[DocName,iCopys,iPages,iEdit])
        else
          Str := Str+#13#10+ Format('%s'+#9+'%d'+#9+'%d'+#9+'%s',[DocName,iCopys,iPages,iEdit]);
      end;
      DocDirList.Delete(0);
    end;
  finally
  DocDirList.Free;
  FileList.Free;
  end;
  Result := Str;
end;
 
 
{ ==============================================================================
  方法名稱:CreateDocnoFrom_Info
  引用相依:FileExists, LoadFromFile
  方法描述:產生被引進的保管袋文件詳細資訊字串。程序遍歷案件的文件目錄,排除自定義
            文件後,取得各文件的份數、總頁數、異動狀態及來源案件編號(UseCase)。若同
            一文件來自多個目錄,則會累加數據,最後產出以 Tab 分隔的文件資訊清單。
============================================================================== }
Function TCB_IMGPSScanX.CreateDocnoFrom_Info(CaseID:String):String; //產生被引進的保管袋文件資訊  Docno[tab]份數[tab]案件編號#13#10Docno[tab]份數[tab]案件編號
var
  i,n : Integer;
  DocDirList,DocDir_CopiesList,FileList : TStringlist;
  DocNo,iDocDir,iDocNo,iEdit:String;
  FromCaseID : string;
  icopys,ipages : integer;
  S,S1 : TStringlist;
  Str : String;
begin
  DocDirList := TStringlist.Create;
  DocDir_CopiesList := TStringlist.Create;
  FileList := TStringlist.Create;
  try
    Str := '';
    if Not FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then Exit;
    DocDirList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
 
    if DocDirList.Count=0 then exit;//20170222 新加
 
 
    DocDir_CopiesList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo_Copies.dat');
    while DocDirList.Count > 0 do
    begin
      iDocDir := DocDirList.Strings[0];
      DocNo := DocNoDir2DocNo(iDocDir);
      if (Copy(iDocDir,1,5) <> 'ZZZZZ') then   //不為自定文件
      begin
        //icopys := 1;
        //icopys := GetDocNoCount(CaseID,DocNo);
        icopys := GetDocDirCopies(CaseID,iDocDir);
        ipages := GetDocDir_Page(CaseID,iDocDir);
        iEdit := GetDocNoEdit(CaseID,DocNo,'');
        FromCaseID := GetUseCase('F',ImageSavePath+CaseID+'\',iDocDir);
        if FromCaseID <> '' then
        begin
          for i := DocDirList.Count - 1 downto 1 do
          begin
            iDocDir := DocDirList.Strings[i];
            iDocNo := DocNoDir2DocNo(iDocDir);
            if (iDocNo = DocNo) and (GetUseCase('F',ImageSavePath+CaseID+'\',iDocDir)<>'') then
            begin
              FromCaseID := GetUseCase('F',ImageSavePath+CaseID+'\',iDocDir);
              //inc(icopys);
              icopys := icopys + GetDocDirCopies(CaseID,iDocDir);
              ipages := ipages + GetDocDir_Page(CaseID,iDocDir);
              DocDirList.Delete(i);
            end;
          end;
          if str = '' then
            Str := Format('%s'+#9+'%d'+#9+'%s',[DocNo,iCopys,FromCaseID])
          else
            Str := Str+#13#10+ Format('%s'+#9+'%d'+#9+'%s',[DocNo,iCopys,FromCaseID]);
        end;
      end;
      DocDirList.Delete(0);
    end;
  finally
  DocDirList.Free;
  DocDir_CopiesList.Free;
  FileList.Free;
  end;
  Result := Str;
end;
 
 
{ ==============================================================================
  方法名稱:CreateCustDocNoFrom_Info
  引用相依:FileExists, LoadFromFile
  方法描述:產出自定義文件的引進資訊字串。專門處理前綴為 "ZZZZZ" 的目錄,提取自定
            義文件名稱、份數及來源案件。與保管袋文件類似,會執行重複合併並統計總頁
            數,最後產出格式化的資訊字串。
============================================================================== }
Function TCB_IMGPSScanX.CreateCustDocNoFrom_Info(CaseID:String):String; //產生被引進的自定文件資訊  Docno[tab]份數[tab]案件編號#13#10Docno[tab]份數[tab]案件編號
var
  i,n : Integer;
  DocDirList,FileList : TStringlist;
  DocNo,DocName,iDocDir,iDocNo,iEdit:String;
  FromCaseID : string;
  icopys,ipages : integer;
  S,S1 : TStringlist;
  Str : String;
begin
  DocDirList := TStringlist.Create;
  FileList := TStringlist.Create;
  try
    Str := '';
    if Not FileExists(ImageSavePath+CaseID+'\CaseDocNo.dat') then Exit;
    DocDirList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat');
    while DocDirList.Count > 0 do
    begin
      iDocDir := DocDirList.Strings[0];
      DocNo := DocNoDir2DocNo(iDocDir);
      if Copy(iDocDir,1,5) = 'ZZZZZ' then   //是自定文件
      begin
        //icopys := 1;
        //icopys := GetDocNoCount(CaseID,DocNo);
        icopys := GetDocDirCopies(CaseID,iDocDir);
        ipages := GetDocDir_Page(CaseID,iDocDir);
        iEdit := GetDocNoEdit(CaseID,DocNo,DocName);
        FromCaseID := GetUseCase('F',ImageSavePath+CaseID+'\',iDocDir);
        if FromCaseID <> '' then
        begin
          for i := DocDirList.Count - 1 downto 1 do
          begin
            iDocDir := DocDirList.Strings[i];
            iDocNo := DocNoDir2DocNo(iDocDir);
            if (iDocNo = DocNo) and (GetUseCase('F',ImageSavePath+CaseID+'\',iDocDir)<>'') then
            begin
              FromCaseID := GetUseCase('F',DisplayPath,iDocDir);
              //inc(icopys);
              ipages := ipages + GetDocDir_Page(CaseID,iDocDir);
              DocDirList.Delete(i);
            end;
          end;
          DocName := GetCustomDocName(ImageSavePath+CaseID+'\',DocNo);
          if str = '' then
            Str := Format('%s'+#9+'%d'+#9+'%s',[DocName,iCopys,FromCaseID])
          else
            Str := Str+#13#10+ Format('%s'+#9+'%d'+#9+'%s',[DocName,iCopys,FromCaseID]);
        end;
      end;
      DocDirList.Delete(0);
    end;
  finally
  DocDirList.Free;
  FileList.Free;
  end;
  Result := Str;
end;
 
 
{ ==============================================================================
  方法名稱:CreateAttach_Info
  引用相依:
  方法描述:判斷案件是否存在附加電子檔。透過檢查附加檔案目錄的總頁數是否大於 0,回
            傳 "Y" 或 "N"。
============================================================================== }
Function TCB_IMGPSScanX.CreateAttach_Info(CaseID:String):String; //產生是否有Attach Y:有 N:沒有
begin
  Result := 'N';
  if GetDocDir_Page(CaseID,AttName) > 0 Then
    Result := 'Y';
end;