curtis
13小時前 62c5adb8641e8626a056abc773b72449152d8ae9
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
{ ==============================================================================
  方法名稱: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
  引用相依:FileExists, LoadFromFile, MoveFile, RenameFile, SaveToFile
  方法描述:修正案件中歸類錯誤的表單代碼及其關聯檔案。邏輯如下:
            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;