Changeset 12 for trunk/UCore.pas
- Timestamp:
- Mar 15, 2013, 11:42:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r11 r12 8 8 Classes, SysUtils, FileUtil, ExtCtrls, Controls, ActnList, Menus, UFioAPI, 9 9 URegistry, UApplicationInfo, UCoolTranslator, Registry, DateUtils, Forms, 10 Dialogs ;10 Dialogs, SpecializedList, dom, XMLRead, XMLWrite; 11 11 12 12 type 13 14 { TAccount } 15 16 TAccount = class 17 Token: string; 18 Name: string; 19 Number: string; 20 Balance: Double; 21 Time: TDateTime; 22 procedure Assign(Source: TAccount); 23 procedure LoadFromRegistry(Context: TRegistryContext); 24 procedure SaveToRegistry(Context: TRegistryContext); 25 end; 26 27 { TAccountList } 28 29 TAccountList = class(TListObject) 30 procedure LoadFromRegistry(Context: TRegistryContext); 31 procedure SaveToRegistry(Context: TRegistryContext); 32 procedure LoadToStrings(Strings: TStrings); 33 procedure Assign(Source: TAccountList); 34 end; 13 35 14 36 { TCore } … … 16 38 TCore = class(TDataModule) 17 39 AAbout: TAction; 40 AAccounts: TAction; 18 41 ActionList1: TActionList; 19 42 ADownloadInterval: TAction; … … 36 59 PopupMenuTray: TPopupMenu; 37 60 TrayIcon1: TTrayIcon; 61 procedure AAccountsExecute(Sender: TObject); 38 62 procedure ADownloadIntervalExecute(Sender: TObject); 39 63 procedure ADownloadMonthlyExecute(Sender: TObject); … … 49 73 public 50 74 RegistryContext: TRegistryContext; 51 Token: string; 75 Accounts: TAccountList; 76 CurrentAccount: TAccount; 52 77 DataFormat: TFioDataFormat; 53 78 TargetDirectory: string; … … 56 81 ReportTimeFrom: TDateTime; 57 82 ReportTimeTo: TDateTime; 83 procedure LoadAccount(Account: TAccount); 84 procedure LoadAccounts; 58 85 procedure SaveToRegistry(Context: TRegistryContext); 59 86 procedure LoadFromRegistry(Context: TRegistryContext); … … 68 95 69 96 uses 70 UFormAbout, UFormMain, UFormSettings ;97 UFormAbout, UFormMain, UFormSettings, UFormAccounts; 71 98 72 99 resourcestring … … 75 102 SSavedToFile = 'Dump saved to file %s'; 76 103 104 { TAccount } 105 106 procedure TAccount.Assign(Source: TAccount); 107 begin 108 Token := Source.Token; 109 Name := Source.Name; 110 Balance := Source.Balance; 111 Time := Source.Time; 112 Number := Source.Number; 113 end; 114 115 procedure TAccount.LoadFromRegistry(Context: TRegistryContext); 116 begin 117 with TRegistryEx.Create do 118 try 119 RootKey := Context.RootKey; 120 OpenKey(Context.Key, True); 121 Name := ReadStringWithDefault('Name', ''); 122 Time := ReadDateTimeWithDefault('Time', 0); 123 Token := ReadStringWithDefault('Token', ''); 124 Balance := ReadFloatWithDefault('Balance', 0); 125 Number := ReadStringWithDefault('Number', ''); 126 finally 127 Free; 128 end; 129 end; 130 131 procedure TAccount.SaveToRegistry(Context: TRegistryContext); 132 begin 133 with TRegistryEx.Create do 134 try 135 RootKey := Context.RootKey; 136 OpenKey(Context.Key, True); 137 WriteString('Number', Number); 138 WriteString('Name', Name); 139 WriteDateTime('Time', Time); 140 WriteString('Token', Token); 141 WriteFloat('Balance', Balance); 142 finally 143 Free; 144 end; 145 end; 146 147 { TAccountList } 148 149 procedure TAccountList.LoadFromRegistry(Context: TRegistryContext); 150 var 151 I: Integer; 152 begin 153 with TRegistryEx.Create do 154 try 155 RootKey := Context.RootKey; 156 OpenKey(Context.Key, True); 157 Count := ReadIntegerWithDefault('Count', 0); 158 finally 159 Free; 160 end; 161 for I := 0 to Count - 1 do begin 162 if not Assigned(Items[I]) then Items[I] := TAccount.Create; 163 TAccount(Items[I]).LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I))); 164 end; 165 end; 166 167 procedure TAccountList.SaveToRegistry(Context: TRegistryContext); 168 var 169 I: Integer; 170 begin 171 with TRegistryEx.Create do 172 try 173 RootKey := Context.RootKey; 174 OpenKey(Context.Key, True); 175 WriteInteger('Count', Count); 176 finally 177 Free; 178 end; 179 for I := 0 to Count - 1 do 180 TAccount(Items[I]).SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\' + IntToStr(I))); 181 end; 182 183 procedure TAccountList.LoadToStrings(Strings: TStrings); 184 var 185 I: Integer; 186 begin 187 while Strings.Count < Count do 188 Strings.Add(''); 189 while Strings.Count > Count do 190 Strings.Delete(Strings.Count - 1); 191 for I := 0 to Count - 1 do 192 Strings.Strings[I] := TAccount(Items[I]).Name; 193 end; 194 195 procedure TAccountList.Assign(Source: TAccountList); 196 var 197 I: Integer; 198 begin 199 //inherited Assign(Source); 200 Count := Source.Count; 201 for I := 0 to Count - 1 do begin 202 if not Assigned(Items[I]) then Items[I] := TAccount.Create; 203 TAccount(Items[I]).Assign(TAccount(Source.Items[I])); 204 end; 205 end; 206 77 207 { TCore } 78 208 … … 84 214 procedure TCore.DataModuleCreate(Sender: TObject); 85 215 begin 216 Accounts := TAccountList.Create; 86 217 RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot), 87 218 ApplicationInfo1.RegistryKey); 88 219 LoadFromRegistry(RegistryContext); 220 //LoadAccounts; 89 221 end; 90 222 … … 92 224 begin 93 225 SaveToRegistry(RegistryContext); 226 FreeAndNil(Accounts); 227 end; 228 229 procedure TCore.LoadAccount(Account: TAccount); 230 var 231 FioAPI: TFioAPI; 232 List: TStringList; 233 FileName: string; 234 XMLDocument: TXMLDocument; 235 Mem: TMemoryStream; 236 RootNode: TDOMNode; 237 begin 238 FioAPI := TFioAPI.Create; 239 List := TStringList.Create; 240 XMLDocument := TXMLDocument.Create; 241 Mem := TMemoryStream.Create; 242 try 243 FioAPI.Format := DataFormat; 244 FioAPI.Token := Account.Token; 245 Account.Time := Now; 246 if FioAPI.DownloadInterval(Now, Now, List) then begin 247 List.SaveToStream(Mem); 248 ReadXMLFile(XMLDocument, Mem); 249 RootNode := XMLDocument.DocumentElement; 250 ShowMessage(RootNode.NodeName); 251 end else begin 252 Account.Number := ''; 253 Account.Balance := 0; 254 end; 255 finally 256 Mem.Free; 257 XMLDocument.Free; 258 FioAPI.Free; 259 List.Free; 260 end; 261 end; 262 263 procedure TCore.LoadAccounts; 264 var 265 I: Integer; 266 begin 267 for I := 0 to Accounts.Count - 1 do 268 LoadAccount(TAccount(Accounts[I])); 94 269 end; 95 270 … … 108 283 WriteString('TargetDir', TargetDirectory); 109 284 WriteInteger('DataFormat', Integer(DataFormat)); 110 WriteString('Token', Token);111 285 WriteDate('ReportTimeFrom', ReportTimeFrom); 112 286 WriteDateTime('ReportTimeTo', ReportTimeTo); … … 117 291 Free; 118 292 end; 293 Accounts.SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\Account')); 119 294 end; 120 295 … … 127 302 TargetDirectory := ReadStringWithDefault('TargetDir', ExtractFileDir(Application.ExeName)); 128 303 DataFormat := TFioDataFormat(ReadIntegerWithDefault('DataFormat', Integer(dfXML))); 129 Token := ReadStringWithDefault('Token', '');130 304 ReportTimeFrom := ReadDateTimeWithDefault('ReportTimeFrom', Now); 131 305 ReportTimeTo := ReadDateTimeWithDefault('ReportTimeTo', Now); … … 136 310 Free; 137 311 end; 312 Accounts.LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\Account')); 138 313 end; 139 314 … … 162 337 try 163 338 FioAPI.Format := DataFormat; 164 FioAPI.Token := Token;339 FioAPI.Token := CurrentAccount.Token; 165 340 if FioAPI.DownloadLast(List) then begin 166 341 FileName := TargetDirectory + DirectorySeparator + Format(SReport, [FormatDateTime('yyyy-mm-dd hh-nn-ss', Now) + … … 185 360 try 186 361 FioAPI.Format := DataFormat; 187 FioAPI.Token := Token;362 FioAPI.Token := CurrentAccount.Token; 188 363 if FioAPI.DownloadMonthly(ReportYear, ReportId, List) then begin 189 364 FileName := TargetDirectory + DirectorySeparator + Format(SReport, [IntToStr(ReportYear) + … … 209 384 try 210 385 FioAPI.Format := DataFormat; 211 FioAPI.Token := Token;386 FioAPI.Token := CurrentAccount.Token; 212 387 if FioAPI.DownloadInterval(ReportTimeFrom, ReportTimeTo, List) then begin 213 388 FileName := TargetDirectory + DirectorySeparator + Format(SReport, [FormatDateTime('yyyy-mm-dd', ReportTimeFrom) + … … 223 398 end; 224 399 400 procedure TCore.AAccountsExecute(Sender: TObject); 401 begin 402 TAccountList(FormAccounts.Accounts).Assign(Accounts); 403 if FormAccounts.ShowModal = mrOk then begin 404 Accounts.Assign(TAccountList(FormAccounts.Accounts)); 405 end; 406 end; 407 225 408 end. 226 409
Note:
See TracChangeset
for help on using the changeset viewer.