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
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
{ ==============================================================================
  方法名稱:ReNameContext
  引用相依:SaveToFile
  方法描述:在指定路徑下執行影像清單的更名同步。遍歷 ContextList,比對舊檔名後更新
            為新檔名,同步更新 Context.dat 及對應的文件編號清單(Context_DocNo.dat
            )。
============================================================================== }
Procedure TCB_IMGPSScanX.ReNameContext(Path,OldName,NewName:String);
var
  i : Integer;
begin
  for i := 0 to ContextList.Count - 1 do
  begin
    if OldName = ContextList.Strings[i] then
    begin
      ContextList.Strings[i] := NewName;
      ContextList.SaveToFile(Path+'Context.dat');
      Context_DocnoList.Strings[i] := FormCode2DocNo(FileName2FormCode(NewName));
      Context_DocnoList.SaveToFile(Path+'Context_DocNo.dat');
      Break;
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:DeleteImageFile
  引用相依:DeleteImageFile, FileExists, LoadFromFile, SaveToFile
  方法描述:刪除指定的影像檔案。執行實體刪除後,自動計算文件目錄,並呼叫 SetContext
            List 從 Context 清單中移除對應的影像記錄。
============================================================================== }
Procedure TCB_IMGPSScanX.DeleteImageFile(Path,FileName,CaseID:String); // 刪除檔案  (無法得到DocDir用)
var
  i : Integer;
  FileList:TStringlist;
  DocDir : String;
begin
  
 
  DeleteFile(Path+FileName);
  DocDir := Path2DocDir(Path,CaseID);
//ShowMessage('DocDir='+DocDir);
  SetContextList('D',-1,CaseID,DocDir,FileName);
  {FileList:=TStringlist.Create;
  try
    if FileExists(Path+'Context.dat') then
      FileList.LoadFromFile(Path+'Context.dat');
    for i := 0 to FileList.Count - 1 do
    begin
      if FileName = FileList.Strings[i] then
      begin
        FileList.Delete(i);
        FileList.SaveToFile(Path+'Context.dat');
        Break;
      end;
    end;
    if FileList.Count = 0 then
      DeleteFile(Path+'Context.dat');
  finally
  FileList.Free;
  end;}
end;
 
 
{ ==============================================================================
  方法名稱:DeleteFormCodeFile
  引用相依:DeleteImageFile, FileExists, LoadFromFile, ReSortFileName, SaveToFil
            e
  方法描述:刪除案件中指定 FormID 的所有文件。讀取 Context.dat 並遍歷,若 FormID 
            匹配則執行刪除(在 ESCAN 模式下會檢查是否非當次掃瞄以保護舊圖)。刪除後
            執行檔案序號重新排序。
============================================================================== }
Procedure TCB_IMGPSScanX.DeleteFormCodeFile(CaseID,DocDir,FormID:String);  //刪除指定FormID文件
var
  i: Integer;
  FileList : TStringlist;
