From ef8675b8cf493c2b08c428b8f9f5e35a5c52e51c Mon Sep 17 00:00:00 2001
From: Hong-Dell\Hong <chlin1022@i-mps.com>
Date: 星期二, 08 十一月 2022 12:04:52 +0800
Subject: [PATCH] Ver 2,0,1,77

---
 CB_IMGPSScanImp.pas |  606 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 464 insertions(+), 142 deletions(-)

diff --git a/CB_IMGPSScanImp.pas b/CB_IMGPSScanImp.pas
index 65d6fe7..2568e1a 100644
--- a/CB_IMGPSScanImp.pas
+++ b/CB_IMGPSScanImp.pas
@@ -1,5 +1,5 @@
 unit CB_IMGPSScanImp;
-
+//Test
 {$WARN SYMBOL_PLATFORM OFF}
 
 interface
@@ -9,12 +9,20 @@
   EnDiGrph, { for TDibGraphic }
   EnMisc,   { for MinFloat }
   EnTifGr,  { for TTifGraphic }
+  {$IFDEF Production}
+  CB_IMGPSScan_TLB,
+  {$ENDIF}
+  {$IFDEF Test}
+  CB_IMGPSScan_test_TLB,
+  {$ENDIF}
+
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  ActiveX, AxCtrls, CB_IMGPSScan_TLB, StdVcl, VCLUnZip, VCLZip, Encryp,
+  ActiveX, AxCtrls, StdVcl, VCLUnZip, VCLZip, Encryp,
   ExtCtrls, ComCtrls, Menus, StdCtrls, Gauges, EnImgScr, PJMenuSpeedButtons,
   Buttons, ImgList, SBSimpleSSL, SBHTTPSClient, SBWinCertStorage, SBX509,
   SBCustomCertStorage, SBUtils,mpsBarco,BarcodesFinder,HTTPApp,ErrList,
-  Xmltool,inifiles,printers,IdHashMessageDigest, idHash, LogFile;
+  Xmltool,inifiles,printers,IdHashMessageDigest, idHash, LogFile,ShellApi,
+  SBSocket;
 
 var
   Ch_WriteNote : Boolean;
@@ -111,7 +119,6 @@
     Splitter1: TSplitter;
     Panel3: TPanel;
     Label7: TLabel;
-    TreeView1: TTreeView;
     Panel6: TPanel;
     CB1: TCheckBox;
     ScanDuplexCB: TCheckBox;
@@ -180,7 +187,6 @@
     PM402: TMenuItem;
     PM403: TMenuItem;
     PM404: TMenuItem;
-    HTTPSClient: TElHTTPSClient;
     ElWinCertStorage: TElWinCertStorage;
     ElMemoryCertStorage: TElMemoryCertStorage;
     Panel5: TPanel;
@@ -188,8 +194,6 @@
     Panel11: TPanel;
     SampleScanBtn: TBitBtn;
     WNoteBtn: TBitBtn;
-    Panel13: TPanel;
-    CaseHelpBtn: TBitBtn;
     PopupMenu1: TPopupMenu;
     PM101: TMenuItem;
     N12: TMenuItem;
@@ -247,7 +251,6 @@
     Edit1: TEdit;
     PM110: TMenuItem;
     Image1: TImage;
-    PrtLb: TLabel;
     UseOldCaseLb: TLabel;
     PM111: TMenuItem;
     SmoothCB: TCheckBox;
@@ -258,6 +261,18 @@
     Label3: TLabel;
     LogFile1: TLogFile;
     ScanGrayCB: TCheckBox;
+    AttFileGB: TGroupBox;
+    AttListBox: TListBox;
+    Panel20: TPanel;
+    AddAttFileLB: TLabel;
+    DelAttFileLB: TLabel;
+    Splitter2: TSplitter;
+    Panel17: TPanel;
+    TreeView1: TTreeView;
+    Panel13: TPanel;
+    PrtLb: TLabel;
+    CaseHelpBtn: TBitBtn;
+    HTTPSClient: TElHTTPSClient;
     procedure ActiveFormCreate(Sender: TObject);
     procedure Panel9Resize(Sender: TObject);
     procedure ISB1Click(Sender: TObject);
@@ -376,6 +391,14 @@
     procedure TreeView1MouseEnter(Sender: TObject);
     procedure ScrollBox1MouseEnter(Sender: TObject);
     procedure ScanGrayCBClick(Sender: TObject);
+    procedure AddAttFileLBClick(Sender: TObject);
+    procedure DelAttFileLBClick(Sender: TObject);
+    procedure AttListBoxDblClick(Sender: TObject);
+    procedure AttListBoxClick(Sender: TObject);
+    procedure TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure HTTPSClientRedirection(Sender: TObject; const OldURL: string;
+      var NewURL: string; var AllowRedirection: Boolean);
   private
     { Private declarations }
     HotKeyId1,HotKeyId2,HotKeyId3,HotKeyId4 :Integer;
@@ -473,6 +496,7 @@
     CaseDocNoList : TStringlist;  //案件裡的DocNo清單(不重複)
     CaseDocNo_CopiesList : TStringlist; //案件裡的DocNo份數清單
     ContextList : TStringlist; //案件裡的檔案清單
+    AttContextList : TStringlist; //案件裡的附加檔案清單
     OMRFileList : TStringList; //要OMR檢核的文件(只檢查每種Form的第一頁)
     Cust_DocNoList : TStringlist; //自行定義文件名稱
     IN_WH_DocNoList : TStringlist; //入庫的文件清單
@@ -572,7 +596,7 @@
     FJpgCompression:integer;// 20171211 jpg to tif 的壓縮率
 
     Draging : Boolean;
-
+    MDown : Boolean;  //20181210 用來判斷滑鼠右鍵要Popupmenu是否有MouseDonw發生
 
     FEvents: ICB_IMGPSScanXEvents;
 
@@ -650,6 +674,7 @@
     Procedure initkscan; //檢查掃描器的功能
     procedure LoadImgFile; //載入案件
     procedure LoadImgFile1; //載入案件
+    procedure LoadAttFile(CaseID:String); //載入附加檔案
     Procedure DistinctFormCode(CaseID:String); //案件裡的FormCode取出第一頁
     Function OMRCheckCase(CaseID:String):Boolean; //OMR檢核
     Procedure OMRErr2ini(CaseID,Reason,FileName,Site,RelaFileName,RelaSite,Anchor,Anchor1:String;Del,Ingnore,Display:Boolean); //OMR檢核失敗寫入ini
@@ -712,6 +737,9 @@
     Procedure SetCaseList(Mode:Char;Index:Integer;text:String);  //'A:加入,I:插入,D:刪除,E:修改'
     Procedure SetDocNoList(Mode:Char;Index:Integer;CaseNo,DocDir,Copies:String);  //'A:加入,I:插入,D:刪除,E:修改'
     Procedure SetContextList(Mode:Char;Index:Integer;CaseNo,DocDir,FileName:String);  //'A:加入,I:插入,D:刪除,E:修改'
+    Procedure SetAttContextList(Mode:Char;Index:Integer;CaseNo,FileName:String);  //'A:加入,I:插入,D:刪除,E:修改'
+
+
     Function checkCaseOMRDone:Boolean;  //檢查案件是否完成OMR檢核
     Function CheckCaseID_OK:Boolean;  //檢查是否有未配號的案件
     Procedure CreateEmptyCase(Path,CaseID:String);  //產生空白案號(重掃件用)
@@ -723,7 +751,6 @@
     Procedure PageReplaceFormID(Path,NowFormID,NewFormID:String); //選取頁更換FormID
     Function ModeNeedCheck(OMRMode,ScanMode:String):Boolean; //掃瞄模式是否要做檢核
     procedure WMMOUSEWHEEL(var message: TWMMouseWheel); message WM_MOUSEWHEEL;
-    Function GetInputMask:String; //取得輸入的保單號碼
     Function GetCasePage(Path,CaseID:String):Integer;
     Function GetFormIDPage(FileList:TStringlist;FormID:String):Integer;
     Procedure SetFile2Case(CaseID,FileName:String);
@@ -1679,6 +1706,7 @@
   DocNo_List.Free; //DocNo清單
   Context_DocnoList.Free; //案件裡的檔案Docno清單
   ContextList.Free; //案件裡的檔案清單
