{ ============================================================================== 方法名稱:OldCasetoNewCase 引用相依:LoadFromFile, SaveToFile 方法描述:將舊系統格式的案件文件份數轉換為新系統規則。方法會載入案件的文件目錄 清單 (CaseDocNo.dat),並解析由全域變數傳入的舊案文件編號與名稱清單(以 Tab 字串傳遞)。流程中會針對每個目錄編號統計其在舊資料中的出現次數,並 將統計後的份數結果更新至 CaseDocNo_Copies.dat 檔案中,以完成歷史資料 的規格對接。 ============================================================================== } Procedure TCB_IMGPSScanX.OldCasetoNewCase(CaseID:String); //將舊案份數轉成新規則 var i,n : Integer; C_DocNoList,C_DocNameList : TStringlist; DocNoList,DocNo_CopiesList : TStringlist; DocNo,DocName,DocDir : String; DocNo_Ct :integer; begin C_DocNoList := TStringlist.Create; C_DocNameList := TStringlist.Create; DocNoList := TStringlist.Create; DocNo_CopiesList := TStringlist.Create; try DocNoList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat'); for i := 0 to DocNoList.Count - 1 do begin DocNo_CopiesList.Add('0'); end; //Showmessage(FC_DocNoList); if FC_DocNoList <> '' then begin C_DocNoList.StrictDelimiter := True; C_DocNoList.Delimiter := #9; C_DocNoList.DelimitedText := FC_DocNoList; //showmessage(C_DocNoList.Text+#13+#13+DocNoList.Text); for i := 0 to DocNoList.Count - 1 do begin //DocNo := DocNoList.Strings[i]; DocNo := DocNoDir2DocNo(DocNoList.Strings[i]); //20140812 因轉舊案錯誤件會出現DocnoDir DocNo_Ct := 0; for n := 0 to C_DocNoList.Count - 1 do begin if DocNo = C_DocNoList.Strings[n] then inc(DocNo_Ct); end; if DocNo_CT > 0 Then DocNo_CopiesList.Strings[i] := inttostr(DocNo_CT); end; DocNo_CopiesList.SaveToFile(ImageSavePath+CaseID+'\CaseDocNo_Copies.dat'); end; if FC_DocNameList <> '' then begin C_DocNameList.StrictDelimiter := True; C_DocNameList.Delimiter := #9; C_DocNameList.DelimitedText := FC_DocNameList; for i := 0 to DocNoList.Count - 1 do begin DocNo := DocNoList.Strings[i]; DocNo_Ct := 0; for n := 0 to C_DocNameList.Count - 1 do begin if GetCustomDocName(ImageSavePath+CaseID+'\',DocNo) = C_DocNameList.Strings[n] then inc(DocNo_Ct); end; if DocNo_CT > 0 Then DocNo_CopiesList.Strings[i] :=inttostr(DocNo_CT); end; end; DocNo_CopiesList.SaveToFile(ImageSavePath+CaseID+'\CaseDocNo_Copies.dat'); finally C_DocNoList.Free; C_DocNameList.Free; DocNoList.Free; DocNo_CopiesList.Free; end; end; { ============================================================================== 方法名稱:ErrFormtoCurrentForm 引用相依:LoadFromFile, FileExists, RenameFile, SaveToFile, MoveFile 方法描述:修正案件中歸類錯誤的表單代碼及其關聯檔案。邏輯如下: 1. 取得錯誤與正確表單對應的文件編號。 2. 遍歷案件下的所有文件目錄,載入各目錄的影像索引檔 (Context.dat)。 3. 識別檔名中包含 EFormID 的影像,執行實體重新命名並更新索引。 4. 若該目錄編號與錯誤文件編號一致,則會執行 MoveFile 搬移整個目錄至新 路徑,並同步更新總文件清單 (CaseDocNo.dat),確保影像與分類資訊的一致性 。 ============================================================================== } Procedure TCB_IMGPSScanX.ErrFormtoCurrentForm(CaseID,EFormID,CFormID:String);//將舊案的錯誤FormID改正確的FormID var DocNoList,FileList :TStringlist; EDocNo,CDocNo,iDocNo,iFormID :String; EDocDir,CDocDir:String; OldFile,NewFile :String; iPath,iiPath : String; i,n : Integer; begin EDocNo := FormCode2DocNo(EFormID); CDocNo := FormCode2DocNo(CFormID); DocNoList :=TStringlist.Create; FileList := TStringlist.Create; try DocNoList.LoadFromFile(ImageSavePath+CaseID+'\CaseDocNo.dat'); for i := 0 to DocNoList.Count - 1 do begin EDocDir := DocNoList.Strings[i]; iDocNo := DocNoDir2DocNo(DocNoList.Strings[i]); iPath := ImageSavePath+CaseID+'\'+EDocDir+'\'; if FileExists(iPath+'Context.dat') then //20140909漏加這個判斷造成自訂文件但沒影像會出錯誤訊息 FileList.LoadFromFile(iPath+'Context.dat'); for n := 0 to FileList.Count - 1 do begin iFormID := FileName2FormCode(FileList.Strings[n]); if iFormID = EFormID then begin OldFile := FileList.Strings[n]; NewFile := StringReplace(FileList.Strings[n],iFormID,CFormID,[rfReplaceAll]); FileList.Strings[n] := NewFile; RenameFile(iPath+OldFile,iPath+NewFile); FileList.SaveToFile(iPath+'Context.dat'); end; end; if iDocNo = EDocNo then begin CDocDir := StringReplace(EDocDir,EDocNo,CDocNo,[rfReplaceAll]); iiPath := ImageSavePath+CaseID+'\'+CDocDir+'\'; MoveFile(PWideChar(iPath),PWideChar(iiPath)); DocNoList.Strings[i] := StringReplace(DocNoList.Strings[i],iDocNo,CDocNo,[rfReplaceAll]); DocNoList.SaveToFile(ImageSavePath+CaseID+'\CaseDocNo.dat'); //SetRecordEditedDocDir('A',CaseID,CDocNo); //20140918 yuu說改成不紀錄 end; end; finally DocNoList.Free; FileList.Free; end; end; { ============================================================================== 方法名稱:SetRecordEditedDocDir 引用相依:FileExists, LoadFromFile, SaveToFile 方法描述:記錄案件中曾被異動(新增或刪除)的文件目錄。將目錄名稱存入 EditedDocDir .dat,以便後續判斷哪些內容需要同步上傳或重新計算。 ============================================================================== } Procedure TCB_IMGPSScanX.SetRecordEditedDocDir(Mode:Char;CaseID,DocDir:String); //記錄被異動的文件目錄 'A:加入D:刪掉' var i : Integer; Exists : Boolean; EditedDocDirList : TStringlist; begin EditedDocDirList := TStringlist.Create; try if FileExists(ImageSavePath+CaseID+'\EditedDocDir.dat') then EditedDocDirList.LoadFromFile(ImageSavePath+CaseID+'\EditedDocDir.dat'); case Mode of 'A':begin Exists := False; for i := 0 to EditedDocDirList.Count - 1 do begin if EditedDocDirList.Strings[i]=DocDir then begin Exists := True; Break; end; end; if not Exists then begin EditedDocDirList.Add(DocDir); EditedDocDirList.SaveToFile(ImageSavePath+CaseID+'\EditedDocDir.dat'); end; end; 'D':begin for i := 0 to EditedDocDirList.Count - 1 do begin if EditedDocDirList.Strings[i] = DocDir then begin EditedDocDirList.Delete(i); if EditedDocDirList.Count > 0 then EditedDocDirList.SaveToFile(ImageSavePath+CaseID+'\EditedDocDir.dat') else DeleteFile(ImageSavePath+CaseID+'\EditedDocDir.dat'); Break; end; end; end; end; finally EditedDocDirList.Free; end; end;