begin
  FileList := TStringlist.Create;
  try
    FileList.Clear;
    if FileExists(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat') then
      FileList.LoadFromFile(ImageSavePath+CaseID+'\'+DocDir+'\Context.dat');
 
    for i := FileList.Count - 1 downto 0 do
    begin
      if FileName2FormCode(FileList.Strings[i]) = FormID then
      begin
        if (FMode = 'ESCAN') and (FModeName<>_Msg('異動件')) then
        begin
          if ISExistImg(ImageSavePath+CaseID+'\'+DocDir+'\'+FileList.Strings[i]) then
          begin
            //ShowMessage('有圖為非當次掃瞄,不可刪除');
            Break;
          end;
        end;
//ShowMessage(FileList.Strings[i]);
        DeleteImageFile(ImageSavePath+CaseID+'\'+DocDir+'\',FileList.Strings[i],CaseID);
      end;
    end;
  finally
  FileList.Free;
  end;
  ReSortFileName(ImageSavePath+CaseID+'\'+DocDir+'\');
  {for i := ContextList.Count - 1 downto 0 do
  begin
    FName := ContextList.Strings[i];
    if FormID = 'Err' then  //刪未註冊文件
    begin
      If not FormIDExists(FileName2FormCode(FName),False,0) Then
      begin
        DeleteFile(Path+FName);
        ContextList.Delete(i);
      end;
    end
    Else
    begin
      If FormID = FileName2FormCode(FName) then
      begin
        DeleteFile(Path+FName);
        ContextList.Delete(i);
      end;
    end;
  end;
  ContextList.SaveToFile(Path+'Context.dat');
  ReSortFileName(Path); }
end;
 
 
{ ==============================================================================
  方法名稱:DeleteDocNoFile
  引用相依:DeleteDocNoFile, FileExists, LoadFromFile, ReSortFileName, SaveToFil
            e
  方法描述:刪除指定的文件編號(DocNo)影像。遍歷 ContextList,比對文件編號後執行實
            體刪除與清單移除(含 Context 與 Context_DocNo)。處理完成後執行檔案重新
            排序並重新載入清單。
============================================================================== }
Function TCB_IMGPSScanX.DeleteDocNoFile(Path,DocNo:String):Boolean;  //刪除指定DocNo文件
var
  i: Integer;
  FName : String;
begin
  Result := False;
  for i := ContextList.Count - 1 downto 0 do
  begin
    FName := ContextList.Strings[i];
    If DocNo = FormCode2DocNo(FileName2FormCode(FName)) then
    begin
      DeleteFile(Path+FName);
      ContextList.Delete(i);
      Context_DocnoList.Delete(i);
      Result := True; //有刪到指定文件
    end;
  end;
  ContextList.SaveToFile(Path+'Context.dat');
  Context_DocnoList.SaveToFile(Path+'Context_DocNo.dat');
  ReSortFileName(Path);
  ContextList.LoadFromFile(Path+'Context.dat');
  Context_DocnoList.LoadFromFile(Path+'Context_DocNo.dat');
  if FileExists(Path+'CustomDocNo.dat') then
    Cust_DocNoList.LoadFromFile(Path+'CustomDocNo.dat');
end;
 
 
{ ==============================================================================
  方法名稱:DeleteDocNoFileForESCAN
  引用相依:DeleteDocNoFile, LoadFromFile, SaveToFile, _DelTree
  方法描述:在補件模式 (ESCAN) 下刪除屬於特定文件類型 (DocNo) 的影像。方法會從索
            引清單 (ContextList) 的末尾開始向前遍歷,識別符合目標文件編號或附件名
            稱的圖檔。若該檔案並非預先存在的(ISExistImg 返回 False),則執行實體刪
            除並從索引清單中移除。若整個文件目錄因此清空,則會進一步移除該目錄並從
            文件清單中刪除紀錄。
============================================================================== }
Function TCB_IMGPSScanX.DeleteDocNoFileForESCAN(Path,DocNo:String):Boolean;  //刪除指定DocNo文件
var
  i,j,k: Integer;
  FName : String;
  ST1,ST2,ST3:TStringList;
 
begin
 
  Result := False;
//ShowMessage(DocNo);
  for i := ContextList.Count - 1 downto 0 do
  begin
    FName := ContextList.Strings[i];
    If (DocNo = FormCode2DocNo(FileName2FormCode(FName))) or (DocNo=AttName) then
    begin
      if not ISExistImg(Path+'\'+FName) then
      begin
        DeleteFile(Path+'\'+FName);
        ContextList.Delete(i);
      end;
      Result := True; //有刪到指定文件
    end;
  end;
  ContextList.SaveToFile(Path+'\Context.dat');
  ContextList.LoadFromFile(Path+'\Context.dat');
 
  if ContextList.Count=0 then
  begin
    _DelTree(Path);
    SetDocNoList('D',-1,NowCaseNo,NowDocDir,'');
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:DeleteShowFile
  引用相依:DeleteShowFile
  方法描述:刪除當前顯示清單(NowShowFileList)中的影像檔案並更新索引。
============================================================================== }
Procedure TCB_IMGPSScanX.DeleteShowFile(Path:String); //刪除顯示中的影像
var
  i : Integer;
  DelFile : String;
begin
  for i := 0 to NowShowFileList.Count - 1 do
  begin
    DelFile := NowShowFileList.Strings[i];
    DeleteFile(Path+DelFile);
    SetContextList('D',-1,NowCaseno,NowDocNo,DelFile);
  end;
 
end;
 
 
{ ==============================================================================
  方法名稱:DeleteCustomDocDir
  引用相依:
  方法描述:從 CustomDocNo.ini 中刪除指定的自定義文件區段。
============================================================================== }
Procedure TCB_IMGPSScanX.DeleteCustomDocDir(Path,DocNo:String); //刪除自定文件DocNo
var
  ini : Tinifile;
begin
  ini := Tinifile.Create(Path+'CustomDocNo.ini');
  try
    ini.EraseSection(DocNo);
  finally
  ini.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ReSortFileName
  引用相依:FileExists, LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:執行影像檔案名稱的重新排序與更名。讀取目錄下的 Context.dat,根據目前的
            排列順序為每個檔案產生新的三位數序號前綴,並呼叫 ReNameFile 執行磁碟
            更名,最後同步更新清單內容並儲存。
============================================================================== }
Procedure TCB_IMGPSScanX.ReSortFileName(Path:String); //檔名重新排序
var
  i : Integer;
  OldName,NewName : String;
  Filelist : TStringlist;
begin
  Filelist := TStringlist.Create;
  try
    if FileExists(Path+'Context.dat') then
    begin
      Filelist.LoadFromFile(Path+'Context.dat');
      for i := 0 to Filelist.Count - 1 do
      begin
        OldName := Filelist.Strings[i];
        //NewName := Add_Zoo(i+1,3)+Copy(OldName,4,length(OldName)-3);
        NewName := Add_Zoo(i+1,3)+FileName2NoQuene_Filename(OldName);
//ShowMessage(OldName+#10#13+NewName);
        ReNameFile(Path+OldName,Path+NewName);
        Filelist.Strings[i] := NewName;
      end;
      Filelist.SaveToFile(Path+'Context.dat');
      ContextList.LoadFromFile(Path+'Context.dat');
    end;
  finally
  Filelist.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ReSortFileName_New
  引用相依:FileExists, LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:與 ReSortFileName 類似,執行影像檔案名稱的重新排序,但採用從清單末尾向
            前遍歷的方式執行更名與儲存。
============================================================================== }
Procedure TCB_IMGPSScanX.ReSortFileName_New(Path:String); //檔名重新排序
var
  i : Integer;
  OldName,NewName : String;
  Filelist : TStringlist;
begin
  Filelist := TStringlist.Create;
  try
    if FileExists(Path+'Context.dat') then
    begin
      Filelist.LoadFromFile(Path+'Context.dat');
      for i := Filelist.Count - 1 downto 0 do
      begin
        OldName := Filelist.Strings[i];
        //NewName := Add_Zoo(i+1,3)+Copy(OldName,4,length(OldName)-3);
        NewName := Add_Zoo(i+1,3)+FileName2NoQuene_Filename(OldName);
        ReNameFile(Path+OldName,Path+NewName);
        Filelist.Strings[i] := NewName;
      end;
      Filelist.SaveToFile(Path+'Context.dat');
      ContextList.LoadFromFile(Path+'Context.dat');
    end;
  finally
  Filelist.Free;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:ReSortFileName2Scanlist
  引用相依:FileExists, LoadFromFile, ReSortFileName, RenameFile, SaveToFile
  方法描述:針對 scanlist.dat 檔案內的影像路徑進行序號重排。讀取清單後,依序為檔案
            名稱加上新的序號前綴並存回。
============================================================================== }
Procedure TCB_IMGPSScanX.ReSortFileName2Scanlist(Path:String); //檔名重新排序給Scanlist.dat
var
  i : Integer;
  OldName,NewName : String;
  S : TStringlist;
begin
  S := TStringlist.Create;
  try
    if FileExists(Path+'scanlist.dat') then
      S.LoadFromFile(Path+'scanlist.dat');
    for i := 0 to S.Count - 1 do
    begin
      OldName := S.Strings[i];
      //NewName := Add_Zoo(i+1,3)+Copy(OldName,4,length(OldName)-3);
      NewName := Add_Zoo(i+1,3)+FileName2NoQuene_Filename(OldName);
      //ReNameFile(Path+OldName,Path+NewName);
      S.Strings[i] := NewName;
    end;
    S.SaveToFile(Path+'scanlist.dat');
  finally
  S.Free;
  end;
end;