1 | unit UCore;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, ExtCtrls, Controls, ActnList, Menus, UFioAPI,
|
---|
9 | URegistry, UApplicationInfo, UCoolTranslator, Registry, DateUtils, Forms,
|
---|
10 | Dialogs, SpecializedList, dom, XMLRead, XMLWrite;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TAccountOperation }
|
---|
15 |
|
---|
16 | TAccountOperation = class
|
---|
17 | Id: string;
|
---|
18 | Time: TDateTime;
|
---|
19 | Value: Double;
|
---|
20 | Account: string;
|
---|
21 | VarSym: string;
|
---|
22 | SpecSym: string;
|
---|
23 | ConstSym: string;
|
---|
24 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
25 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
26 | end;
|
---|
27 |
|
---|
28 | { TAccount }
|
---|
29 |
|
---|
30 | TAccount = class
|
---|
31 | Token: string;
|
---|
32 | Name: string;
|
---|
33 | Number: string;
|
---|
34 | BankCode: string;
|
---|
35 | Balance: Double;
|
---|
36 | Time: TDateTime;
|
---|
37 | Operations: TListObject;
|
---|
38 | procedure Assign(Source: TAccount);
|
---|
39 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
40 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
41 | constructor Create;
|
---|
42 | destructor Destroy; override;
|
---|
43 | end;
|
---|
44 |
|
---|
45 | { TAccountList }
|
---|
46 |
|
---|
47 | TAccountList = class(TListObject)
|
---|
48 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
49 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
50 | procedure LoadToStrings(Strings: TStrings);
|
---|
51 | procedure Assign(Source: TAccountList);
|
---|
52 | end;
|
---|
53 |
|
---|
54 | { TCore }
|
---|
55 |
|
---|
56 | TCore = class(TDataModule)
|
---|
57 | AAbout: TAction;
|
---|
58 | AAccounts: TAction;
|
---|
59 | ActionList1: TActionList;
|
---|
60 | ADownloadInterval: TAction;
|
---|
61 | ADownloadMonthly: TAction;
|
---|
62 | ADownloadNew: TAction;
|
---|
63 | AExit: TAction;
|
---|
64 | ApplicationInfo1: TApplicationInfo;
|
---|
65 | ASettings: TAction;
|
---|
66 | AShow: TAction;
|
---|
67 | CoolTranslator1: TCoolTranslator;
|
---|
68 | ImageList1: TImageList;
|
---|
69 | MenuItem1: TMenuItem;
|
---|
70 | MenuItem2: TMenuItem;
|
---|
71 | MenuItem3: TMenuItem;
|
---|
72 | MenuItem4: TMenuItem;
|
---|
73 | MenuItem5: TMenuItem;
|
---|
74 | MenuItem6: TMenuItem;
|
---|
75 | MenuItem7: TMenuItem;
|
---|
76 | MenuItem8: TMenuItem;
|
---|
77 | MenuItem9: TMenuItem;
|
---|
78 | PopupMenuTray: TPopupMenu;
|
---|
79 | TrayIcon1: TTrayIcon;
|
---|
80 | procedure AAccountsExecute(Sender: TObject);
|
---|
81 | procedure ADownloadIntervalExecute(Sender: TObject);
|
---|
82 | procedure ADownloadMonthlyExecute(Sender: TObject);
|
---|
83 | procedure ADownloadNewExecute(Sender: TObject);
|
---|
84 | procedure AExitExecute(Sender: TObject);
|
---|
85 | procedure ASettingsExecute(Sender: TObject);
|
---|
86 | procedure AShowExecute(Sender: TObject);
|
---|
87 | procedure AAboutExecute(Sender: TObject);
|
---|
88 | procedure DataModuleCreate(Sender: TObject);
|
---|
89 | procedure DataModuleDestroy(Sender: TObject);
|
---|
90 | private
|
---|
91 | function GetFileName: string;
|
---|
92 | public
|
---|
93 | RegistryContext: TRegistryContext;
|
---|
94 | Accounts: TAccountList;
|
---|
95 | CurrentAccount: TAccount;
|
---|
96 | DataFormat: TFioDataFormat;
|
---|
97 | TargetDirectory: string;
|
---|
98 | ReportYear: Integer;
|
---|
99 | ReportId: Integer;
|
---|
100 | ReportTimeFrom: TDateTime;
|
---|
101 | ReportTimeTo: TDateTime;
|
---|
102 | OutputFormat: string;
|
---|
103 | SelectedAccountIndex: Integer;
|
---|
104 | procedure LoadAccount(Account: TAccount);
|
---|
105 | procedure LoadAccounts;
|
---|
106 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
107 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
108 | end;
|
---|
109 |
|
---|
110 | var
|
---|
111 | Core: TCore;
|
---|
112 |
|
---|
113 | implementation
|
---|
114 |
|
---|
115 | {$R *.lfm}
|
---|
116 |
|
---|
117 | uses
|
---|
118 | UFormAbout, UFormMain, UFormSettings, UFormAccounts;
|
---|
119 |
|
---|
120 | resourcestring
|
---|
121 | SDownloadNotSuccess = 'Download failed';
|
---|
122 | SReport = 'Dump %s';
|
---|
123 | SSavedToFile = 'Dump saved to file %s';
|
---|
124 | SDumpFormat = 'Dump %d %t.%f';
|
---|
125 |
|
---|
126 | { TAccountOperation }
|
---|
127 |
|
---|
128 | procedure TAccountOperation.LoadFromRegistry(Context: TRegistryContext);
|
---|
129 | begin
|
---|
130 | with TRegistryEx.Create do
|
---|
131 | try
|
---|
132 | RootKey := Context.RootKey;
|
---|
133 | OpenKey(Context.Key, True);
|
---|
134 | Id := UTF8Encode(ReadStringWithDefault('Id', UTF8Decode('')));
|
---|
135 | Time := ReadDateTimeWithDefault('Time', 0);
|
---|
136 | Value := ReadFloatWithDefault('Value', 0);
|
---|
137 | Account := UTF8Encode(ReadStringWithDefault('Account', UTF8Decode('')));
|
---|
138 | VarSym := UTF8Encode(ReadStringWithDefault('VarSym', UTF8Decode('')));
|
---|
139 | SpecSym := UTF8Encode(ReadStringWithDefault('SpecSym', UTF8Decode('')));
|
---|
140 | ConstSym := UTF8Encode(ReadStringWithDefault('ConstSym', UTF8Decode('')));
|
---|
141 | finally
|
---|
142 | Free;
|
---|
143 | end;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TAccountOperation.SaveToRegistry(Context: TRegistryContext);
|
---|
147 | begin
|
---|
148 | with TRegistryEx.Create do
|
---|
149 | try
|
---|
150 | RootKey := Context.RootKey;
|
---|
151 | OpenKey(Context.Key, True);
|
---|
152 | WriteString('Id', UTF8Decode(Id));
|
---|
153 | WriteString('Account', UTF8Decode(Account));
|
---|
154 | WriteDateTime('Time', Time);
|
---|
155 | WriteFloat('Value', Value);
|
---|
156 | WriteString('VarSym', UTF8Decode(VarSym));
|
---|
157 | WriteString('SpecSym', UTF8Decode(SpecSym));
|
---|
158 | WriteString('ConstSym', UTF8Decode(ConstSym));
|
---|
159 | finally
|
---|
160 | Free;
|
---|
161 | end;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | { TAccount }
|
---|
165 |
|
---|
166 | procedure TAccount.Assign(Source: TAccount);
|
---|
167 | begin
|
---|
168 | Token := Source.Token;
|
---|
169 | Name := Source.Name;
|
---|
170 | Balance := Source.Balance;
|
---|
171 | Time := Source.Time;
|
---|
172 | Number := Source.Number;
|
---|
173 | BankCode := Source.BankCode;
|
---|
174 | //Operations.Assign(Source.Operations);
|
---|
175 | end;
|
---|
176 |
|
---|
177 | procedure TAccount.LoadFromRegistry(Context: TRegistryContext);
|
---|
178 | var
|
---|
179 | I: Integer;
|
---|
180 | begin
|
---|
181 | with TRegistryEx.Create do
|
---|
182 | try
|
---|
183 | RootKey := Context.RootKey;
|
---|
184 | OpenKey(Context.Key, True);
|
---|
185 | Name := UTF8Encode(ReadStringWithDefault('Name', UTF8Decode('UÄet')));
|
---|
186 | Time := ReadDateTimeWithDefault('Time', 0);
|
---|
187 | Token := UTF8Encode(ReadStringWithDefault('Token', ''));
|
---|
188 | Balance := ReadFloatWithDefault('Balance', 0);
|
---|
189 | Number := UTF8Encode(ReadStringWithDefault('Number', ''));
|
---|
190 | BankCode := UTF8Encode(ReadStringWithDefault('BankCode', ''));
|
---|
191 | finally
|
---|
192 | Free;
|
---|
193 | end;
|
---|
194 | with Operations do
|
---|
195 | for I := 0 to Count - 1 do begin
|
---|
196 | if not Assigned(Items[I]) then Items[I] := TAccountOperation.Create;
|
---|
197 | TAccountOperation(Items[I]).LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I)));
|
---|
198 | end;
|
---|
199 | end;
|
---|
200 |
|
---|
201 | procedure TAccount.SaveToRegistry(Context: TRegistryContext);
|
---|
202 | var
|
---|
203 | I: Integer;
|
---|
204 | begin
|
---|
205 | with TRegistryEx.Create do
|
---|
206 | try
|
---|
207 | RootKey := Context.RootKey;
|
---|
208 | OpenKey(Context.Key, True);
|
---|
209 | WriteString('Number', UTF8Decode(Number));
|
---|
210 | WriteString('Name', UTF8Decode(Name));
|
---|
211 | WriteDateTime('Time', Time);
|
---|
212 | WriteString('Token', UTF8Decode(Token));
|
---|
213 | WriteFloat('Balance', Balance);
|
---|
214 | WriteString('BankCode', UTF8Decode(BankCode));
|
---|
215 | finally
|
---|
216 | Free;
|
---|
217 | end;
|
---|
218 | with Operations do
|
---|
219 | for I := 0 to Count - 1 do
|
---|
220 | TAccountOperation(Items[I]).SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I)));
|
---|
221 | end;
|
---|
222 |
|
---|
223 | constructor TAccount.Create;
|
---|
224 | begin
|
---|
225 | Operations := TListObject.Create;
|
---|
226 | end;
|
---|
227 |
|
---|
228 | destructor TAccount.Destroy;
|
---|
229 | begin
|
---|
230 | Operations.Free;
|
---|
231 | inherited Destroy;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | { TAccountList }
|
---|
235 |
|
---|
236 | procedure TAccountList.LoadFromRegistry(Context: TRegistryContext);
|
---|
237 | var
|
---|
238 | I: Integer;
|
---|
239 | begin
|
---|
240 | with TRegistryEx.Create do
|
---|
241 | try
|
---|
242 | RootKey := Context.RootKey;
|
---|
243 | OpenKey(Context.Key, True);
|
---|
244 | Count := ReadIntegerWithDefault('Count', 0);
|
---|
245 | finally
|
---|
246 | Free;
|
---|
247 | end;
|
---|
248 | for I := 0 to Count - 1 do begin
|
---|
249 | if not Assigned(Items[I]) then Items[I] := TAccount.Create;
|
---|
250 | TAccount(Items[I]).LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I)));
|
---|
251 | end;
|
---|
252 | end;
|
---|
253 |
|
---|
254 | procedure TAccountList.SaveToRegistry(Context: TRegistryContext);
|
---|
255 | var
|
---|
256 | I: Integer;
|
---|
257 | begin
|
---|
258 | with TRegistryEx.Create do
|
---|
259 | try
|
---|
260 | RootKey := Context.RootKey;
|
---|
261 | OpenKey(Context.Key, True);
|
---|
262 | WriteInteger('Count', Count);
|
---|
263 | finally
|
---|
264 | Free;
|
---|
265 | end;
|
---|
266 | for I := 0 to Count - 1 do
|
---|
267 | TAccount(Items[I]).SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I)));
|
---|
268 | end;
|
---|
269 |
|
---|
270 | procedure TAccountList.LoadToStrings(Strings: TStrings);
|
---|
271 | var
|
---|
272 | I: Integer;
|
---|
273 | begin
|
---|
274 | while Strings.Count < Count do
|
---|
275 | Strings.Add('');
|
---|
276 | while Strings.Count > Count do
|
---|
277 | Strings.Delete(Strings.Count - 1);
|
---|
278 | for I := 0 to Count - 1 do begin
|
---|
279 | Strings.Strings[I] := IntToStr(I + 1) + ': ' + TAccount(Items[I]).Name + ' (' +
|
---|
280 | TAccount(Items[I]).Number + '/' + TAccount(Items[I]).BankCode + ')';
|
---|
281 | Strings.Objects[I] := Items[I];
|
---|
282 | end;
|
---|
283 | end;
|
---|
284 |
|
---|
285 | procedure TAccountList.Assign(Source: TAccountList);
|
---|
286 | var
|
---|
287 | I: Integer;
|
---|
288 | begin
|
---|
289 | //inherited Assign(Source);
|
---|
290 | Count := Source.Count;
|
---|
291 | for I := 0 to Count - 1 do begin
|
---|
292 | if not Assigned(Items[I]) then Items[I] := TAccount.Create;
|
---|
293 | TAccount(Items[I]).Assign(TAccount(Source.Items[I]));
|
---|
294 | end;
|
---|
295 | end;
|
---|
296 |
|
---|
297 | { TCore }
|
---|
298 |
|
---|
299 | procedure TCore.AShowExecute(Sender: TObject);
|
---|
300 | begin
|
---|
301 | Application.Restore;
|
---|
302 | end;
|
---|
303 |
|
---|
304 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
305 | begin
|
---|
306 | Accounts := TAccountList.Create;
|
---|
307 | RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
|
---|
308 | ApplicationInfo1.RegistryKey);
|
---|
309 | LoadFromRegistry(RegistryContext);
|
---|
310 | end;
|
---|
311 |
|
---|
312 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
313 | begin
|
---|
314 | SaveToRegistry(RegistryContext);
|
---|
315 | FreeAndNil(Accounts);
|
---|
316 | end;
|
---|
317 |
|
---|
318 | function TCore.GetFileName: string;
|
---|
319 | begin
|
---|
320 | Result := OutputFormat;
|
---|
321 | Result := StringReplace(Result, '%f', DataFormatURL[DataFormat], [rfReplaceAll]);
|
---|
322 | Result := StringReplace(Result, '%d', StringReplace(DateToStr(Now), '.', '-', [rfReplaceAll]), [rfReplaceAll]);
|
---|
323 | Result := StringReplace(Result, '%t', StringReplace(TimeToStr(Now),':', '-', [rfReplaceAll]), [rfReplaceAll]);
|
---|
324 | Result := StringReplace(Result, '%a', CurrentAccount.Number, [rfReplaceAll]);
|
---|
325 | Result := StringReplace(Result, '%n', CurrentAccount.Name, [rfReplaceAll]);
|
---|
326 | Result := StringReplace(Result, '%b', CurrentAccount.BankCode, [rfReplaceAll]);
|
---|
327 | Result := StringReplace(Result, '%%', '%', [rfReplaceAll]);
|
---|
328 | end;
|
---|
329 |
|
---|
330 | procedure TCore.LoadAccount(Account: TAccount);
|
---|
331 | var
|
---|
332 | FioAPI: TFioAPI;
|
---|
333 | List: TStringList;
|
---|
334 | FileName: string;
|
---|
335 | XMLDocument: TXMLDocument;
|
---|
336 | Mem: TMemoryStream;
|
---|
337 | RootNode: TDOMNode;
|
---|
338 | Node: TDOMNode;
|
---|
339 | Node2: TDOMNode;
|
---|
340 | begin
|
---|
341 | FioAPI := TFioAPI.Create;
|
---|
342 | List := TStringList.Create;
|
---|
343 | XMLDocument := TXMLDocument.Create;
|
---|
344 | Mem := TMemoryStream.Create;
|
---|
345 | try
|
---|
346 | FioAPI.Format := dfXML;
|
---|
347 | FioAPI.Token := Account.Token;
|
---|
348 | Account.Time := Now;
|
---|
349 | if FioAPI.DownloadInterval(Now, Now, List) then begin
|
---|
350 | List.SaveToStream(Mem);
|
---|
351 | Mem.Position := 0;
|
---|
352 | ReadXMLFile(XMLDocument, Mem);
|
---|
353 | RootNode := XMLDocument.DocumentElement;
|
---|
354 | Node := RootNode.FindNode('Info');
|
---|
355 | Node2 := Node.FindNode('accountId');
|
---|
356 | if Assigned(Node2) then
|
---|
357 | Account.Number := UTF8Encode(Node2.TextContent);
|
---|
358 | Node2 := Node.FindNode('bankId');
|
---|
359 | if Assigned(Node2) then
|
---|
360 | Account.BankCode := UTF8Encode(Node2.TextContent);
|
---|
361 | Node2 := Node.FindNode('closingBalance');
|
---|
362 | if Assigned(Node2) then
|
---|
363 | Account.Balance := StrToFloat(StringReplace(Node2.TextContent, '.',
|
---|
364 | DefaultFormatSettings.DecimalSeparator, [rfReplaceAll]));
|
---|
365 | end else begin
|
---|
366 | Account.BankCode := '';
|
---|
367 | Account.Number := '';
|
---|
368 | Account.Balance := 0;
|
---|
369 | end;
|
---|
370 | finally
|
---|
371 | Mem.Free;
|
---|
372 | XMLDocument.Free;
|
---|
373 | FioAPI.Free;
|
---|
374 | List.Free;
|
---|
375 | end;
|
---|
376 | end;
|
---|
377 |
|
---|
378 | procedure TCore.LoadAccounts;
|
---|
379 | var
|
---|
380 | I: Integer;
|
---|
381 | begin
|
---|
382 | for I := 0 to Accounts.Count - 1 do
|
---|
383 | LoadAccount(TAccount(Accounts[I]));
|
---|
384 | end;
|
---|
385 |
|
---|
386 | procedure TCore.AAboutExecute(Sender: TObject);
|
---|
387 | begin
|
---|
388 | FormAbout.ApplicationInfo := ApplicationInfo1;
|
---|
389 | FormAbout.ShowModal;
|
---|
390 | end;
|
---|
391 |
|
---|
392 | procedure TCore.SaveToRegistry(Context: TRegistryContext);
|
---|
393 | begin
|
---|
394 | with TRegistryEx.Create do
|
---|
395 | try
|
---|
396 | RootKey := Context.RootKey;
|
---|
397 | OpenKey(Context.Key, True);
|
---|
398 | WriteString('TargetDir', UTF8Decode(TargetDirectory));
|
---|
399 | WriteInteger('DataFormat', Integer(DataFormat));
|
---|
400 | WriteDate('ReportTimeFrom', ReportTimeFrom);
|
---|
401 | WriteDateTime('ReportTimeTo', ReportTimeTo);
|
---|
402 | WriteInteger('ReportYear', ReportYear);
|
---|
403 | WriteInteger('ReportId', ReportId);
|
---|
404 | WriteString('Language', CoolTranslator1.Language.Code);
|
---|
405 | WriteString('FileNameFormat', UTF8Decode(OutputFormat));
|
---|
406 | WriteInteger('SelectedAccountIndex', SelectedAccountIndex);
|
---|
407 | finally
|
---|
408 | Free;
|
---|
409 | end;
|
---|
410 | Accounts.SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\Account'));
|
---|
411 | end;
|
---|
412 |
|
---|
413 | procedure TCore.LoadFromRegistry(Context: TRegistryContext);
|
---|
414 | begin
|
---|
415 | with TRegistryEx.Create do
|
---|
416 | try
|
---|
417 | RootKey := Context.RootKey;
|
---|
418 | OpenKey(Context.Key, True);
|
---|
419 | TargetDirectory := UTF8Encode(ReadStringWithDefault('TargetDir', UTF8Decode(ExtractFileDir(Application.ExeName))));
|
---|
420 | DataFormat := TFioDataFormat(ReadIntegerWithDefault('DataFormat', Integer(dfXML)));
|
---|
421 | ReportTimeFrom := ReadDateTimeWithDefault('ReportTimeFrom', Now);
|
---|
422 | ReportTimeTo := ReadDateTimeWithDefault('ReportTimeTo', Now);
|
---|
423 | ReportYear := ReadIntegerWithDefault('ReportYear', YearOf(Now));
|
---|
424 | ReportId := ReadIntegerWithDefault('ReportId', MonthOf(Now));
|
---|
425 | CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('Language', ''));
|
---|
426 | OutputFormat := UTF8Encode(ReadStringWithDefault('FileNameFormat', UTF8Decode(SDumpFormat)));
|
---|
427 | SelectedAccountIndex := ReadIntegerWithDefault('SelectedAccountIndex', 0);
|
---|
428 | finally
|
---|
429 | Free;
|
---|
430 | end;
|
---|
431 | Accounts.LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\Account'));
|
---|
432 | end;
|
---|
433 |
|
---|
434 | procedure TCore.AExitExecute(Sender: TObject);
|
---|
435 | begin
|
---|
436 | Application.Terminate;
|
---|
437 | end;
|
---|
438 |
|
---|
439 | procedure TCore.ASettingsExecute(Sender: TObject);
|
---|
440 | begin
|
---|
441 | FormSettings.Load;
|
---|
442 | if FormSettings.ShowModal = mrOk then begin
|
---|
443 | FormSettings.Save;
|
---|
444 | SaveToRegistry(RegistryContext);
|
---|
445 | end;
|
---|
446 | end;
|
---|
447 |
|
---|
448 | procedure TCore.ADownloadNewExecute(Sender: TObject);
|
---|
449 | var
|
---|
450 | FioAPI: TFioAPI;
|
---|
451 | List: TStringList;
|
---|
452 | FileName: string;
|
---|
453 | begin
|
---|
454 | FioAPI := TFioAPI.Create;
|
---|
455 | List := TStringList.Create;
|
---|
456 | try
|
---|
457 | FioAPI.Format := DataFormat;
|
---|
458 | FioAPI.Token := CurrentAccount.Token;
|
---|
459 | if FioAPI.DownloadLast(List) then begin
|
---|
460 | FileName := TargetDirectory + DirectorySeparator + GetFileName;
|
---|
461 | List.SaveToFile(UTF8Decode(FileName));
|
---|
462 | ShowMessage(Format(SSavedToFile, [FileName]));
|
---|
463 | end else ShowMessage(SDownloadNotSuccess);
|
---|
464 | finally
|
---|
465 | FioAPI.Free;
|
---|
466 | List.Free;
|
---|
467 | end;
|
---|
468 | end;
|
---|
469 |
|
---|
470 | procedure TCore.ADownloadMonthlyExecute(Sender: TObject);
|
---|
471 | var
|
---|
472 | FioAPI: TFioAPI;
|
---|
473 | List: TStringList;
|
---|
474 | FileName: string;
|
---|
475 | begin
|
---|
476 | FioAPI := TFioAPI.Create;
|
---|
477 | List := TStringList.Create;
|
---|
478 | try
|
---|
479 | FioAPI.Format := DataFormat;
|
---|
480 | FioAPI.Token := CurrentAccount.Token;
|
---|
481 | if FioAPI.DownloadMonthly(ReportYear, ReportId, List) then begin
|
---|
482 | FileName := TargetDirectory + DirectorySeparator + GetFileName;
|
---|
483 | List.SaveToFile(UTF8Decode(FileName));
|
---|
484 | ShowMessage(Format(SSavedToFile, [FileName]));
|
---|
485 | end else ShowMessage(SDownloadNotSuccess);
|
---|
486 | finally
|
---|
487 | FioAPI.Free;
|
---|
488 | List.Free;
|
---|
489 | end;
|
---|
490 | end;
|
---|
491 |
|
---|
492 | procedure TCore.ADownloadIntervalExecute(Sender: TObject);
|
---|
493 | var
|
---|
494 | FioAPI: TFioAPI;
|
---|
495 | List: TStringList;
|
---|
496 | FileName: string;
|
---|
497 | begin
|
---|
498 | FioAPI := TFioAPI.Create;
|
---|
499 | List := TStringList.Create;
|
---|
500 | try
|
---|
501 | FioAPI.Format := DataFormat;
|
---|
502 | FioAPI.Token := CurrentAccount.Token;
|
---|
503 | if FioAPI.DownloadInterval(ReportTimeFrom, ReportTimeTo, List) then begin
|
---|
504 | FileName := TargetDirectory + DirectorySeparator + GetFileName;
|
---|
505 | List.SaveToFile(UTF8Decode(FileName));
|
---|
506 | ShowMessage(Format(SSavedToFile, [FileName]));
|
---|
507 | end else ShowMessage(SDownloadNotSuccess);
|
---|
508 | finally
|
---|
509 | FioAPI.Free;
|
---|
510 | List.Free;
|
---|
511 | end;
|
---|
512 | end;
|
---|
513 |
|
---|
514 | procedure TCore.AAccountsExecute(Sender: TObject);
|
---|
515 | begin
|
---|
516 | TAccountList(FormAccounts.Accounts).Assign(Accounts);
|
---|
517 | if FormAccounts.ShowModal = mrOk then begin
|
---|
518 | Accounts.Assign(TAccountList(FormAccounts.Accounts));
|
---|
519 | end;
|
---|
520 | end;
|
---|
521 |
|
---|
522 | end.
|
---|
523 |
|
---|