+  AttContextList.Free; //案件裡的附加檔案清單
   NowShowFileList.Free;  //目前顯示的影像清單
   NowSelectFileList.Free; //目前被點選的影像清單
   Cust_DocNoList.Free; //自行定義文件名稱
@@ -2106,7 +2134,7 @@
               if FileExists(ImageSavePath + NowCaseno+'\'+DocDir+'\Context.dat') then
               begin
                 ST1.LoadFromFile(ImageSavePath + NowCaseno+'\'+DocDir+'\Context.dat');
-                if ISExistImg(ImageSavePath + NowCaseno+'\'+DocDir+'\'+ST1.Strings[0]) then
+                if (ST1.Count > 0) and ISExistImg(ImageSavePath + NowCaseno+'\'+DocDir+'\'+ST1.Strings[0]) then   //20181210 多增加判斷ST1>0 否則會有機會出現List out of bound  Hong
                 begin
                   DocDir := DocNo2DocNoDir(ImageSavePath + NowCaseno+'\',DocNo);
                 end;
@@ -2190,11 +2218,11 @@
     GoAtt := True;
   end;
 
-  if InputQuery('輸入其他文件名稱','文件名稱',CustomDocName) then
+  if InputQuery(_Msg('輸入其他文件名稱'),_Msg('文件名稱'),CustomDocName) then
   begin
     if FindCustomDocName(DisplayPath,CustomDocName) then
     begin
-      Showmessage(Format('文件名稱:"%s"己存在',[CustomDocName]));
+      Showmessage(Format(_Msg('文件名稱:"%s"己存在'),[CustomDocName]));
       Exit;
     end;
     CustomDocNo := GetNewCustomDocNo(DisplayPath,CustomDocName);
@@ -2274,7 +2302,7 @@
   iISBName,OldName : String;
   iISB : TImageScrollBox;
 begin
-  if MessageDlg('是否確定刪除??',mtconfirmation,[mbyes,mbcancel],0) = mrcancel then Exit;
+  if MessageDlg(_Msg('是否確定刪除??'),mtconfirmation,[mbyes,mbcancel],0) = mrcancel then Exit;
 
   for i := 0 to ComponentCount -1 do
   begin
@@ -2300,7 +2328,7 @@
 //ShowMessage('iISB.FileName='+iISB.FileName);
   ReSortFileName(ExtractFilePath(iISB.FileName));
   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);  //清掉檢核記錄
   TreeView1click(self);
@@ -2310,7 +2338,7 @@
 var
   mp:string;
 begin
-  mp := InputBox('移動頁數','請輸入移入頁碼','');
+  mp := InputBox(_Msg('移動頁數'),_Msg('請輸入移入頁碼'),'');
   if (mp <> '') then
   begin
     MoveImage(DisplayPath+NowDocDir+'\',strtoint(mp));
@@ -2629,7 +2657,8 @@
 begin
   Result:=False;
   ST:=TStringList.Create;
-  ST.loadFromfile(DocNopath+'\Context.dat');
+  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
@@ -2772,8 +2801,9 @@
 //ShowMessage(IntToStr(FileRec.Size)+','+IntToStr(FFileSizeLimit * 1024));
     If FileRec.Size > FFileSizeLimit * 1024 Then // 檢查檔案大小
     Begin
-      ShowMessage(Format('目前檔案大小為 %.3f MB', [FileRec.Size / (1024*1024)]) +
-        ',已超過單一檔案匯入限制'+Format('%.1f',[FFileSizeLimit/1024])+'MB');
+      ShowMessage(Format(_Msg('目前檔案大小為 %.3f MB,已超過單一檔案匯入限制%1.f MB'),[FileRec.Size / (1024*1024),FFileSizeLimit/1024]));
+      {ShowMessage(Format('目前檔案大小為 %.3f MB', [FileRec.Size / (1024*1024)]) +
+        ',已超過單一檔案匯入限制'+Format('%.1f',[FFileSizeLimit/1024])+'MB');}
       FindClose(FileRec);
       DataLoading(false, false);
       Exit;
@@ -2788,7 +2818,8 @@
     P := ISB.ImageCountFromFile(OpenDialog1.FileName);
     For i := 1 To P Do
     Begin
-      ShowText := _Msg('檔案加入中,請稍候(' + inttostr(i) + '/' + inttostr(P) + ')');
+      ShowText := Format(_Msg('檔案加入中,請稍候(%d/%d)'),[i,p]);
+      //ShowText := _Msg('檔案加入中,請稍候')+'(' + inttostr(i) + '/' + inttostr(P) + ')';
       DataLoading(True, True);
       ISB.LoadFromFile(FName, i);
       DeskewImg(ISB.Graphic);
@@ -2810,7 +2841,7 @@
       MpsGetBarcode(ISB_BW.Graphic, MpsBarcodeinf); //判斷A3 有用FormID 所以要先辨條碼
       For n := 1 To MpsBarcodeinf.Count Do
       Begin
-        If MpsBarcodeinf.r180[n] <> 0 Then // 依條碼角度轉影像
+        If (MpsBarcodeinf.r180[n] <> 0) and (Length(MpsBarcodeinf.Text[n])=FormIDLength) Then // 依條碼角度轉影像
         Begin
           Rotate(ISB.Graphic, MpsBarcodeinf.r180[n]);
           //MpsGetBarcode(iGraphic_First, MpsBarcodeinf);
@@ -2837,7 +2868,7 @@
         iRect.Bottom := ISB.Graphic.Height;
         CropImg(iGraphic_sec, iRect);
       End;
-
+      ISB.Graphic.Clear;  //20220711  Hong 覺得ISB後面沒有到了,先清掉減少記憶體使用
       iGraphic := iGraphic_First;
 
       While Not iGraphic.IsEmpty Do
@@ -2855,7 +2886,7 @@
 //ShowMessage(IntToStr(MpsBarcodeinf.Count));
           For n := 1 To MpsBarcodeinf.Count Do
           Begin
-            If MpsBarcodeinf.r180[n] <> 0 Then // 依條碼角度轉影像
+            If (MpsBarcodeinf.r180[n] <> 0) and (Length(MpsBarcodeinf.Text[n])=FormIDLength) Then // 依條碼角度轉影像
             Begin
               Rotate(iGraphic, MpsBarcodeinf.r180[n]);
               MpsGetBarcode(ISB_BW.Graphic, MpsBarcodeinf);
@@ -2892,7 +2923,7 @@
 
           DocNo := FormCode2DocNo(FormID);
           DocDir := FindLastestDocDir(CaseID, DocNo);
-          if (FMode='ESCAN') and (FModeName='補件掃描') then
+          if (FMode='ESCAN') and (FModeName=_Msg('補件掃描')) then
           begin
             DocDir := FindLastestDocDirForPage(CaseID, DocNo,FormID);
 //ShowMessage('DocDir='+DocDir);
@@ -2933,7 +2964,7 @@
 
           For n := 1 To MpsBarcodeinf.Count Do
           Begin
-            If MpsBarcodeinf.r180[n] <> 0 Then // 依條碼角度轉影像
+            If (MpsBarcodeinf.r180[n] <> 0) and (Length(MpsBarcodeinf.Text[n])=FormIDLength) Then // 依條碼角度轉影像
             Begin
               Rotate(iGraphic, MpsBarcodeinf.r180[n]);
               MpsGetBarcode(ISB_BW.Graphic, MpsBarcodeinf);
@@ -2941,11 +2972,31 @@
             End;
           End;
 //ShowMessage(IntToStr(iGraphic.Palette.palNumEntries));
-          if (iGraphic.Palette.palNumEntries = 0) or (iGraphic.Palette.palNumEntries = 256) then  //20171130 彩色 會為0  黑白 為2  灰階256
+          if iGraphic.ImageFormat = ifBlackWhite then   //20200806 出現無法匯入,是因color256無法壓JPEG,待報會後再開啟
+          begin
+            iGraphic.Compression:=tcGroup4;
+          end
+          else if iGraphic.ImageFormat= ifColor256 then
+          begin
+            ConverttoGray(iGraphic);
+            iGraphic.Compression:=tcJPEG;
+            iGraphic.JpegQuality:=cooom;
+          end
+          else if (iGraphic.ImageFormat = ifTrueColor) or (iGraphic.ImageFormat = ifGray256) then
           begin
             iGraphic.Compression:=tcJPEG;
             iGraphic.JpegQuality:=cooom;
+          end
+          else
+          begin
+            iGraphic.Compression:=tcLZW;
           end;
+
+          {if (iGraphic.Palette.palNumEntries = 0) or (iGraphic.Palette.palNumEntries = 256) then  //20171130 彩色 會為0  黑白 為2  灰階256     //20200806拿掉
+          begin
+            iGraphic.Compression:=tcJPEG;
+            iGraphic.JpegQuality:=cooom;
+          end;}
 
           If LowerCase(ExtractFileExt(SavePath + SaveFilename)) = '.tif' Then
           Begin
@@ -3096,6 +3147,8 @@
 
 finally
 ISB.Free;
+iGraphic_First.Free;
+iGraphic_sec.Free;
 end;
 
 
@@ -3241,12 +3294,12 @@
 
         if Trim(DocListForm.Edit1.Text)='' then
         begin
-          Showmessage('未輸入文件名稱');
+          Showmessage(_Msg('未輸入文件名稱'));
           Exit;
         end;
         if FindCustomDocName(DisplayPath,NewFormID) then
         begin
-          Showmessage(Format('文件名稱:"%s"己存在',[NewFormID]));
+          Showmessage(Format(_Msg('文件名稱:"%s"己存在'),[NewFormID]));
           Exit;
         end;
         if NowFormCode <> AttName then
@@ -3337,7 +3390,7 @@
   SavePath : String;
   ST1:TStringList;
 begin
-  if InputQuery('輸入其他文件名稱','文件名稱',CustomDocName) then
+  if InputQuery(_Msg('輸入其他文件名稱'),_Msg('文件名稱'),CustomDocName) then
   begin
     if CustomDocName <> '' then
     begin
@@ -3366,26 +3419,26 @@
 begin
   oldCopies := GetDocDirCopies(NowCaseno,NowDocDir);
   try
-    NewCopies := Strtoint(inputBox('修改份數','請輸入修改後的份數',inttostr(oldCopies)));
+    NewCopies := Strtoint(inputBox(_Msg('修改份數'),_Msg('請輸入修改後的份數'),inttostr(oldCopies)));
   except
-    Showmessage('輸入錯誤');
+    Showmessage(_Msg('輸入錯誤'));
     Exit;
   end;
   if (NewCopies <= 0) and (NewCopies >= 10000) then
   begin
-    Showmessage('輸入範圍錯誤');
+    Showmessage(_Msg('輸入範圍錯誤'));
     Exit;
   end;
 
   if (oldCopies <> NewCopies) and (NewCopies > 0) and (NewCopies < 10000) then
   begin
-    if DocNoNeedDiv(NowDocNo) and (NewCopies = 1) and (MessageDlg('修改至1份後此文件將無法再進行份數修改,是否確定??',mtConfirmation,[mbyes,mbcancel],0)= mrcancel) then
+    if DocNoNeedDiv(NowDocNo) and (NewCopies = 1) and (MessageDlg(_Msg('修改至1份後此文件將無法再進行份數修改,是否確定??'),mtConfirmation,[mbyes,mbcancel],0)= mrcancel) then
       Exit;
 
     SetDocDirCopies(NowCaseno,NowDocDir,NewCopies);
     SetRecordEditedDocDir('A',NowCaseNo,NowDocDir);
     DrawDocItem2(MytreeNode1,NowCaseno);
-    Showmessage('修改完成');
+    Showmessage(_Msg('修改完成'));
   end;
 
 end;
@@ -3541,7 +3594,7 @@
   if DisplayISB.FileName = '' then Exit;
   if (ContextList.Count = 1) and ((FMode = 'NSCAN') or (FMode = 'ASCAN') or (FMode = 'DSCAN') or (FMode = 'ISCAN') or (FMode = 'SSCAN') or (FMode = 'MSCAN') or (FMode = 'RI_SCAN')) then
   begin
-    if Messagedlg(_Msg('刪除後(%s)案件無影像,將刪除此案件,是否確定刪除?'),mtconfirmation,[mbyes,mbcancel],0) = mrCancel then Exit;
+    if Messagedlg(Format(_Msg('刪除後(%s)案件無影像,將刪除此案件,是否確定刪除?'),[NowCaseno]),mtconfirmation,[mbyes,mbcancel],0) = mrCancel then Exit;
     _DelTree(DisplayPath);
     SetCaseList('D',NewTreeNode.IndexOf(MyTreeNode1),'');
     LoadImgFile;
@@ -3612,7 +3665,7 @@
       PM104.Visible := True;   //檔案加入影像
     end;
 
-    if FModeName='異動件' then
+    if FModeName=_Msg('異動件') then
     begin
       PM101.Visible := True;
     end;
@@ -3637,7 +3690,7 @@
     if FMode='ESCAN' then
       PM101.Visible:=false;
 
-    if FModeName='異動件' then
+    if FModeName=_Msg('異動件') then
     begin
       PM101.Visible := True;
     end;
@@ -3677,7 +3730,7 @@
       PM101.Visible:=false;
     end;
 
-    if FModeName='異動件' then
+    if FModeName=_Msg('異動件') then
     begin
       PM101.Visible := True;
     end;
@@ -3716,7 +3769,7 @@
       PM101.Visible:=false;
     end;
 
-    if FModeName='異動件' then
+    if FModeName=_Msg('異動件') then
     begin
       PM101.Visible := True;
     end;
@@ -3818,7 +3871,7 @@
     PM605.Visible := True;  //刪除
   end;
 
-  if  FModeName<>'異動件' then
+  if  FModeName<>_Msg('異動件') then
   begin
     if (FImgDelete='Y') then
     begin
@@ -3891,7 +3944,7 @@
   if SampleFormIDList.IndexOf(SampleFormID)<>-1 then
   begin
     // Show a custom dialog
-    buttonSelected := messagedlg(SampleFormID+'已有範本,是否取代?',mtCustom,
+    buttonSelected := messagedlg(SampleFormID+_Msg('已有範本,是否取代?'),mtCustom,
                                 [mbYes,mbCancel], 0);
     if buttonSelected = mrCancel then
     begin
@@ -4082,6 +4135,36 @@
   end;
 end;
 
+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;
+
 procedure TCB_IMGPSScanX.AddCredit1RGClick(Sender: TObject);
 begin
   if DisplayPath <> '' then
@@ -4101,7 +4184,7 @@
 begin
   IF not InitialOk Then
   begin
-    Showmessage(_msg('資訊尚未下載完成,請稍候或重新進入'));
+    Showmessage(_Msg('資訊尚未下載完成,請稍候或重新進入'));
     Exit;
   end;
   if MyTreeNode1 = nil then
@@ -4135,6 +4218,26 @@
   ClearErrini(NowCaseno,MyTreeNode1);  //清掉檢核記錄
   SetDocDirtoSelected(MyTreeNode1,FirstDocDir);
   TreeView1Click(self);
+end;
+
+procedure TCB_IMGPSScanX.AttListBoxClick(Sender: TObject);
+begin
+  DelAttFileLB.Enabled := False;
+  if AttListBox.ItemIndex >= 0 then
+    DelAttFileLB.Enabled := True;
+end;
+
+procedure TCB_IMGPSScanX.AttListBoxDblClick(Sender: TObject);
+var
+  AttFile : String;
+begin
+  if AttListBox.ItemIndex < 0 then Exit;
+
+  AttFile := HTTPEncode(UTF8Encode(AttListBox.Items.Strings[AttListBox.ItemIndex]));
+  if FileExists(DisplayPath+AttFile) then
+    ShellExecute(Application.Handle,'open',PChar(DisplayPath+AttFile),nil,nil,SW_SHOW)
+  else
+    Showmessage(Format(_Msg('找不到檔案:%s'),[AttFile]));
 end;
 
 procedure TCB_IMGPSScanX.BtnMouseEnter(Sender: TObject);
@@ -4730,7 +4833,7 @@
         DocNo := FormCode2DocNo(FormID);
         ScanDocDir := FindLastestDocDir(ScanCaseno,DocNo);
 
-        if (FMode='ESCAN') and (FModeName='補件掃描') then    //20180207 加入的特殊邏輯
+        if (FMode='ESCAN') and (FModeName=_Msg('補件掃描')) then    //20180207 加入的特殊邏輯
         begin
           ScanDocDir := FindLastestDocDirForPage(ScanCaseno, DocNo,FormID);
         end;
@@ -4858,7 +4961,7 @@
   DeleteFile(LngPath+'mps.dat');
   end;
   ////壓zip//////
-  Showmessage('匯出完成,匯出檔案:'+LngPath+'mps.zip');
+  Showmessage(_Msg('匯出完成,匯出檔案:')+LngPath+'mps.zip');
 end;
 
 procedure TCB_IMGPSScanX.ImportBtClick(Sender: TObject);
@@ -4885,16 +4988,16 @@
 
       str2dir(ZipPath);
       if not ExecuteUnZip_Pwd(OpenDialog1.FileName,ZipPath,False,'9338430') then
-        Showmessage('無法解壓縮');
+        Showmessage(_Msg('無法解壓縮'));
       if not FileExists(ZipPath+'mps.dat') then
       begin
-        Showmessage('格式不符,無法匯入');
+        Showmessage(_Msg('格式不符,無法匯入'));
         Exit;
       end;
       S.LoadFromFile(ZipPath+'mps.dat');
       if (En_DecryptionStr_Base64('D',S.Strings[0],'9338430')<> ServerDate) then
       begin
-        Showmessage('檔案過期,無法匯入');
+        Showmessage(_Msg('檔案過期,無法匯入'));
         Exit;
       end;
 
@@ -4934,7 +5037,7 @@
   S.Free;
   _DelTree(ZipPath);
   end;
-  Showmessage('匯入完成');
+  Showmessage(_Msg('匯入完成'));
 end;
 
 procedure TCB_IMGPSScanX.HotKeyDown (var Msg : TMessage);
@@ -5326,6 +5429,12 @@
   Validate := True;
 end;
 
+procedure TCB_IMGPSScanX.HTTPSClientRedirection(Sender: TObject;
+  const OldURL: string; var NewURL: string; var AllowRedirection: Boolean);
+begin
+  AllowRedirection := True;
+end;
+
 procedure TCB_IMGPSScanX.EnableImage(v:integer;Sender : TObject);
 var bmp : Tbitmap;
 begin
@@ -5516,6 +5625,7 @@
 
   Result := False;     // http://192.168.0.101:8080/fbnp/servlet/CWC01?act=getservertime
   EnCodeDateTime := En_DecryptionStr_Base64('E',ServerDate+GetBalance2Time(Balance),Mpskey);
+
   ColumeStr := 'WORK_NO,DOC_NO,DOC_U_DESC,DOC_TYPE,DOC_VERSION,FORM_PAGES,START_DATE,STOP_DATE,IS_DOC_DIV,IS_IN_WH';
   //If not ProcessServlet(HTTPSClient,FURL+'servlet/CWC02 ','checktime='+EnCodeDateTime+'&mode=1&col='+Doc_Inf_Colume+'&workno='+FWork_No,FReWrite.Text,Memo1) Then
 
@@ -5915,7 +6025,7 @@
     begin
       if FileName2FormCode(FileList.Strings[i]) = FormID then
       begin
-        if (FMode = 'ESCAN') and (FModeName<>'異動件') then
+        if (FMode = 'ESCAN') and (FModeName<>_Msg('異動件')) then
         begin
           if ISExistImg(ImageSavePath+CaseID+'\'+DocDir+'\'+FileList.Strings[i]) then
           begin
@@ -6330,6 +6440,7 @@
     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');
 
@@ -6438,7 +6549,6 @@
   if HaveMask then
     ZipMaskFile(Path,MaskPath,Path,'MaskImg.zip');  //有遮罩設定的才產生
   /////壓檔////
-
   ///檢查上傳的zip大小////
    FName :=Path+ 'Img.zip';
 
@@ -6450,7 +6560,8 @@
 //exit;           //目前上傳檔案大小為xxMB,已超過50MB,無法上傳    %.3f  ,[FileRec.Size / 1048576]
     If FileRec.Size > StrtoInt(FMaxUploadSize) * 1048576 Then // 檢查檔案大小
     Begin
-      ShowMessage(Format('%s目前上傳檔案大小為%.3fMB,已超過'+FMaxUploadSize+'MB,無法上傳',[caseid,FileRec.Size / 1048576]) );
+      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;
@@ -6475,6 +6586,8 @@
   +'&in_doc2='+HTTPEncode(UTF8Encode(In_Doc2));
 //ShowMessage('SendData='+SendData);
 //ShowMessage(FData+#10#13+Doc_Data);
+  //Showmessage('Wait');
+
   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+'.');
@@ -6494,7 +6607,6 @@
     Exit;
   end;
   ////上傳////
-
   if FMode = 'ESCAN' then    //上傳舊件引入檔案      //20140616 原本先搬舊件再搬新件,改為先搬新件再搬舊件
   begin
     if not TransOldCaseFile(ImageSavePath+CaseID+'\') then
@@ -6503,9 +6615,6 @@
       Exit;
     end;
   end;
-
-
-
   // 呼叫Server完成 /////
   {If not CaseComplete(Path,CaseID,MainCase) Then
   begin
@@ -7309,6 +7418,49 @@
   end;
 end;
 
+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;
+
 Function TCB_IMGPSScanX.checkCaseOMRDone:Boolean;  //檢查案件是否完成OMR檢核
 var
   i : Integer;
@@ -7438,7 +7590,36 @@
   try
     NewDocNo := FormCode2DocNo(NewFormID);
     NewDocDir := FindLastestDocDir(CaseID,NewDocNo);
-    if NewDocDir = '' then
+
+    /////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
@@ -7465,7 +7646,7 @@
           NewDocDir := DocNo2DocNoDir(ImageSavePath + NowCaseno+'\',NewDocNo);
         end;
       end;
-    end;
+    end; }
     if Not DirectoryExists(ImageSavePath+CaseID+'\'+NewDocDir) then
     begin
       MkDir(ImageSavePath+CaseID+'\'+NewDocDir);
@@ -7583,26 +7764,6 @@
   Result := False;
   if Pos(ScanMode,OMRMode) > 0 then
     Result := True;
-end;
-
-Function TCB_IMGPSScanX.GetInputMask:String; //取得輸入的保單號碼
-var
-  InputMaskForm: TInputMaskForm;
-begin
-  Result := '';
-  ShowText := _msg('輸入保單號碼中');
-  DataLoading(True,True);
-  InputMaskForm := TInputMaskForm.Create(self);
-  try
-    InputMaskForm.MaskEdit1.ClearSelection;
-    if InputMaskForm.ShowModal = mrOk then
-    begin
-      Result := Trim(InputMaskForm.MaskEdit1.Text)+Trim(InputMaskForm.MaskEdit2.Text)+Trim(InputMaskForm.MaskEdit3.Text);
-    end;
-  finally
-  InputMaskForm.Free;
-  DataLoading(False,False);
-  end;
 end;
 
 Function TCB_IMGPSScanX.GetCasePage(Path,CaseID:String):Integer;
@@ -8100,6 +8261,18 @@
     end;
     if FileExists(SoPath+'Context.dat') then
       ZipFileList.Add(SoPath+'Context.dat');
+
+    AttContextList.Clear;
+    if FileExists(SoPath+'ATTContext.dat') then
+      AttContextList.LoadFromFile(SoPath+'ATTContext.dat');
+    for n := 0 to AttContextList.Count - 1 do
+    begin
+      ZipFileList.Add(SoPath+AttContextList.Strings[n]);
+    end;
+    if FileExists(SoPath+'ATTContext.dat') then
+      ZipFileList.Add(SoPath+'ATTContext.dat');
+
+
     if FileExists(SoPath+'Context_DocNo.dat') then
       ZipFileList.Add(SoPath+'Context_DocNo.dat');
     if FileExists(SoPath+'scanlist.dat') then
@@ -8306,7 +8479,7 @@
 begin
   if Mode = 'ID' then
   begin
-    Result := '自行輸入';
+    Result := _Msg('自行輸入');
     for i := 0 to ID_S.Count - 1 do
     begin
       if Str = ID_S.Strings[i] then
@@ -8750,7 +8923,7 @@
       //DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('頁'),[CaseDocNoList.Strings[i],DocNo2DocName(Caseno,iDocNo),DocNoPage]));
       //DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[CaseDocNoList.Strings[i],DocNo2DocName(Caseno,iDocNo),DocNoCopies]));
 //ShowMessage('iDocNo='+iDocNo);
-      DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[DocNo2DocName(Caseno,iDocNo),CaseDocNoList.Strings[i],DocNoCopies]));
+      DocNode := TreeView1.Items.AddChild(CaseNode,Format(_Msg('%s{%s}-%d份'),[DocNo2DocName(Caseno,iDocNo),CaseDocNoList.Strings[i],DocNoCopies]));
 
       if GetUseCase('F',ImageSavePath+Caseno+'\',CaseDocNoList.Strings[i]) <> '' Then
       begin
@@ -8780,7 +8953,7 @@
             FormPage := GetFormIDPage(FileList,FormID);
             FormName := FormCode2FormName(Caseno,FormID);
             //FormNode := TreeView1.Items.AddChild(DocNode,FormID+'{'+FormName+'}-'+inttostr(FormPage)+_msg('頁'));
-            FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+            FormNode := TreeView1.Items.AddChild(DocNode,Format(_Msg('%s{%s}-%d頁'),[FormName,FormID,FormPage]));
             FormNode.ImageIndex := 4;
             FormNode.SelectedIndex := 4;
             DocNode.AlphaSort(True);
@@ -8794,7 +8967,8 @@
         FormPage := GetFormIDPage(FileList,FormID);
         FormName := FormCode2FormName(Caseno,FormID);
         //FormNode := TreeView1.Items.AddChild(DocNode,FormID+'{'+FormName+'}-'+inttostr(FormPage)+_msg('頁'));
-        FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+        //FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+        FormNode := TreeView1.Items.AddChild(DocNode,Format(_Msg('%s{%s}-%d頁'),[FormName,FormID,FormPage]));
         FormNode.ImageIndex := 4;
         FormNode.SelectedIndex := 4;
         DocNode.AlphaSort(True);
@@ -8820,8 +8994,8 @@
             FormPage := GetFormIDPage(FileList,FormID);
             FormName := FormCode2FormName(Caseno,FormID);
             //FormNode := TreeView1.Items.AddChild(DocNode,FormID+'{'+FormName+'}-'+inttostr(FormPage)+_msg('頁'));
-            FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
-
+            //FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+            FormNode := TreeView1.Items.AddChild(DocNode,Format(_Msg('%s{%s}-%d頁'),[FormName,FormID,FormPage]));
             FormNode.ImageIndex := 4;
             FormNode.SelectedIndex := 4;
             DocNode.AlphaSort(True);
@@ -8855,7 +9029,7 @@
       DocNoPage := FileList.Count;
       iDocNo := DocNoDir2DocNo(AttName);
       //DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[AttName,DocNo2DocName(Caseno,iDocNo),1]));
-      DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[DocNo2DocName(Caseno,iDocNo),AttName,1]));
+      DocNode := TreeView1.Items.AddChild(CaseNode,Format(_Msg('%s{%s}-%d份'),[DocNo2DocName(Caseno,iDocNo),AttName,1]));
       DocNode.ImageIndex := 2;
       DocNode.SelectedIndex := 2;
       for n := 0 to FileList.Count - 1 do
@@ -8866,8 +9040,8 @@
           FormPage := GetFormIDPage(FileList,FormID);
           FormName := FormCode2FormName(Caseno,FormID);
           //FormNode := TreeView1.Items.AddChild(DocNode,FormID+'{'+FormName+'}-'+inttostr(FormPage)+_msg('頁'));
-          FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
-
+          //FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+          FormNode := TreeView1.Items.AddChild(DocNode,Format(_Msg('%s{%s}-%d頁'),[FormName,FormID,FormPage]));
           FormNode.ImageIndex := 4;
           FormNode.SelectedIndex := 4;
         end;
@@ -8889,7 +9063,9 @@
         DocNoPage := FileList.Count;
         iDocNo := DocNoDir2DocNo(AttName);
         //DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[AttName,DocNo2DocName(Caseno,iDocNo),1]));
-        DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[DocNo2DocName(Caseno,iDocNo),'Attach',1]));
+        //DocNode := TreeView1.Items.AddChild(CaseNode,Format('%s{%s}-%d'+_msg('份'),[DocNo2DocName(Caseno,iDocNo),'Attach',1]));
+        DocNode := TreeView1.Items.AddChild(CaseNode,Format(_Msg('%s{%s}-%d份'),[DocNo2DocName(Caseno,iDocNo),'Attach',1]));
+
         DocNode.ImageIndex := 2;
         DocNode.SelectedIndex := 2;
         for n := 0 to FileList.Count - 1 do
@@ -8900,7 +9076,8 @@
             FormPage := GetFormIDPage(FileList,FormID);
             FormName := FormCode2FormName(Caseno,FormID);
             //FormNode := TreeView1.Items.AddChild(DocNode,FormID+'{'+FormName+'}-'+inttostr(FormPage)+_msg('頁'));
-            FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+            //FormNode := TreeView1.Items.AddChild(DocNode,FormName+'{'+FormID+'}-'+inttostr(FormPage)+_msg('頁'));
+            FormNode := TreeView1.Items.AddChild(DocNode,Format(_Msg('%s{%s}-%d頁'),[FormName,FormID,FormPage]));
 
             FormNode.ImageIndex := 4;
             FormNode.SelectedIndex := 4;
@@ -8991,7 +9168,7 @@
     PrtDialog : TPrintDialog;
     S : String;
 begin
-  ShowText := '列印中,請稍候';
+  ShowText := _Msg('列印中,請稍候');
   DataLoading(True,True);
   Case2upload(NowCaseNo);   //產生原影像結構
 
@@ -9075,6 +9252,7 @@
   OldCaseInfoForm.IN_WH_DocNoList := TStringlist.Create;
   OldCaseInfoForm.OldCopiesList := TStringlist.Create;
   try
+    InitialLanguage(OldCaseInfoForm); //載入多國語言
     OldCaseInfoForm.Notebook1.ActivePage := 'CaseInfo';
     OldCaseInfoForm.ImageSavePath := ImageSavePath;
     OldCaseInfoForm.CaseID := NowCaseNo;
@@ -9101,7 +9279,7 @@
       Year := Caseinfolist.Strings[1];
       BS_No := Caseinfolist.Strings[2];
       IS_Old := Caseinfolist.Strings[3];
-      With OldCaseInfoForm.ListView1.Items.Add do
+      With OldCaseInfoForm.OldCaseLV.Items.Add do
       begin
         Caption := CaseID;
         SubItems.Add(Year);
@@ -9185,7 +9363,8 @@
       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('%s-%d'+_Msg('頁'),[NowCaseno,GetCasePage(ImageSavePath,NowCaseNo)]);
+      MyTreeNode1.Text := Format(_Msg('%s-%d頁'),[NowCaseno,GetCasePage(ImageSavePath,NowCaseNo)]);
       NewTreeNodeRefresh;
       ClearErrini(NowCaseno,MyTreeNode1);  //清掉檢核記錄
     end;
@@ -9260,6 +9439,9 @@
 begin
   ClearView(1);
   PageLV.Clear;
+  AttListBox.Items.Clear;
+  AddAttFileLB.Enabled := False;
+  DelAttFileLB.Enabled := False;
   DisplayPath := '';
   ClearCaseIndex;
   CaseHelpBtn.Visible := False;
@@ -9442,6 +9624,27 @@
   end;
 end;
 
+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;
+
 function TCB_IMGPSScanX.logTimeString: String;
 begin
 Result:=FormatDateTime('yyyymmdd hh:mm:ss',now) +'  caseNo='+NowCaseno+'  ';
@@ -9568,9 +9771,9 @@
   if FileExists(LngPath+'MPSLIC_SCAN.lic') then
     DeleteFile(LngPath+'MPSLIC_SCAN.lic');
   if LegalDate = '' then
-    StatusBar1.Panels[4].Text := '註冊號:'+MacID+' 剩餘註冊數:'+inttostr(Totalcount-Nowcount);
+    StatusBar1.Panels[4].Text := Format(_Msg('註冊號:%s 剩餘註冊數:%s'),[MacID,inttostr(Totalcount-Nowcount)]);
   if LegalDate <> '' then
-    StatusBar1.Panels[4].Text := '*註冊號:'+MacID+'('+inttostr(Lic_Idx)+')'+' 剩餘註冊數:'+inttostr(Totalcount-Nowcount);
+    StatusBar1.Panels[4].Text := '*'+Format(_Msg('註冊號:%s 剩餘註冊數:%s'),[MacID+'('+inttostr(Lic_Idx)+')',inttostr(Totalcount-Nowcount)]);
 end;
 
 procedure TCB_IMGPSScanX.SmoothCBClick(Sender: TObject);
@@ -9614,9 +9817,9 @@
       Anchor := FormID2Anchor(FormID);
       //ParserPoint(CropMpsV.FindPoint(Anchor));
       FindPoint(ImageScrollBox1.Graphic,UpLPoint,UpRPoint,DownLPoint,Anchor);
-      if FileExists(CheckXmlPath+FormID+'.xml') then  //沒有Xml就不用遮罩
+      if FileExists(CheckXmlPath+FWork_no+'\'+FormID+'.xml') then  //沒有Xml就不用遮罩
       begin
-        XT.LoadFromFile(CheckXmlPath+FormID+'.xml');
+        XT.LoadFromFile(CheckXmlPath+FWork_no+'\'+FormID+'.xml');
         if XT.SubNodes['/form/settype10/'].First then
         Repeat
           ColEName := XT.SubNodes['/form/settype10/'].NodeName;
@@ -9812,6 +10015,41 @@
   end;
 end;
 
+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;
+
 Procedure TCB_IMGPSScanX.DeleteCustomDocDir(Path,DocNo:String); //刪除自定文件DocNo
 var
   ini : Tinifile;
@@ -9858,7 +10096,7 @@
           Printer object. Otherwise, if UsePrintJob is True, the Title
           property of the TDibGraphicPrinter object is used to specify the
           job name. }
-        Printer.Title := '影像列印';
+        Printer.Title := _Msg('影像列印');
       end;
 
       IF (Page mod 2) = 1 Then
@@ -9883,7 +10121,7 @@
   procedure PrintWithAutoPrintJob;
   begin
       GraphicPrinter.UsePrintJob := True;
-      GraphicPrinter.Title       := '影像列印';
+      GraphicPrinter.Title       := _Msg('影像列印');
       GraphicPrinter.Print(ImageScrollBox1.Graphic);
   end;
 
@@ -10527,19 +10765,19 @@
         //Showmessage(FUrl+'service/slic/SLIC02/useOther?'+senddata);
         if not upFile(HTTPSClient,FUrl,'service/imgpsc/IMGPSC02/useOther',SendData,'file',OldCasePath+'UseCase.ini',FReWrite,Memo1,False) then
         begin
-          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!'+_Msg('錯誤代碼:')),[OldCaseID])+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason);
+          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!'),[OldCaseID])+_Msg('錯誤代碼:')+Inttostr(HttpError.HttpErrorCode)+' '+HttpError.HttpReason);
           Result := False;
           Exit;
         end;
         if memo1.Lines.Strings[0] = '1' then
         begin
-          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!')+_Msg('錯誤原因:'),[OldCaseID])+memo1.Lines.Strings[1]);
+          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!'),[OldCaseID])+_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
-          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!')+_Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入'),[OldCaseID]));
+          Showmessage(Format(_Msg('傳送舊件編號(%s)檔案時,網路發生錯誤!!'),[OldCaseID])+_Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入'));
           Result := False;
           Exit;
         end;
@@ -10608,10 +10846,17 @@
 Function TCB_IMGPSScanX.DocNoAppear(DocNo:String):Boolean;   //DocNo是否可出現
 begin
   Result := True;
-  if (((FIs_In_Wh  = 'Y') and (not DocNoIs_In_WH(DocNo)) or (DocNo ='S_Attach')) or   //入庫掃描不看非入庫文件
+
+  {if (((FIs_In_Wh  = 'Y') and (not DocNoIs_In_WH(DocNo)) or (DocNo ='S_Attach')) or   //入庫掃描不看非入庫文件
      ((FIs_In_Wh  = 'N') and (DocNoIs_In_WH(DocNo)) or (DocNo ='Attach') )) {and      //非入庫掃描不看入庫文件
+     (Copy(DocNo,1,5)<>'ZZZZZ')} {then
+       {Result := False;}
+  //20181031 應該要換成下面的判斷比較對,FIs_In_Wh傳空的話才會出全部
+  if (((FIs_In_Wh  = 'Y') and ((not DocNoIs_In_WH(DocNo)) or (DocNo ='S_Attach'))) or   //入庫掃描不看非入庫文件
+     ((FIs_In_Wh  = 'N') and ((DocNoIs_In_WH(DocNo)) or (DocNo ='Attach') ))) {and      //非入庫掃描不看入庫文件
      (Copy(DocNo,1,5)<>'ZZZZZ')} then
        Result := False;
+
 
 end;
 
@@ -11028,16 +11273,18 @@
 var
   i,n:Integer;
   OldPath,NewPath,DocDir : String;
-  OldFile,NewFile : 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\';
@@ -11122,6 +11369,18 @@
         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');
@@ -11129,6 +11388,7 @@
 
   finally
   iFileList.Free;
+  iAttFileList.Free;
   iFile_DocNoList.Free;
   DocNoList.Free;
   FileList.Free;
@@ -11139,9 +11399,10 @@
 var
   i,n : Integer;
   DocDir:String;
-  OldFile,NewFile:String;
+  OldFile,NewFile,AttFile:String;
   DocNoList,FileList : TStringlist;
   iFileList,iFile_DocDirList :TStringlist;
+  iAttFileList :TStringlist;
   AA,AA2,AA3,AA4:Boolean;
 begin
 
@@ -11166,6 +11427,7 @@
   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');
@@ -11279,6 +11541,17 @@
         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
@@ -11916,7 +12189,7 @@
 LogFile1.LogToFile(logTimeString+'最大頁數B段 '+CaseID+' '+'OMRFileList.Text='+OMRFileList.Text);
         For i := 0 to OMRFileList.Count - 1 do
         begin
-          if FModeName='異動件' then Continue;
+          if FModeName=_Msg('異動件') then Continue;
 
           if FWH_category='N' then
           begin
@@ -11964,11 +12237,11 @@
 //Display1.Lines.Add('OMRFile='+OMRFile+',OMRFormCode='+OMRFormCode+',OMRFormName='+OMRFormName);
 LogFile1.LogToFile(logTimeString+'OMRFile='+OMRFile+',OMRFormCode='+OMRFormCode+',OMRFormName='+OMRFormName);
 //ShowMessage('KKKKK');
-          if not FileExists(CheckXmlPath+OMRFormCode+'.xml') then  //沒有Xml就不用檢核
+          if not FileExists(CheckXmlPath+FWork_no+'\'+OMRFormCode+'.xml') then  //沒有Xml就不用檢核
             Continue;
 
 //ShowMessage('11638 OMRFileList.Strings['+IntToStr(i)+']'+OMRFileList.Strings[i]);
-          XT := TXmltool.Create(CheckXmlPath+OMRFormCode+'.xml');
+          XT := TXmltool.Create(CheckXmlPath+FWork_no+'\'+OMRFormCode+'.xml');
           RelaXT := TXmltool.Create;
 //ShowMessage('ModeNeedCheck='+BoolToStr(ModeNeedCheck(OMRErrInfo[4].Mode,FMode),true));
           try
@@ -12057,7 +12330,7 @@
                       RelaFile := FormCode2FileName(RelaFormCode,ContextList);
                       RelaFormName := FormCode2FormName(CaseID,RelaFormCode);
                       Anchor1 := FormID2Anchor(RelaFormCode);
-                      RelaXT.LoadFromFile(CheckXmlPath+RelaFormCode+'.xml');
+                      RelaXT.LoadFromFile(CheckXmlPath+FWork_no+'\'+RelaFormCode+'.xml');
 Display1.Lines.Add(RelaFile+','+RelaFormName);
 //ShowMessage(RelaFile);
 //ShowMessage(ImageSavePath+CaseID+'\upload\'+RelaFile);
@@ -12161,7 +12434,7 @@
                     RelaFile := FormCode2FileName(RelaFormCode,ContextList);
                     RelaFormName := FormCode2FormName(CaseID,RelaFormCode);
                     Anchor1 := FormID2Anchor(RelaFormCode);
-                    RelaXT.LoadFromFile(CheckXmlPath+RelaFormCode+'.xml');
+                    RelaXT.LoadFromFile(CheckXmlPath+FWork_no+'\'+RelaFormCode+'.xml');
 
                     if RelaFile<>'' then
                     begin
@@ -12512,7 +12785,7 @@
 begin
   Result := True;     // http://192.168.0.101:8080/fbnp/servlet/CWC01?act=getservertime
   //dnFile(HTTPSClient,FUrl+'Language.Lng','','',LngPath+'Language.Lng',FReWrite.Text,Memo1,False,DownImgStatus)
-  If not dnFile_Get(HTTPSClient,FUrl+'Language.Lng','','',LngPath+'Language.Lng',FReWrite,Memo1,False,'') Then
+  If not dnFile_Get(HTTPSClient,FUrl+'Language.Lng','','',LngPath+'Language.Lng',FReWrite,Memo1,False,DownImgStatus) Then
   begin
     HttpErrStr := _Msg('錯誤代碼:')+inttostr(HttpError.HttpErrorCode)+','+HttpError.HttpReason;
     Result := False;
@@ -12542,7 +12815,7 @@
     List_FormCode,Err_FormCode: String;
     iFormID : String;
 begin
-   ShowText := '影像顯示中,請稍候';
+   ShowText := _Msg('影像顯示中,請稍候');
    DataLoading(True,True);
 
    IF FormCode = 'ShowAll' then  //顯示所有的影像 (因為附件會傳空字串,所以用ShowAll)
@@ -12659,7 +12932,7 @@
     iGroupNo,page,Ct,int1 : Integer;
     ST1:TStringList;
 begin
-   ShowText := '影像顯示中,請稍候';
+   ShowText := _Msg('影像顯示中,請稍候');
    DataLoading(True,True);
 ST1:=TStringList.Create;
 //Display1.Lines.Clear;
@@ -12727,7 +13000,7 @@
            ISB.AntiAliased := False;
          ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[n],1);
 
-         DpiResize(ISB.Graphic,36);
+         DpiResize(ISB.Graphic,36,False);
          ISB.Redraw(true);
 
        end;
@@ -12787,7 +13060,7 @@
        if ISB.ZoomPercent > 100  then
          ISB.AntiAliased := False;
        ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[i],1);
-       DpiResize(ISB.Graphic,36);
+       DpiResize(ISB.Graphic,36,False);
        ISB.Redraw(true);
      end;
      FitPreViewISB;
@@ -12826,7 +13099,7 @@
            if ISB.ZoomPercent > 100  then
              ISB.AntiAliased := False;
            ISB.LoadFromFile(Path+iDocNo+'\'+ContextList.Strings[i],1);
-           DpiResize(ISB.Graphic,36);
+           DpiResize(ISB.Graphic,36,False);
            ISB.Redraw(true);
 
            //NowShowFileList.Add(ContextList.Strings[i]);
@@ -13984,7 +14257,7 @@
     end;
     if FileExists(CheckXmlPath+'OMRSet.zip') then   //有更新
     begin
-      ExecuteUnZip(CheckXmlPath+'OMRSet.zip',CheckXmlPath,False);
+      ExecuteUnZip(CheckXmlPath+'OMRSet.zip',CheckXmlPath,True);
       S.Clear;
       S.Add(ServerDate+GetBalance2Time(Balance));
       S.SaveToFile(CheckXmlPath+'LastDateTime.dat');
@@ -14042,7 +14315,7 @@
     end;
     if FileExists(SitePath+'KeyinSet.zip') then  //有更新
     begin
-      ExecuteUnZip(SitePath+'KeyinSet.zip',SitePath,False);
+      ExecuteUnZip(SitePath+'KeyinSet.zip',SitePath,True);
       S.Clear;
       S.Add(ServerDate+GetBalance2Time(Balance));
       S.SaveToFile(SitePath+'LastDateTime.dat');
@@ -14091,7 +14364,7 @@
     end;
   end;
 //ShowMessage(SendData);
-//ShowMessage(Memo1.Lines.Text);
+
   IF memo1.Lines.Strings[0] <> '0' Then
   begin
     HttpErrStr := _Msg('')+memo1.Lines.Strings[1]+'。';
@@ -14397,6 +14670,9 @@
     Panel6.Visible := True;
     Panel21.Visible := True;
     Panel23.Visible := True;
+
+    AttFileGB.Visible := True;
+    Splitter2.Visible := True;
     ScanDuplexCB.Visible := True; //雙面掃描
   end
   Else if FMode = 'FSCAN' then
@@ -14411,11 +14687,18 @@
     Panel6.Visible := True;
     Panel21.Visible := True;
     Panel23.Visible := True;
+    AttFileGB.Visible := True;
+    Splitter2.Visible := True;
   end;
   DisplayMode(1,1,1,Panel9);
   Application.ProcessMessages;
   StatusBar1.Panels[0].Text := 'Ver'+GetCurrentVersionNo;
-  StatusBar1.Panels[1].Text := _Msg('登入人員:')+FUserName;
+  StatusBar1.Panels[1].Text := 'Login User:'+FUserName;
+  {$IFDEF Test}
+    StatusBar1.Panels[0].Text := StatusBar1.Panels[0].Text+'(test)';
+  {$ENDIF}
+    StatusBar1.Panels[0].Text := StatusBar1.Panels[0].Text;
+
   if FPrintyn = 'Y' then
     PrtLB.Visible := True;
 
@@ -14423,11 +14706,24 @@
   InitScrollRec;
   If FUrl = '' then
   begin
-    Showmessage(_Msg('URL不能為空白,請洽詢程式人員'));
+    Showmessage(_Msg('URL cannot be empty,please contact system administrator'));
     Exit;
   end;
   if FUrl[length(FUrl)]<>'/' then
     FUrl := FUrl + '/';
+  //20221028 把語言檔改放至 Local目錄裡,才不會有些文字來不及使用
+  LngPath := GetLocalAppDir(Handle)+'MPS\CB_IMGPS\';
+  Str2Dir(LngPath);
+  ////下載語言檔/////  20170218 先拿調以便測試
+  If not DownLanguage Then
+  begin
+    Showmessage('Language File error!!'+HttpErrStr);
+    DataLoading(False,False);
+    Exit;
+  end;
+
+  InitialLanguage(Self);  //載入多國語言
+
 
   if FWork_no='' then
   begin
@@ -14462,6 +14758,7 @@
   CaseList := TStringList.Create;    //記錄掃瞄案件的順序
   Context_DocnoList := TStringlist.Create; //案件裡的檔案Docno清單
   ContextList := TStringlist.Create; //案件裡的檔案清單
+  AttContextList := TStringlist.Create; //案件裡的附加檔案清單
   NoSaveBarCodeList := TStringlist.Create; //不儲存的條碼清單
   FormID_List := TStringlist.Create;  //FormID清單
   DocNo_List := TStringlist.Create; //DocNo清單
@@ -14574,10 +14871,12 @@
   if ImagePath[Length(ImagePath)] <> '\' then
     ImagePath := ImagePath + '\';
 //ShowMessage('ImagePath='+ImagePath);
-  CheckXmlPath := ImagePath+'OMRSITE\'+FWork_No;
+  //CheckXmlPath := ImagePath+'OMRSITE\'+FWork_No;
+  CheckXmlPath := ImagePath+'OMRSITE\';  // 20200612 發現影像平台是取回所有業務的設定,所以不能有業務別目錄
 //ShowMessage('CheckXmlPath='+CheckXmlPath);
-  SitePath := ImagePath+'Site\'+FWork_No+'\';
-  LngPath := ImagePath;
+  //SitePath := ImagePath+'Site\'+FWork_No+'\';
+  SitePath := ImagePath+'Site\';  // 20200612 發現影像平台是取回所有業務的設定,所以不能有業務別目錄
+  //LngPath := ImagePath; //改放至上面取Local目錄
   SamplePath := ImagePath+'Sample\'+FWork_No+'\';
   ImagePath := ImagePath + 'Scantemp\';
 //ShowMessage('AA  ImagePath='+ImagePath);
@@ -14616,15 +14915,8 @@
   ShowText := _Msg('資料載入中,請稍候');
   DataLoading(True,True);
 
-   ////下載語言檔/////  20170218 先拿調以便測試
-  If not DownLanguage Then
-  begin
-    Showmessage('Language File error!!'+HttpErrStr);
-    DataLoading(False,False);
-    Exit;
-  end;
 
-  InitialLanguage(Self);  //載入多國語言
+  StatusBar1.Panels[1].Text := _Msg('登入人員:')+FUserName;
   //FCaseID:='20150302180133';//測試用
   ////下載語言檔/////
 //ShowMessage('OOOO');
@@ -14833,7 +15125,6 @@
     CreateIn_WH(CaseID);    //產生入庫文件文字檔 In_Wh.dat
     Case2upload(CaseID);   //產生原影像結構
     TransPath := ImageSavePath+CaseID+'\Upload\';
-
     {if FMode = 'ESCAN' then    //20140320 yuu說拿掉此檢查
     begin
       S := TStringlist.Create;
@@ -14928,7 +15219,7 @@
   begin
     uploadMsg:=NowCaseNo+_Msg('影像上傳完成。此案已進入下一流程');
   end;
-  if (FMode='ESCAN') and (FModeName='補件掃描') and (SuccessCount = 1) then
+  if (FMode='ESCAN') and (FModeName=_Msg('補件掃描')) and (SuccessCount = 1) then
   begin
     uploadMsg:=NowCaseNo+_Msg('影像已補件完成');
   end;
@@ -14981,6 +15272,9 @@
   ClearCaseIndex;
   PageLv.Items.Clear;  //頁數清單
   //Panel18.Enabled:= False;
+  AttListBox.Items.Clear;
+  AddAttFileLB.Enabled := False;
+  DelAttFileLB.Enabled := False;
   UseOldCaseLb.Visible := False;
   PM107.Visible := False; //備註功能
   CaseHelpBtn.Visible := False; //檢核失敗原因鈕
@@ -15056,9 +15350,9 @@
       DisplayPath := ImageSavePath+NowCaseNo+'\';
 
       if GetUseCase('F',DisplayPath,NowDocDir) <> '' then
-        StatusBar1.Panels[2].Text := Format('從%s引用',[GetUseCase('F',DisplayPath,NowDocDir)]);
+        StatusBar1.Panels[2].Text := Format(_Msg('從%s引用'),[GetUseCase('F',DisplayPath,NowDocDir)]);
       if GetUseCase('T',DisplayPath,NowDocDir) <> '' then
-        StatusBar1.Panels[2].Text := Format('被%s引用',[GetUseCase('T',DisplayPath,NowDocDir)]);
+        StatusBar1.Panels[2].Text := Format(_Msg('被%s引用'),[GetUseCase('T',DisplayPath,NowDocDir)]);
       if FLoanDoc_Enable = 'Y' then
       begin
         AddCredit1RG.Enabled := True;
@@ -15132,9 +15426,9 @@
       DisplayPath := ImageSavePath+NowCaseNo+'\';
 
       if GetUseCase('F',DisplayPath,NowDocDir) <> '' then
-        StatusBar1.Panels[2].Text := Format('從%s引用',[GetUseCase('F',DisplayPath,NowDocDir)]);
+        StatusBar1.Panels[2].Text := Format(_Msg('從%s引用'),[GetUseCase('F',DisplayPath,NowDocDir)]);
       if GetUseCase('T',DisplayPath,NowDocDir) <> '' then
-        StatusBar1.Panels[2].Text := Format('被%s引用',[GetUseCase('T',DisplayPath,NowDocDir)]);
+        StatusBar1.Panels[2].Text := Format(_Msg('被%s引用'),[GetUseCase('T',DisplayPath,NowDocDir)]);
 
       if FLoanDoc_Enable = 'Y' then
       begin
@@ -15161,7 +15455,12 @@
       if FileExists(DisplayPath+'CustomDocNo.dat') then
         Cust_DocNoList.LoadFromFile(DisplayPath+'CustomDocNo.dat');
     end;
-     MyTreeNode1.Expand(True);
+    MyTreeNode1.Expand(True);
+    AddAttFileLB.Enabled := True;
+    if FileExists(DisplayPath+'ATTContext.dat') then
+    begin
+      LoadAttFile(NowCaseno);
+    end;
   end
   Else     //點在NewTreenode or MyTreenode1 上
   begin
@@ -15405,6 +15704,17 @@
 
 end;
 
+procedure TCB_IMGPSScanX.TreeView1MouseDown(Sender: TObject;
+  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  IF Button = TMouseButton(MbRight) Then
+  begin
+    MDown := True;
+    If TreeView1.GetNodeAt(X,Y) = nil then Exit;
+    TreeView1.Selected := TreeView1.GetNodeAt(X,Y);
+  end;
+end;
+
 procedure TCB_IMGPSScanX.TreeView1MouseEnter(Sender: TObject);
 begin
 TreeView1.SetFocus;
@@ -15424,9 +15734,13 @@
   IF Button = TMouseButton(MbRight) Then
   begin
     If TreeView1.GetNodeAt(X,Y) = nil then Exit;
-    TreeView1.Selected := TreeView1.GetNodeAt(X,Y);
-    TreeView1Click(self);
-    TreeView1.PopupMenu.Popup(Mouse.CursorPos.X ,Mouse.CursorPos.Y);
+    if MDown then
+    begin
+      TreeView1Click(self);
+      TreeView1.PopupMenu.Popup(Mouse.CursorPos.X ,Mouse.CursorPos.Y);
+    end;
+    Application.ProcessMessages; //需加這行,不然有些全域變數會沒變到
+    MDown:= False;
   end;
 end;
 
@@ -15825,14 +16139,22 @@
     OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
     tmApartment);
 
-  SetLicenseKey('5B4451E676A1D2976FBB0F3BB18341336AF114C80B5ABAE7F6926B1CAF671F44' +
+  {SetLicenseKey('5B4451E676A1D2976FBB0F3BB18341336AF114C80B5ABAE7F6926B1CAF671F44' +
   'BD2F098CCEDA922F6389BFAE398DA6AEE67F97EEA0C17234C20D75C12173DBDA' +
   '594924D56DD8E342F454389C836AD880BB4352CA3BE62C4933B1BA3828E7462C' +
   '60514F2ECDAD322E6128D841F12D24DA00B623106D3F08EBCAA917D8A97CAA34' +
   '3D65F2DA567316457395BF9123EE53DF235D181F191A5712DBB27735284AA92D' +
   '5DFA0C8308308505F384707E900C6063F53F1BFF4C6972607955D1AE517B19D0' +
   '82CDD16301885403AD229D57BAEF98C056F31430861E5F68F339D658D72E1F92' +
-  '63899412EC2D07891FE3AFD35F3E4A4390B2F0A8A1BF1B7D6160E5F1CC009B17');
+  '63899412EC2D07891FE3AFD35F3E4A4390B2F0A8A1BF1B7D6160E5F1CC009B17'); }
+  SetLicenseKey('4B2CF65E8C2A86CE8A0DD0F6A7DB03BC0B0126168B48AE4C27EBD78CAE75CF0F' +
+   'A612190861E0D99F6FAE3ED97AC1941B5E97843CFFCF705A3787989072D4EB2C' +
+   'AE6CAB3F5B69B86616ACC8A37AD6A2AB21C7BDD5C9AE1EDF9E4193D353805C9A' +
+   '403631CE8A3D0803FEBB1BE4C209CE7A63B1298EF080EB34B8628CED567D2B68' +
+   'E777FAC58E2E32B7411FC217A04336231D1E861A93474759DAA6EDF53F6EB632' +
+   'A3055229A52F3053FB844754741409022DDE3DFB19473510F2BE63328E74BE20' +
+   'A6A29AA24878F91ADA9DF8CE1F320AF4DAF58EBF95D9BE761D70EEA274E19475' +
+   '1C15948B184264C5C49E60493F3BCD2FFAE2CA8B021D00B96F45550C5F050D8A');
 
 
   SetLicenseKey('A6A94A8D91B08A9D58F300C0573EA9EF1B9DB0BF69B90E13B958DB4CB6B44F5A' +

--
Gitblit v1.8.0