From 0756bf12d10cf1b7f78c571de0a9ad69cbaeb7ca Mon Sep 17 00:00:00 2001
From: curtis <curtis@i-mps.com>
Date: 星期一, 30 三月 2026 14:24:17 +0800
Subject: [PATCH] fix: 更新內部引用方法參照

---
 reassemble/CB_IMGPSScanImp.custdoc.pas |  332 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 332 insertions(+), 0 deletions(-)

diff --git a/reassemble/CB_IMGPSScanImp.custdoc.pas b/reassemble/CB_IMGPSScanImp.custdoc.pas
new file mode 100644
index 0000000..7da4bd4
--- /dev/null
+++ b/reassemble/CB_IMGPSScanImp.custdoc.pas
@@ -0,0 +1,332 @@
+{ ==============================================================================
+  方法名稱:GetNewCustomDocNo
+  引用相依:FileExists, LoadFromFile, SaveToFile
+  方法描述:產生一個全新的自定義文件編號。讀取 CustomDocNo.ini 中的計數器,根據入
+            庫/非入庫性質產生 ZZZZZ 或 YYYYY 開頭的編號,並預設其內部的第一個表單
+            代碼,最後將新設定寫回 INI 檔。
+============================================================================== }
+Function TCB_IMGPSScanX.GetNewCustomDocNo(Path,DocName:String):String; //取出未使用的自訂文件代號
+var
+  ini : Tinifile;
+  Ct:Integer;
+  DocNo,FormID : String;
+
+  {i,n,v,ln : Integer;
+  C_No,C_Name : String;
+  CNo : Integer;
+  S : TStringlist;
+  NewDocNo : String;}
+begin
+  ini := Tinifile.Create(Path+'CustomDocNo.ini');
+  try
+    Ct := ini.ReadInteger('CustomCount','Count',0);
+    inc(Ct);
+    DocNo := 'ZZZZZ'+Add_Zoo(Ct,3);
+    if FIs_In_Wh <> 'Y' then //不是入庫文件
+      DocNo := 'YYYYY'+Add_Zoo(Ct,3);
+
+    if (FMode='ESCAN') and (FWH_category='N')  then //20170914 補件下改成非入庫的自定文件
+    begin
+      DocNo := 'YYYYY'+Add_Zoo(Ct,3);
+    end;
+
+    FormID := DocNo+'010101A';
+    ini.WriteInteger('CustomCount','Count',Ct);
+    ini.WriteString(DocNo,'FormID',FormID);
+    ini.WriteString(DocNo,'Name',DocName);
+    Result := DocNo;
+  finally
+  ini.Free;
+  end;
+
+  {S := TStringlist.Create;
+  try
+  NewDocNo :='ZZZZZ001';
+  if FileExists(Path+'CustomDocNo.dat') then
+  begin
+    ///   ZZZZZ001_自定文件名稱  001_自定文件名稱
+    S.LoadFromFile(Path+'CustomDocNo.dat');
+    for i := 0 to S.Count - 1 do
+    begin
+      v := Pos('_',S.Strings[i]);
+      ln := Length(S.Strings[i]);
+      C_No := Copy(S.Strings[i],1,v-1);
+      C_Name := Copy(S.Strings[i],v+1,ln-v);
+      if DocName = C_Name then
+      begin
+        Showmessage('文件名稱已存在');
+        Result := '';
+        Exit;
+      end;
+    end;
+    CNo := strtoint(Copy(C_No,6,3))+1;
+    NewDocNo := 'ZZZZZ'+Add_Zoo(CNo,3);
+  end;
+  S.Add(NewDocNo+'_'+DocName);
+  S.SaveToFile(Path+'CustomDocNo.dat');
+  Result := NewDocNo;
+  finally
+  S.Free;
+  end; }
+end;
+
+
+{ ==============================================================================
+  方法名稱:GetCustomDocName
+  引用相依:
+  方法描述:從 CustomDocNo.ini 中讀取指定自定義文件編號對應的顯示名稱。
+============================================================================== }
+Function TCB_IMGPSScanX.GetCustomDocName(Path,DocNo:String):String; //取出自定文件名稱
+var
+  ini : Tinifile;
+begin
+  ini := Tinifile.Create(Path+'CustomDocNo.ini');
+  try
+    Result := ini.ReadString(DocNo,'Name','');
+  finally
+  ini.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:GetCustomFormID
+  引用相依:
+  方法描述:從 CustomDocNo.ini 中讀取指定自定義文件編號對應的表單代碼(FormID)。
+============================================================================== }
+Function TCB_IMGPSScanX.GetCustomFormID(Path,DocNo:String):String; //取出自定文件FormID
+var
+  ini : Tinifile;
+begin
+  ini := Tinifile.Create(Path+'CustomDocNo.ini');
+  try
+    Result := ini.ReadString(DocNo,'FormID','');
+  finally
+  ini.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:GetCustomDocDir
+  引用相依:
+  方法描述:根據自定義文件名稱尋找對應的目錄代號(如 ZZZZZ001)。遍歷 CustomDocNo.i
+            ni 中的所有區段,讀取 Name 欄位進行比對,成功則回傳該編號。
+============================================================================== }
+Function TCB_IMGPSScanX.GetCustomDocDir(Path,DocName:String):String; //取出自定文件DocDir
+var
+  i,ct:integer;
+  ini : Tinifile;
+begin
+  Result := '';
+  ini := Tinifile.Create(Path+'CustomDocNo.ini');
+  try
+    ct := ini.ReadInteger('CustomCount','Count',0);
+    for i := 1 to ct do
+    begin
+      if ini.ReadString('ZZZZZ'+Add_Zoo(i,3),'Name','') = DocName then
+      begin
+        Result := 'ZZZZZ'+Add_Zoo(i,3);
+        Break;
+      end;
+      if ini.ReadString('YYYYY'+Add_Zoo(i,3),'Name','') = DocName then
+      begin
+        Result := 'YYYYY'+Add_Zoo(i,3);
+        Break;
+      end;
+    end;
+  finally
+  ini.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:FindCustomDocName
+  引用相依:
+  方法描述:檢查指定的自定義文件名稱是否已存在於 CustomDocNo.ini 設定檔中。
+============================================================================== }
+Function TCB_IMGPSScanX.FindCustomDocName(Path,DocName:String):Boolean; //尋找自定文件名稱是否存在
+var
+  ini : Tinifile;
+  Ct,i:Integer;
+  DocNo,FormID : String;
+begin
+  Result := False;
+  ini := Tinifile.Create(Path+'CustomDocNo.ini');
+  try
+    Ct := ini.ReadInteger('CustomCount','Count',0);
+    for I := 1 to Ct do
+    begin
+      DocNo := 'ZZZZZ'+Add_Zoo(i,3);
+      if DocName = ini.ReadString(DocNo,'Name','') then
+      begin
+        Result := True;
+        Break;
+      end;
+    end;
+  finally
+  ini.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:Create_Cust_DocDir
+  引用相依:DirectoryExists
+  方法描述:根據外部傳入的清單(FC_DocNoList 或 FC_DocNameList)預先產生案件所需的
+            文件目錄。會自動處理分份文件的命名、檢查是否已存在,並在 CustomDocNo.in
+            i 中註冊新名稱。
+============================================================================== }
+Procedure TCB_IMGPSScanX.Create_Cust_DocDir(CaseID:String); //產生外面傳入的文件代號及自定文件
+var
+  i,n : Integer;
+  C_DocNoList,C_DocNameList : TStringlist;
+  DocNo,DocName,DocDir : String;
+  DocNo_Ct,NowDocNo_Ct :integer;
+  DocName_Ct : Integer;
+  inx : Integer;
+begin
+  C_DocNoList := TStringlist.Create;
+  C_DocNameList := TStringlist.Create;
+  try
+
+    if FC_DocNoList <> '' then
+    begin
+      C_DocNoList.StrictDelimiter := True;
+      C_DocNoList.Delimiter := #9;
+      C_DocNoList.DelimitedText := FC_DocNoList;
+      //Showmessage(C_DocNoList.Text);
+      for i := 0 to C_DocNoList.Count - 1 do
+      begin
+        DocNo := C_DocNoList.Strings[i];
+        //舊件不長出錯誤的文件出來
+        if (FIs_OldCase = 'Y') and (FWork_no='HLN') and (DocNo = FormCode2DocNo('10000001011112A')) then
+          Continue;
+        NowDocNo_Ct := GetDocNoCount(CaseID,DocNo);
+        if DocNoNeedDiv(DocNo) then
+        begin
+          DocNo_Ct := 0;
+          for n := 0 to i do
+          begin
+            if C_DocNoList.Strings[n] = DocNo then
+              inc(DocNo_Ct);
+          end;
+          if DocNo_CT <= NowDocNo_Ct then
+            Continue;
+          if DirectoryExists(ImageSavePath+CaseID+'\'+DocNo+'('+inttostr(DocNo_Ct)+')') then  //存在了
+            Continue;
+          if (DocNo_Ct = 1) and DirectoryExists(ImageSavePath+CaseID+'\'+DocNo) then  //存在了  20140327加
+            Continue;
+          DocDir := DocNo2DocNoDir(ImageSavePath+CaseID+'\',DocNo)
+
+        end
+        else
+        begin
+          DocDir := DocNo;
+        end;
+        if not DirectoryExists(ImageSavePath+CaseID+'\'+DocDir) then
+        begin
+          MkDir(ImageSavePath+CaseID+'\'+DocDir);
+          SetDocNoList('A',-1,CaseID,DocDir,'1');
+        end;
+        if not DocNoNeedDiv(DocNo) then   //不分份的秀數
+          SetDocDirCopies(CaseID,DocNo,GetCustomDocNoCount(DocNo));
+
+      end;
+    end;
+    if FC_DocNameList <> '' then
+    begin
+      C_DocNameList.StrictDelimiter := True;
+      C_DocNameList.Delimiter := #9;
+      C_DocNameList.DelimitedText := FC_DocNameList;
+      //Showmessage(C_DocNameList.Text);
+      for i := 0 to C_DocNameList.Count - 1 do
+      begin
+        DocName := C_DocNameList.Strings[i];
+        DocName_Ct := GetCustomNameCount(DocName);
+        if not FindCustomDocName(ImageSavePath+CaseID+'\',DocName) then
+        begin
+          DocDir := GetNewCustomDocNo(ImageSavePath+CaseID+'\',DocName);
+          if not DirectoryExists(ImageSavePath+CaseID+'\'+DocDir) then
+          begin
+            MkDir(ImageSavePath+CaseID+'\'+DocDir);
+            SetDocNoList('A',-1,CaseID,DocDir,inttostr(DocName_Ct));
+          end;
+        end
+        Else
+        begin
+          DocDir := GetCustomDocDir(ImageSavePath+CaseID+'\',DocName);
+          //inx := DocNoDir2Index(ImageSavePath+CaseID+'\',DocDir);
+          SetDocDirCopies(CaseID,DocDir,DocName_Ct);
+        end;
+      end;
+    end;
+
+  finally
+  C_DocNoList.Free;
+  C_DocNameList.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:GetCustomNameCount
+  引用相依:
+  方法描述:統計外部傳入清單中,特定自定義文件名稱出現的次數。
+============================================================================== }
+Function TCB_IMGPSScanX.GetCustomNameCount(CustomName:String):Integer;   //取外傳的名稱數量
+var
+  i,ct : Integer;
+  C_DocNameList : TStringlist;
+begin
+  C_DocNameList := TStringlist.Create;
+  try
+    C_DocNameList.StrictDelimiter := True;
+    C_DocNameList.Delimiter := #9;
+    C_DocNameList.DelimitedText := FC_DocNameList;
+    ct := 0;
+    for i := 0 to C_DocNameList.Count - 1 do
+    begin
+      if C_DocNameList.Strings[i] = CustomName then
+      begin
+        inc(ct);
+      end;
+    end;
+    Result := ct;
+  finally
+  C_DocNameList.Free;
+  end;
+end;
+
+
+{ ==============================================================================
+  方法名稱:GetCustomDocNoCount
+  引用相依:
+  方法描述:統計外部傳入清單中,特定文件編號(DocNo)出現的次數。
+============================================================================== }
+Function TCB_IMGPSScanX.GetCustomDocNoCount(Docno:String):Integer;   //取外傳的DocNo數量
+var
+  i,ct : Integer;
+  C_DocNoList : TStringlist;
+begin
+  C_DocNoList := TStringlist.Create;
+  try
+    C_DocNoList.StrictDelimiter := True;
+    C_DocNoList.Delimiter := #9;
+    C_DocNoList.DelimitedText := FC_DocNoList;
+    ct := 0;
+    for i := 0 to C_DocNoList.Count - 1 do
+    begin
+      if C_DocNoList.Strings[i] = Docno then
+      begin
+        inc(ct);
+      end;
+    end;
+    Result := ct;
+  finally
+  C_DocNoList.Free;
+  end;
+end;
+
+

--
Gitblit v1.8.0