Changeset 12


Ignore:
Timestamp:
Mar 15, 2013, 11:42:38 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Podpora pro více účtů.
Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/FioInfo.lpi

    r9 r12  
    9999      </Item5>
    100100    </RequiredPackages>
    101     <Units Count="6">
     101    <Units Count="7">
    102102      <Unit0>
    103103        <Filename Value="FioInfo.lpr"/>
     
    142142        <UnitName Value="UCore"/>
    143143      </Unit5>
     144      <Unit6>
     145        <Filename Value="Forms/UFormAccounts.pas"/>
     146        <IsPartOfProject Value="True"/>
     147        <ComponentName Value="FormAccounts"/>
     148        <HasResources Value="True"/>
     149        <ResourceBaseClass Value="Form"/>
     150        <UnitName Value="UFormAccounts"/>
     151      </Unit6>
    144152    </Units>
    145153  </ProjectOptions>
  • trunk/FioInfo.lpr

    r9 r12  
    99  Interfaces, // this includes the LCL widgetset
    1010  Forms, laz_synapse, UFioAPI, Common, TemplateGenerics,
    11   UFormSettings, UFormMain, UFormAbout, UCore, CoolTranslator;
     11  UFormSettings, UFormMain, UFormAbout, UFormAccounts, UCore, CoolTranslator;
    1212
    1313{$R *.res}
     
    2020  Application.CreateForm(TFormSettings, FormSettings);
    2121  Application.CreateForm(TFormAbout, FormAbout);
     22  Application.CreateForm(TFormAccounts, FormAccounts);
    2223  Application.Run;
    2324end.
  • trunk/Forms/UFormMain.lfm

    r10 r12  
    2222  end
    2323  object GroupBox1: TGroupBox
    24     Left = 8
     24    Left = 16
    2525    Height = 57
    26     Top = 8
     26    Top = 120
    2727    Width = 498
    2828    Anchors = [akTop, akLeft, akRight]
     
    4242  end
    4343  object GroupBox2: TGroupBox
    44     Left = 8
     44    Left = 17
    4545    Height = 72
    46     Top = 80
     46    Top = 184
    4747    Width = 498
    4848    Anchors = [akTop, akLeft, akRight]
     
    108108  end
    109109  object GroupBox3: TGroupBox
    110     Left = 8
     110    Left = 16
    111111    Height = 65
    112     Top = 168
     112    Top = 280
    113113    Width = 499
    114114    Anchors = [akTop, akLeft, akRight]
     
    181181    TabOrder = 5
    182182  end
     183  object Label5: TLabel
     184    Left = 16
     185    Height = 17
     186    Top = 12
     187    Width = 56
     188    Caption = 'Account:'
     189    ParentColor = False
     190  end
     191  object ComboBoxAccounts: TComboBox
     192    Left = 96
     193    Height = 29
     194    Top = 8
     195    Width = 312
     196    Anchors = [akTop, akLeft, akRight]
     197    ItemHeight = 0
     198    OnChange = ComboBoxAccountsChange
     199    Style = csDropDownList
     200    TabOrder = 6
     201  end
     202  object ButtonNew1: TButton
     203    Left = 416
     204    Height = 25
     205    Top = 8
     206    Width = 88
     207    Anchors = [akTop, akRight]
     208    Caption = 'Edit'
     209    OnClick = ButtonNew1Click
     210    TabOrder = 7
     211  end
     212  object GroupBox4: TGroupBox
     213    Left = 16
     214    Height = 65
     215    Top = 48
     216    Width = 498
     217    Anchors = [akTop, akLeft, akRight]
     218    Caption = 'Account state'
     219    ClientHeight = 46
     220    ClientWidth = 494
     221    TabOrder = 8
     222    object Label6: TLabel
     223      Left = 14
     224      Height = 17
     225      Top = 7
     226      Width = 56
     227      Caption = 'Balance:'
     228      ParentColor = False
     229    end
     230    object LabelBalance: TLabel
     231      Left = 110
     232      Height = 17
     233      Top = 7
     234      Width = 12
     235      Caption = '   '
     236      ParentColor = False
     237    end
     238  end
    183239end
  • trunk/Forms/UFormMain.lrt

    r9 r12  
    1414TFORMMAIN.LABEL2.CAPTION=Year:
    1515TFORMMAIN.LABEL3.CAPTION=Number:
     16TFORMMAIN.LABEL5.CAPTION=Account:
     17TFORMMAIN.BUTTONNEW1.CAPTION=Edit
     18TFORMMAIN.GROUPBOX4.CAPTION=Account state
     19TFORMMAIN.LABEL6.CAPTION=Balance:
     20TFORMMAIN.LABELBALANCE.CAPTION=   
  • trunk/Forms/UFormMain.pas

    r9 r12  
    1616  TFormMain = class(TForm)
    1717    ButtonNew: TButton;
     18    ButtonNew1: TButton;
    1819    ButtonSettings: TButton;
    1920    ButtonInterval: TButton;
     
    2122    ButtonExit: TButton;
    2223    ButtonAbout: TButton;
     24    ComboBoxAccounts: TComboBox;
    2325    DateEditStart: TDateEdit;
    2426    DateEditTo: TDateEdit;
     
    2628    GroupBox2: TGroupBox;
    2729    GroupBox3: TGroupBox;
     30    GroupBox4: TGroupBox;
    2831    Label1: TLabel;
    2932    Label2: TLabel;
    3033    Label3: TLabel;
    3134    Label4: TLabel;
     35    Label5: TLabel;
     36    Label6: TLabel;
     37    LabelBalance: TLabel;
    3238    SpinEditYear: TSpinEdit;
    3339    SpinEditId: TSpinEdit;
    3440    procedure ButtonIntervalClick(Sender: TObject);
    3541    procedure ButtonMonthlyClick(Sender: TObject);
     42    procedure ButtonNew1Click(Sender: TObject);
    3643    procedure ButtonNewClick(Sender: TObject);
     44    procedure ComboBoxAccountsChange(Sender: TObject);
    3745    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3846    procedure FormCreate(Sender: TObject);
     
    6876end;
    6977
     78procedure TFormMain.ComboBoxAccountsChange(Sender: TObject);
     79begin
     80  if ComboBoxAccounts.ItemIndex <> -1 then
     81    Core.CurrentAccount := TAccount(Core.Accounts[ComboBoxAccounts.ItemIndex])
     82    else Core.CurrentAccount := nil;
     83end;
     84
    7085procedure TFormMain.ButtonIntervalClick(Sender: TObject);
    7186begin
     
    7893  SaveInterface;
    7994  Core.ADownloadMonthly.Execute;
     95end;
     96
     97procedure TFormMain.ButtonNew1Click(Sender: TObject);
     98begin
     99  Core.AAccounts.Execute;
     100  LoadInterface;
    80101end;
    81102
     
    92113procedure TFormMain.LoadInterface;
    93114begin
     115  Core.Accounts.LoadToStrings(ComboBoxAccounts.Items);
    94116  DateEditStart.Date := Core.ReportTimeFrom;
    95117  DateEditTo.Date := Core.ReportTimeTo;
    96118  SpinEditYear.Value := Core.ReportYear;
    97119  SpinEditId.Value := Core.ReportId;
     120  ButtonInterval.Enabled := Assigned(Core.CurrentAccount);
     121  ButtonMonthly.Enabled := Assigned(Core.CurrentAccount);
     122  ButtonNew.Enabled := Assigned(Core.CurrentAccount);
    98123end;
    99124
  • trunk/Forms/UFormSettings.lfm

    r9 r12  
    1010  Position = poScreenCenter
    1111  LCLVersion = '1.1'
    12   object LabeledEditToken: TLabeledEdit
    13     Left = 8
    14     Height = 27
    15     Top = 25
    16     Width = 528
    17     Anchors = [akTop, akLeft, akRight]
    18     EditLabel.AnchorSideLeft.Control = LabeledEditToken
    19     EditLabel.AnchorSideRight.Control = LabeledEditToken
    20     EditLabel.AnchorSideRight.Side = asrBottom
    21     EditLabel.AnchorSideBottom.Control = LabeledEditToken
    22     EditLabel.Left = 8
    23     EditLabel.Height = 17
    24     EditLabel.Top = 5
    25     EditLabel.Width = 528
    26     EditLabel.Caption = 'Token'
    27     EditLabel.ParentColor = False
    28     TabOrder = 0
    29   end
    3012  object ButtonCancel: TButton
    3113    Left = 376
     
    3618    Caption = 'Cancel'
    3719    ModalResult = 2
    38     TabOrder = 1
     20    TabOrder = 0
    3921  end
    4022  object ButtonOk: TButton
     
    4729    Default = True
    4830    ModalResult = 1
    49     TabOrder = 2
     31    TabOrder = 1
    5032  end
    5133  object ComboBox1: TComboBox
    52     Left = 8
     34    Left = 11
    5335    Height = 29
    54     Top = 80
     36    Top = 32
    5537    Width = 236
    5638    ItemHeight = 0
    5739    Style = csDropDownList
    58     TabOrder = 3
     40    TabOrder = 2
    5941  end
    6042  object Label1: TLabel
    61     Left = 8
     43    Left = 11
    6244    Height = 17
    63     Top = 64
     45    Top = 16
    6446    Width = 83
    6547    Caption = 'Data format:'
     
    6749  end
    6850  object LabeledEditFolder: TLabeledEdit
    69     Left = 8
     51    Left = 11
    7052    Height = 27
    71     Top = 136
     53    Top = 88
    7254    Width = 440
    7355    Anchors = [akTop, akLeft, akRight]
     
    7658    EditLabel.AnchorSideRight.Side = asrBottom
    7759    EditLabel.AnchorSideBottom.Control = LabeledEditFolder
    78     EditLabel.Left = 8
     60    EditLabel.Left = 11
    7961    EditLabel.Height = 17
    80     EditLabel.Top = 116
     62    EditLabel.Top = 68
    8163    EditLabel.Width = 440
    8264    EditLabel.Caption = 'Destination folder:'
    8365    EditLabel.ParentColor = False
    84     TabOrder = 4
     66    TabOrder = 3
    8567  end
    8668  object Button1: TButton
    87     Left = 461
     69    Left = 464
    8870    Height = 25
    89     Top = 136
     71    Top = 88
    9072    Width = 75
    9173    Anchors = [akTop, akRight]
    9274    Caption = 'Select'
    9375    OnClick = Button1Click
    94     TabOrder = 5
     76    TabOrder = 4
    9577  end
    9678end
  • trunk/Forms/UFormSettings.lrt

    r9 r12  
    11TFORMSETTINGS.CAPTION=Settings
    2 TFORMSETTINGS.LABELEDEDITTOKEN.EDITLABEL.CAPTION=Token
    32TFORMSETTINGS.BUTTONCANCEL.CAPTION=Cancel
    43TFORMSETTINGS.BUTTONOK.CAPTION=Ok
  • trunk/Forms/UFormSettings.pas

    r10 r12  
    1919    ComboBox1: TComboBox;
    2020    Label1: TLabel;
    21     LabeledEditToken: TLabeledEdit;
    2221    LabeledEditFolder: TLabeledEdit;
    2322    procedure Button1Click(Sender: TObject);
     
    6766procedure TFormSettings.Load;
    6867begin
    69   LabeledEditToken.Text := Core.Token;
    7068  ComboBox1.ItemIndex := Integer(Core.DataFormat);
    7169  LabeledEditFolder.Text := Core.TargetDirectory;
     
    7472procedure TFormSettings.Save;
    7573begin
    76   Core.Token := LabeledEditToken.Text;
    7774  Core.DataFormat := TFioDataFormat(ComboBox1.ItemIndex);
    7875  Core.TargetDirectory := LabeledEditFolder.Text;
  • trunk/Languages/FioInfo.cs.po

    r11 r12  
    1515msgstr "O aplikaci"
    1616
     17#: tcore.aaccounts.caption
     18msgctxt "tcore.aaccounts.caption"
     19msgid "Accounts"
     20msgstr "Účty"
     21
    1722#: tcore.adownloadinterval.caption
    1823msgid "Download defined time interval"
     
    5661msgstr "O aplikaci"
    5762
     63#: tformaccounts.buttonadd.caption
     64msgid "Add"
     65msgstr "Přidat"
     66
     67#: tformaccounts.buttoncancel.caption
     68msgctxt "tformaccounts.buttoncancel.caption"
     69msgid "Cancel"
     70msgstr "ZruÅ¡it"
     71
     72#: tformaccounts.buttonok.caption
     73msgctxt "tformaccounts.buttonok.caption"
     74msgid "Ok"
     75msgstr "Ok"
     76
     77#: tformaccounts.buttonremove.caption
     78msgid "Remove"
     79msgstr "Odebrat"
     80
     81#: tformaccounts.caption
     82msgctxt "tformaccounts.caption"
     83msgid "Accounts"
     84msgstr "Účty"
     85
     86#: tformaccounts.labelededitname.editlabel.caption
     87msgctxt "tformaccounts.labelededitname.editlabel.caption"
     88msgid "Name"
     89msgstr "Jméno"
     90
     91#: tformaccounts.labelededittoken.editlabel.caption
     92msgctxt "tformaccounts.labelededittoken.editlabel.caption"
     93msgid "Token"
     94msgstr "Token"
     95
     96#: tformaccounts.listview1.columns[0].caption
     97msgctxt "tformaccounts.listview1.columns[0].caption"
     98msgid "Name"
     99msgstr "Jméno"
     100
     101#: tformaccounts.listview1.columns[1].caption
     102msgid "Number"
     103msgstr "Číslo"
     104
     105#: tformaccounts.listview1.columns[2].caption
     106msgid "Balance"
     107msgstr "Zůstatek"
     108
     109#: tformaccounts.listview1.columns[3].caption
     110#| msgid "Token"
     111msgctxt "tformaccounts.listview1.columns[3].caption"
     112msgid "Date"
     113msgstr "Datum"
     114
     115#: tformaccounts.listview1.columns[4].caption
     116msgctxt "tformaccounts.listview1.columns[4].caption"
     117msgid "Token"
     118msgstr "Token"
     119
    58120#: tformmain.buttoninterval.caption
    59121msgctxt "TFORMMAIN.BUTTONINTERVAL.CAPTION"
     
    71133msgstr "Stáhnout"
    72134
     135#: tformmain.buttonnew1.caption
     136msgid "Edit"
     137msgstr "Upravit"
     138
    73139#: tformmain.caption
    74140msgid "FioInfo"
     
    96162
    97163#: tformmain.groupbox1.caption
     164msgctxt "tformmain.groupbox1.caption"
    98165msgid "New transaction from last check"
    99166msgstr "Nové transakce od poslední kontroly"
     
    107174msgstr "VybranÃœ měsíční vÃœpis"
    108175
     176#: tformmain.groupbox4.caption
     177#| msgid "New transaction from last check"
     178msgctxt "tformmain.groupbox4.caption"
     179msgid "Account state"
     180msgstr "Stav účtu"
     181
    109182#: tformmain.label1.caption
    110183msgid "From:"
     
    123196msgstr "Do:"
    124197
     198#: tformmain.label5.caption
     199msgid "Account:"
     200msgstr "Účet:"
     201
     202#: tformmain.label6.caption
     203msgid "Balance:"
     204msgstr "Zůstatek:"
     205
     206#: tformmain.labelbalance.caption
     207msgid "   "
     208msgstr ""
     209
    125210#: tformsettings.button1.caption
    126211msgid "Select"
     
    133218
    134219#: tformsettings.buttonok.caption
     220msgctxt "tformsettings.buttonok.caption"
    135221msgid "Ok"
    136222msgstr "Ok"
     
    149235msgstr "Cílová sloşka:"
    150236
    151 #: tformsettings.labelededittoken.editlabel.caption
    152 msgid "Token"
    153 msgstr "Token"
    154 
    155237#: ucore.sdownloadnotsuccess
    156238msgctxt "ucore.sdownloadnotsuccess"
     
    185267#: uformabout.shomepage
    186268msgid "Web"
    187 msgstr ""
     269msgstr "Web"
    188270
    189271#: uformabout.smanufacturer
     
    199281msgstr "Verze"
    200282
    201 #: uformmain.sdownloadnotsuccess
    202 msgid "StaÅŸení nebylo úspěšné"
    203 msgstr ""
    204 
    205283#: uformsettings.sselectfolder
    206284msgid "Select destination folder"
  • trunk/Languages/FioInfo.po

    r11 r12  
    77msgstr ""
    88
     9#: tcore.aaccounts.caption
     10msgctxt "TCORE.AACCOUNTS.CAPTION"
     11msgid "Accounts"
     12msgstr ""
     13
    914#: tcore.adownloadinterval.caption
    1015msgid "Download defined time interval"
     
    4853msgstr ""
    4954
     55#: tformaccounts.buttonadd.caption
     56msgid "Add"
     57msgstr ""
     58
     59#: tformaccounts.buttoncancel.caption
     60msgctxt "TFORMACCOUNTS.BUTTONCANCEL.CAPTION"
     61msgid "Cancel"
     62msgstr ""
     63
     64#: tformaccounts.buttonok.caption
     65msgctxt "TFORMACCOUNTS.BUTTONOK.CAPTION"
     66msgid "Ok"
     67msgstr ""
     68
     69#: tformaccounts.buttonremove.caption
     70msgid "Remove"
     71msgstr ""
     72
     73#: tformaccounts.caption
     74msgctxt "tformaccounts.caption"
     75msgid "Accounts"
     76msgstr ""
     77
     78#: tformaccounts.labelededitname.editlabel.caption
     79msgctxt "TFORMACCOUNTS.LABELEDEDITNAME.EDITLABEL.CAPTION"
     80msgid "Name"
     81msgstr ""
     82
     83#: tformaccounts.labelededittoken.editlabel.caption
     84msgctxt "TFORMACCOUNTS.LABELEDEDITTOKEN.EDITLABEL.CAPTION"
     85msgid "Token"
     86msgstr ""
     87
     88#: tformaccounts.listview1.columns[0].caption
     89msgctxt "tformaccounts.listview1.columns[0].caption"
     90msgid "Name"
     91msgstr ""
     92
     93#: tformaccounts.listview1.columns[1].caption
     94msgid "Number"
     95msgstr ""
     96
     97#: tformaccounts.listview1.columns[2].caption
     98msgid "Balance"
     99msgstr ""
     100
     101#: tformaccounts.listview1.columns[3].caption
     102msgctxt "TFORMACCOUNTS.LISTVIEW1.COLUMNS[3].CAPTION"
     103msgid "Date"
     104msgstr ""
     105
     106#: tformaccounts.listview1.columns[4].caption
     107msgctxt "TFORMACCOUNTS.LISTVIEW1.COLUMNS[4].CAPTION"
     108msgid "Token"
     109msgstr ""
     110
    50111#: tformmain.buttoninterval.caption
    51112msgctxt "TFORMMAIN.BUTTONINTERVAL.CAPTION"
     
    63124msgstr ""
    64125
     126#: tformmain.buttonnew1.caption
     127msgid "Edit"
     128msgstr ""
     129
    65130#: tformmain.caption
    66131msgid "FioInfo"
     
    88153
    89154#: tformmain.groupbox1.caption
     155msgctxt "tformmain.groupbox1.caption"
    90156msgid "New transaction from last check"
    91157msgstr ""
     
    99165msgstr ""
    100166
     167#: tformmain.groupbox4.caption
     168msgctxt "TFORMMAIN.GROUPBOX4.CAPTION"
     169msgid "Account state"
     170msgstr ""
     171
    101172#: tformmain.label1.caption
    102173msgid "From:"
     
    115186msgstr ""
    116187
     188#: tformmain.label5.caption
     189msgid "Account:"
     190msgstr ""
     191
     192#: tformmain.label6.caption
     193msgid "Balance:"
     194msgstr ""
     195
     196#: tformmain.labelbalance.caption
     197msgid "   "
     198msgstr ""
     199
    117200#: tformsettings.button1.caption
    118201msgid "Select"
     
    125208
    126209#: tformsettings.buttonok.caption
     210msgctxt "tformsettings.buttonok.caption"
    127211msgid "Ok"
    128212msgstr ""
     
    141225msgstr ""
    142226
    143 #: tformsettings.labelededittoken.editlabel.caption
    144 msgid "Token"
    145 msgstr ""
    146 
    147227#: ucore.sdownloadnotsuccess
    148228msgctxt "ucore.sdownloadnotsuccess"
     
    190270msgstr ""
    191271
    192 #: uformmain.sdownloadnotsuccess
    193 msgctxt "uformmain.sdownloadnotsuccess"
    194 msgid "StaÅŸení nebylo úspěšné"
    195 msgstr ""
    196 
    197272#: uformsettings.sselectfolder
    198273msgid "Select destination folder"
  • trunk/UCore.lfm

    r10 r12  
    355355      OnExecute = AAboutExecute
    356356    end
     357    object AAccounts: TAction
     358      Caption = 'Accounts'
     359      OnExecute = AAccountsExecute
     360    end
    357361  end
    358362  object PopupMenuTray: TPopupMenu
     
    398402    EmailContact = 'robie@centrum.cz'
    399403    AppName = 'FioInfo'
    400     ReleaseDate = 41347
     404    ReleaseDate = 41348
    401405    RegistryKey = '\Software\Chronosoft\FioInfo'
    402406    RegistryRoot = rrKeyCurrentUser
  • trunk/UCore.lrt

    r9 r12  
    66TCORE.ADOWNLOADMONTHLY.CAPTION=Download monthly report
    77TCORE.AABOUT.CAPTION=About
     8TCORE.AACCOUNTS.CAPTION=Accounts
    89TCORE.MENUITEM3.CAPTION=-
  • trunk/UCore.pas

    r11 r12  
    88  Classes, SysUtils, FileUtil, ExtCtrls, Controls, ActnList, Menus, UFioAPI,
    99  URegistry, UApplicationInfo, UCoolTranslator, Registry, DateUtils, Forms,
    10   Dialogs;
     10  Dialogs, SpecializedList, dom, XMLRead, XMLWrite;
    1111
    1212type
     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;
    1335
    1436  { TCore }
     
    1638  TCore = class(TDataModule)
    1739    AAbout: TAction;
     40    AAccounts: TAction;
    1841    ActionList1: TActionList;
    1942    ADownloadInterval: TAction;
     
    3659    PopupMenuTray: TPopupMenu;
    3760    TrayIcon1: TTrayIcon;
     61    procedure AAccountsExecute(Sender: TObject);
    3862    procedure ADownloadIntervalExecute(Sender: TObject);
    3963    procedure ADownloadMonthlyExecute(Sender: TObject);
     
    4973  public
    5074    RegistryContext: TRegistryContext;
    51     Token: string;
     75    Accounts: TAccountList;
     76    CurrentAccount: TAccount;
    5277    DataFormat: TFioDataFormat;
    5378    TargetDirectory: string;
     
    5681    ReportTimeFrom: TDateTime;
    5782    ReportTimeTo: TDateTime;
     83    procedure LoadAccount(Account: TAccount);
     84    procedure LoadAccounts;
    5885    procedure SaveToRegistry(Context: TRegistryContext);
    5986    procedure LoadFromRegistry(Context: TRegistryContext);
     
    6895
    6996uses
    70   UFormAbout, UFormMain, UFormSettings;
     97  UFormAbout, UFormMain, UFormSettings, UFormAccounts;
    7198
    7299resourcestring
     
    75102  SSavedToFile = 'Dump saved to file %s';
    76103
     104{ TAccount }
     105
     106procedure TAccount.Assign(Source: TAccount);
     107begin
     108  Token := Source.Token;
     109  Name := Source.Name;
     110  Balance := Source.Balance;
     111  Time := Source.Time;
     112  Number := Source.Number;
     113end;
     114
     115procedure TAccount.LoadFromRegistry(Context: TRegistryContext);
     116begin
     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;
     129end;
     130
     131procedure TAccount.SaveToRegistry(Context: TRegistryContext);
     132begin
     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;
     145end;
     146
     147{ TAccountList }
     148
     149procedure TAccountList.LoadFromRegistry(Context: TRegistryContext);
     150var
     151  I: Integer;
     152begin
     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;
     165end;
     166
     167procedure TAccountList.SaveToRegistry(Context: TRegistryContext);
     168var
     169  I: Integer;
     170begin
     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)));
     181end;
     182
     183procedure TAccountList.LoadToStrings(Strings: TStrings);
     184var
     185  I: Integer;
     186begin
     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;
     193end;
     194
     195procedure TAccountList.Assign(Source: TAccountList);
     196var
     197  I: Integer;
     198begin
     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;
     205end;
     206
    77207{ TCore }
    78208
     
    84214procedure TCore.DataModuleCreate(Sender: TObject);
    85215begin
     216  Accounts := TAccountList.Create;
    86217  RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
    87218    ApplicationInfo1.RegistryKey);
    88219  LoadFromRegistry(RegistryContext);
     220  //LoadAccounts;
    89221end;
    90222
     
    92224begin
    93225  SaveToRegistry(RegistryContext);
     226  FreeAndNil(Accounts);
     227end;
     228
     229procedure TCore.LoadAccount(Account: TAccount);
     230var
     231  FioAPI: TFioAPI;
     232  List: TStringList;
     233  FileName: string;
     234  XMLDocument: TXMLDocument;
     235  Mem: TMemoryStream;
     236  RootNode: TDOMNode;
     237begin
     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;
     261end;
     262
     263procedure TCore.LoadAccounts;
     264var
     265  I: Integer;
     266begin
     267  for I := 0 to Accounts.Count - 1 do
     268    LoadAccount(TAccount(Accounts[I]));
    94269end;
    95270
     
    108283    WriteString('TargetDir', TargetDirectory);
    109284    WriteInteger('DataFormat', Integer(DataFormat));
    110     WriteString('Token', Token);
    111285    WriteDate('ReportTimeFrom', ReportTimeFrom);
    112286    WriteDateTime('ReportTimeTo', ReportTimeTo);
     
    117291    Free;
    118292  end;
     293  Accounts.SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\Account'));
    119294end;
    120295
     
    127302    TargetDirectory := ReadStringWithDefault('TargetDir', ExtractFileDir(Application.ExeName));
    128303    DataFormat := TFioDataFormat(ReadIntegerWithDefault('DataFormat', Integer(dfXML)));
    129     Token := ReadStringWithDefault('Token', '');
    130304    ReportTimeFrom := ReadDateTimeWithDefault('ReportTimeFrom', Now);
    131305    ReportTimeTo := ReadDateTimeWithDefault('ReportTimeTo', Now);
     
    136310    Free;
    137311  end;
     312  Accounts.LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\Account'));
    138313end;
    139314
     
    162337  try
    163338    FioAPI.Format := DataFormat;
    164     FioAPI.Token := Token;
     339    FioAPI.Token := CurrentAccount.Token;
    165340    if FioAPI.DownloadLast(List) then begin
    166341      FileName := TargetDirectory + DirectorySeparator + Format(SReport, [FormatDateTime('yyyy-mm-dd hh-nn-ss', Now) +
     
    185360  try
    186361    FioAPI.Format := DataFormat;
    187     FioAPI.Token := Token;
     362    FioAPI.Token := CurrentAccount.Token;
    188363    if FioAPI.DownloadMonthly(ReportYear, ReportId, List) then begin
    189364      FileName := TargetDirectory + DirectorySeparator + Format(SReport, [IntToStr(ReportYear) +
     
    209384  try
    210385    FioAPI.Format := DataFormat;
    211     FioAPI.Token := Token;
     386    FioAPI.Token := CurrentAccount.Token;
    212387    if FioAPI.DownloadInterval(ReportTimeFrom, ReportTimeTo, List) then begin
    213388      FileName := TargetDirectory + DirectorySeparator + Format(SReport, [FormatDateTime('yyyy-mm-dd', ReportTimeFrom) +
     
    223398end;
    224399
     400procedure TCore.AAccountsExecute(Sender: TObject);
     401begin
     402  TAccountList(FormAccounts.Accounts).Assign(Accounts);
     403  if FormAccounts.ShowModal = mrOk then begin
     404    Accounts.Assign(TAccountList(FormAccounts.Accounts));
     405  end;
     406end;
     407
    225408end.
    226409
Note: See TracChangeset for help on using the changeset viewer.