curtis
14小時前 3af5c004b4f2d2005d22ee85dccc2c80a66b1556
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
{ ==============================================================================
  方法名稱: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;