Changeset 6


Ignore:
Timestamp:
Mar 14, 2013, 9:24:41 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Okno s nastavením parametrů komunikace.
  • Přidáno: Pamatování si nastavení voleb.
  • Přidáno: Nyní lze stahovat nové operace, výpis dle časového rozmezí a měsíční výpisy.
Location:
trunk
Files:
78 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/FioInfo.lpi

    r3 r6  
    2727          <SearchPaths>
    2828            <IncludeFiles Value="$(ProjOutDir)"/>
     29            <OtherUnitFiles Value="Forms"/>
    2930            <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    3031          </SearchPaths>
     32          <Parsing>
     33            <SyntaxOptions>
     34              <SyntaxMode Value="Delphi"/>
     35              <CStyleOperator Value="False"/>
     36              <AllowLabel Value="False"/>
     37              <CPPInline Value="False"/>
     38            </SyntaxOptions>
     39          </Parsing>
     40          <CodeGeneration>
     41            <Checks>
     42              <IOChecks Value="True"/>
     43              <RangeChecks Value="True"/>
     44              <OverflowChecks Value="True"/>
     45              <StackChecks Value="True"/>
     46            </Checks>
     47            <VerifyObjMethodCallValidity Value="True"/>
     48          </CodeGeneration>
    3149          <Linking>
     50            <Debugging>
     51              <UseHeaptrc Value="True"/>
     52              <UseExternalDbgSyms Value="True"/>
     53            </Debugging>
    3254            <Options>
    3355              <Win32>
     
    5678      </local>
    5779    </RunParams>
    58     <RequiredPackages Count="2">
     80    <RequiredPackages Count="4">
    5981      <Item1>
     82        <PackageName Value="TemplateGenerics"/>
     83        <DefaultFilename Value="Packages/TemplateGenerics/TemplateGenerics.lpk" Prefer="True"/>
     84      </Item1>
     85      <Item2>
     86        <PackageName Value="Common"/>
     87        <DefaultFilename Value="Packages/Common/Common.lpk" Prefer="True"/>
     88      </Item2>
     89      <Item3>
    6090        <PackageName Value="laz_synapse"/>
    6191        <DefaultFilename Value="Packages/synapse/source/lib/laz_synapse.lpk" Prefer="True"/>
    62       </Item1>
    63       <Item2>
     92      </Item3>
     93      <Item4>
    6494        <PackageName Value="LCL"/>
    65       </Item2>
     95      </Item4>
    6696    </RequiredPackages>
    67     <Units Count="3">
     97    <Units Count="4">
    6898      <Unit0>
    6999        <Filename Value="FioInfo.lpr"/>
     
    84114        <UnitName Value="UFioAPI"/>
    85115      </Unit2>
     116      <Unit3>
     117        <Filename Value="Forms/UFormSettings.pas"/>
     118        <IsPartOfProject Value="True"/>
     119        <ComponentName Value="FormSettings"/>
     120        <ResourceBaseClass Value="Form"/>
     121        <UnitName Value="UFormSettings"/>
     122      </Unit3>
    86123    </Units>
    87124  </ProjectOptions>
     
    93130    <SearchPaths>
    94131      <IncludeFiles Value="$(ProjOutDir)"/>
     132      <OtherUnitFiles Value="Forms"/>
    95133      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    96134    </SearchPaths>
     135    <Parsing>
     136      <SyntaxOptions>
     137        <SyntaxMode Value="Delphi"/>
     138        <CStyleOperator Value="False"/>
     139        <AllowLabel Value="False"/>
     140        <CPPInline Value="False"/>
     141      </SyntaxOptions>
     142    </Parsing>
     143    <CodeGeneration>
     144      <SmartLinkUnit Value="True"/>
     145      <Optimizations>
     146        <OptimizationLevel Value="3"/>
     147      </Optimizations>
     148    </CodeGeneration>
    97149    <Linking>
     150      <Debugging>
     151        <GenerateDebugInfo Value="False"/>
     152      </Debugging>
    98153      <Options>
    99154        <Win32>
  • trunk/FioInfo.lpr

    r3 r6  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, laz_synapse, UFioAPI;
     10  Forms, UFormMain, laz_synapse, UFioAPI, Common, TemplateGenerics,
     11  UFormSettings;
    1112
    1213{$R *.res}
     
    1617  Application.Initialize;
    1718  Application.CreateForm(TFormMain, FormMain);
     19  Application.CreateForm(TFormSettings, FormSettings);
    1820  Application.Run;
    1921end.
  • trunk/UFioAPI.pas

    r5 r6  
    11unit UFioAPI;
    22
    3 {$mode objfpc}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
     
    1010type
    1111
     12  TFioDataFormat = (dfXML, dfCVS, dfGPC, dfOFX, dfJSON, dfHTML, dfSTA);
     13
    1214  { TFioAPI }
    1315
     
    1719  public
    1820    Token: string;
    19     Format: string;
     21    Format: TFioDataFormat;
    2022    function DownloadInterval(TimeFrom, TimeTo: TDateTime; Data: TStrings): Boolean;
    2123    function DownloadMonthly(Year, Id: Integer; Data: TStrings): Boolean;
    2224    function DownloadLast(Data: TStrings): Boolean;
    2325  end;
     26
     27const
     28  DataFormatText: array[TFioDataFormat] of string = ('XML', 'CVS', 'GPC', 'OFX',
     29    'JSON', 'HTML', 'STA');
     30  DataFormatURL: array[TFioDataFormat] of string = ('xml', 'cvs', 'gpc', 'ofx',
     31    'json', 'html', 'sta');
    2432
    2533implementation
     
    3341  HTTPSender := THTTPSend.Create;
    3442  try
    35     Format := 'xml';
    36     Token := 'dd';
    3743    HTTPSender.HTTPMethod('GET', URL);
    3844    try
     
    6369    '/' + FormatDateTime('yyyy-mm-dd', TimeFrom) +
    6470    '/' + FormatDateTime('yyyy-mm-dd', TimeTo) +
    65     '/transactions.' + Format, Data);
     71    '/transactions.' + DataFormatURL[Format], Data);
    6672end;
    6773
     
    7076  Result := Download('https://www.fio.cz/ib_api/rest/by-id/' + Token +
    7177    '/' + IntToStr(Year) + '/' + IntToStr(Id) +
    72     '/transactions.' + Format, Data);
     78    '/transactions.' + DataFormatURL[Format], Data);
    7379end;
    7480
     
    7682begin
    7783  Result := Download('https://www.fio.cz/ib_api/rest/last/' + Token +
    78     '/transactions.' + Format, Data);
     84    '/transactions.' + DataFormatURL[Format], Data);
    7985end;
    8086
  • trunk/UFormMain.lfm

    r5 r6  
    11object FormMain: TFormMain
    2   Left = 447
     2  Left = 364
    33  Height = 368
    4   Top = 247
     4  Top = 183
    55  Width = 510
    66  Caption = 'FioInfo'
    77  ClientHeight = 368
    88  ClientWidth = 510
     9  OnClose = FormClose
     10  OnCreate = FormCreate
    911  LCLVersion = '1.1'
    10   object LabeledEdit1: TLabeledEdit
    11     Left = 8
    12     Height = 27
    13     Top = 25
    14     Width = 488
    15     EditLabel.AnchorSideLeft.Control = LabeledEdit1
    16     EditLabel.AnchorSideRight.Control = LabeledEdit1
    17     EditLabel.AnchorSideRight.Side = asrBottom
    18     EditLabel.AnchorSideBottom.Control = LabeledEdit1
    19     EditLabel.Left = 8
    20     EditLabel.Height = 17
    21     EditLabel.Top = 5
    22     EditLabel.Width = 488
    23     EditLabel.Caption = 'Token'
    24     EditLabel.ParentColor = False
     12  object Button2: TButton
     13    Left = 376
     14    Height = 25
     15    Top = 336
     16    Width = 112
     17    Action = ASettings
     18    Anchors = [akTop, akBottom]
    2519    TabOrder = 0
    2620  end
    27   object Button1: TButton
     21  object GroupBox1: TGroupBox
     22    Left = 8
     23    Height = 57
     24    Top = 8
     25    Width = 489
     26    Anchors = [akTop, akLeft, akRight]
     27    Caption = 'Nové platby od posledního staÅŸení'
     28    ClientHeight = 38
     29    ClientWidth = 485
     30    TabOrder = 1
     31    object Button1: TButton
     32      Left = 358
     33      Height = 25
     34      Top = 7
     35      Width = 112
     36      Action = ADownloadNew
     37      Caption = 'Stáhnout'
     38      TabOrder = 0
     39    end
     40  end
     41  object GroupBox2: TGroupBox
     42    Left = 8
     43    Height = 72
     44    Top = 80
     45    Width = 489
     46    Anchors = [akTop, akLeft, akRight]
     47    Caption = 'Transakce v zadaném časovém rozpětí'
     48    ClientHeight = 53
     49    ClientWidth = 485
     50    TabOrder = 2
     51    object Button3: TButton
     52      Left = 358
     53      Height = 25
     54      Top = 7
     55      Width = 112
     56      Action = ADownloadInterval
     57      Caption = 'Stáhnout'
     58      TabOrder = 0
     59    end
     60    object DateEditStart: TDateEdit
     61      Left = 54
     62      Height = 27
     63      Top = 5
     64      Width = 80
     65      CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
     66      OKCaption = 'OK'
     67      CancelCaption = 'Cancel'
     68      DateOrder = doNone
     69      ButtonWidth = 23
     70      CharCase = ecNormal
     71      NumGlyphs = 1
     72      MaxLength = 0
     73      TabOrder = 1
     74    end
     75    object DateEditTo: TDateEdit
     76      Left = 230
     77      Height = 27
     78      Top = 9
     79      Width = 80
     80      CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
     81      OKCaption = 'OK'
     82      CancelCaption = 'Cancel'
     83      DateOrder = doNone
     84      ButtonWidth = 23
     85      CharCase = ecNormal
     86      NumGlyphs = 1
     87      MaxLength = 0
     88      TabOrder = 2
     89    end
     90    object Label1: TLabel
     91      Left = 22
     92      Height = 17
     93      Top = 9
     94      Width = 22
     95      Caption = 'Od:'
     96      ParentColor = False
     97    end
     98    object Label4: TLabel
     99      Left = 174
     100      Height = 17
     101      Top = 15
     102      Width = 22
     103      Caption = 'Do:'
     104      ParentColor = False
     105    end
     106  end
     107  object GroupBox3: TGroupBox
     108    Left = 8
     109    Height = 65
     110    Top = 168
     111    Width = 489
     112    Caption = 'Měsíční vÃœpis'
     113    ClientHeight = 46
     114    ClientWidth = 485
     115    TabOrder = 3
     116    object Button4: TButton
     117      Left = 358
     118      Height = 25
     119      Top = 7
     120      Width = 112
     121      Action = ADownloadMonthly
     122      Caption = 'Stáhnout'
     123      TabOrder = 0
     124    end
     125    object SpinEditYear: TSpinEdit
     126      Left = 54
     127      Height = 27
     128      Top = 7
     129      Width = 96
     130      MaxValue = 9999
     131      MinValue = 1000
     132      TabOrder = 1
     133      Value = 2000
     134    end
     135    object SpinEditId: TSpinEdit
     136      Left = 230
     137      Height = 27
     138      Top = 7
     139      Width = 96
     140      MaxValue = 12
     141      MinValue = 1
     142      TabOrder = 2
     143      Value = 1
     144    end
     145    object Label2: TLabel
     146      Left = 20
     147      Height = 17
     148      Top = 15
     149      Width = 28
     150      Caption = 'Rok:'
     151      ParentColor = False
     152    end
     153    object Label3: TLabel
     154      Left = 174
     155      Height = 17
     156      Top = 15
     157      Width = 36
     158      Caption = 'Číslo:'
     159      ParentColor = False
     160    end
     161  end
     162  object Button5: TButton
    28163    Left = 16
    29164    Height = 25
    30     Top = 344
     165    Top = 336
    31166    Width = 112
    32     Action = ADownload
    33     TabOrder = 1
    34   end
    35   object Memo1: TMemo
    36     Left = 16
    37     Height = 271
    38     Top = 56
    39     Width = 453
    40     TabOrder = 2
     167    Action = AExit
     168    Anchors = [akLeft, akBottom]
     169    TabOrder = 4
    41170  end
    42171  object TrayIcon1: TTrayIcon
     
    43294458    Hint = 'FioInfo'
    43304459    Visible = True
    4331     left = 216
    4332     top = 176
     4460    left = 224
     4461    top = 296
    43334462  end
    43344463  object PopupMenuTray: TPopupMenu
    43354464    Images = ImageList1
    4336     left = 152
    4337     top = 93
     4465    left = 224
     4466    top = 240
    43384467    object MenuItem1: TMenuItem
    43394468      Action = AShow
     
    43464475  object ActionList1: TActionList
    43474476    Images = ImageList1
    4348     left = 264
    4349     top = 93
     4477    left = 296
     4478    top = 240
    43504479    object AShow: TAction
    43514480      Caption = 'Ukázat'
     
    43564485      OnExecute = AExitExecute
    43574486    end
    4358     object ADownload: TAction
    4359       Caption = 'Zkontrolovat'
    4360       OnExecute = ADownloadExecute
     4487    object ASettings: TAction
     4488      Caption = 'Nastavení'
     4489      OnExecute = ASettingsExecute
     4490    end
     4491    object ADownloadNew: TAction
     4492      Caption = 'Stáhnout nové'
     4493      OnExecute = ADownloadNewExecute
     4494    end
     4495    object ADownloadInterval: TAction
     4496      Caption = 'Stáhnout dle rozsahu data'
     4497      OnExecute = ADownloadIntervalExecute
     4498    end
     4499    object ADownloadMonthly: TAction
     4500      Caption = 'Stáhnout měsíční vÃœpis'
     4501      OnExecute = ADownloadMonthlyExecute
    43614502    end
    43624503  end
    43634504  object ImageList1: TImageList
    43644505    left = 296
    4365     top = 176
     4506    top = 296
    43664507  end
    43674508end
  • trunk/UFormMain.pas

    r5 r6  
    11unit UFormMain;
    22
    3 {$mode objfpc}{$H+}
     3{$mode delphi{$H+}
    44
    55interface
     
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, Menus, ActnList, httpsend, UFioAPI;
     9  ExtCtrls, Menus, ActnList, Spin, EditBtn, UFioAPI, URegistry, Registry,
     10  DateUtils;
    1011
    1112type
     
    1415
    1516  TFormMain = class(TForm)
    16     ADownload: TAction;
     17    ADownloadInterval: TAction;
     18    ADownloadMonthly: TAction;
     19    ASettings: TAction;
     20    ADownloadNew: TAction;
    1721    AExit: TAction;
    1822    AShow: TAction;
    1923    ActionList1: TActionList;
    2024    Button1: TButton;
     25    Button2: TButton;
     26    Button3: TButton;
     27    Button4: TButton;
     28    Button5: TButton;
     29    DateEditStart: TDateEdit;
     30    DateEditTo: TDateEdit;
     31    GroupBox1: TGroupBox;
     32    GroupBox2: TGroupBox;
     33    GroupBox3: TGroupBox;
    2134    ImageList1: TImageList;
    22     LabeledEdit1: TLabeledEdit;
    23     Memo1: TMemo;
     35    Label1: TLabel;
     36    Label2: TLabel;
     37    Label3: TLabel;
     38    Label4: TLabel;
    2439    MenuItem1: TMenuItem;
    2540    MenuItem2: TMenuItem;
    2641    PopupMenuTray: TPopupMenu;
     42    SpinEditYear: TSpinEdit;
     43    SpinEditId: TSpinEdit;
    2744    TrayIcon1: TTrayIcon;
    28     procedure ADownloadExecute(Sender: TObject);
     45    procedure ADownloadIntervalExecute(Sender: TObject);
     46    procedure ADownloadMonthlyExecute(Sender: TObject);
     47    procedure ADownloadNewExecute(Sender: TObject);
    2948    procedure AExitExecute(Sender: TObject);
     49    procedure ASettingsExecute(Sender: TObject);
    3050    procedure AShowExecute(Sender: TObject);
     51    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     52    procedure FormCreate(Sender: TObject);
    3153  private
    3254    { private declarations }
    3355  public
    34     { public declarations }
     56    RegistryContext: TRegistryContext;
     57    Token: string;
     58    Format: TFioDataFormat;
     59    TargetDirectory: string;
     60    ReportYear: Integer;
     61    ReportId: Integer;
     62    ReportTimeFrom: TDateTime;
     63    ReportTimeTo: TDateTime;
     64    procedure LoadInterface;
     65    procedure SaveInterface;
     66    procedure SaveToRegistry(Context: TRegistryContext);
     67    procedure LoadFromRegistry(Context: TRegistryContext);
    3568  end;
    3669
     
    4275{$R *.lfm}
    4376
     77uses
     78  UFormSettings;
     79
     80resourcestring
     81  SDownloadNotSuccess = 'StaÅŸení nebylo úspěšné';
     82
     83
    4484{ TFormMain }
    4585
     
    4989end;
    5090
     91procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     92begin
     93  SaveInterface;
     94  SaveToRegistry(RegistryContext);
     95end;
     96
     97procedure TFormMain.FormCreate(Sender: TObject);
     98begin
     99  RegistryContext := RegContext(HKEY_CURRENT_USER, '\Software\Chronosoft\FioInfo');
     100  LoadFromRegistry(RegistryContext);
     101  LoadInterface;
     102end;
     103
     104procedure TFormMain.LoadInterface;
     105begin
     106  DateEditStart.Date := ReportTimeFrom;
     107  DateEditTo.Date := ReportTimeTo;
     108  SpinEditYear.Value := ReportYear;
     109  SpinEditId.Value := ReportId;
     110end;
     111
     112procedure TFormMain.SaveInterface;
     113begin
     114  ReportTimeFrom := DateEditStart.Date;
     115  ReportTimeTo := DateEditTo.Date;
     116  ReportYear := SpinEditYear.Value;
     117  ReportId := SpinEditId.Value;
     118end;
     119
     120procedure TFormMain.SaveToRegistry(Context: TRegistryContext);
     121begin
     122  with TRegistryEx.Create do
     123  try
     124    RootKey := Context.RootKey;
     125    OpenKey(Context.Key, True);
     126    WriteString('TargetDir', TargetDirectory);
     127    WriteInteger('DataFormat', Integer(Format));
     128    WriteString('Token', Token);
     129    WriteDate('ReportTimeFrom', ReportTimeFrom);
     130    WriteDateTime('ReportTimeTo', ReportTimeTo);
     131    WriteInteger('ReportYear', ReportYear);
     132    WriteInteger('ReportId', ReportId);
     133  finally
     134    Free;
     135  end;
     136end;
     137
     138procedure TFormMain.LoadFromRegistry(Context: TRegistryContext);
     139begin
     140  with TRegistryEx.Create do
     141  try
     142    RootKey := Context.RootKey;
     143    OpenKey(Context.Key, True);
     144    TargetDirectory := ReadStringWithDefault('TargetDir', ExtractFileDir(Application.ExeName));
     145    Format := TFioDataFormat(ReadIntegerWithDefault('DataFormat', Integer(dfXML)));
     146    Token := ReadStringWithDefault('Token', '');
     147    ReportTimeFrom := ReadDateTimeWithDefault('ReportTimeFrom', Now);
     148    ReportTimeTo := ReadDateTimeWithDefault('ReportTimeTo', Now);
     149    ReportYear := ReadIntegerWithDefault('ReportYear', YearOf(Now));
     150    ReportId := ReadIntegerWithDefault('ReportId', MonthOf(Now));
     151  finally
     152    Free;
     153  end;
     154end;
     155
    51156procedure TFormMain.AExitExecute(Sender: TObject);
    52157begin
    53   Application.Terminate;
    54 end;
    55 
    56 procedure TFormMain.ADownloadExecute(Sender: TObject);
     158  Close;
     159end;
     160
     161procedure TFormMain.ASettingsExecute(Sender: TObject);
     162begin
     163  FormSettings.Load;
     164  if FormSettings.ShowModal = mrOk then begin
     165    FormSettings.Save;
     166    SaveToRegistry(RegistryContext);
     167  end;
     168end;
     169
     170procedure TFormMain.ADownloadNewExecute(Sender: TObject);
    57171var
    58172  FioAPI: TFioAPI;
     173  List: TStringList;
    59174begin
    60175  FioAPI := TFioAPI.Create;
    61   try
    62     FioAPI.Token := LabeledEdit1.Text;
    63     FioAPI.Format := 'xml';
    64     FioAPI.DownloadInterval(EncodeDate(2013, 03, 01), EncodeDate(2013, 03, 14),
    65       Memo1.Lines);
     176  List := TStringList.Create;
     177  try
     178    FioAPI.Format := Format;
     179    FioAPI.Token := Token;
     180    if FioAPI.DownloadLast(List) then begin
     181      List.SaveToFile('VÃœpis ' + FormatDateTime('yyyy-mm-dd hh-nn-ss', Now) +
     182        ExtensionSeparator + DataFormatURL[FioAPI.Format]);
     183    end else ShowMessage(SDownloadNotSuccess);
    66184  finally
    67185    FioAPI.Free;
     186    List.Free;
     187  end;
     188end;
     189
     190procedure TFormMain.ADownloadMonthlyExecute(Sender: TObject);
     191var
     192  FioAPI: TFioAPI;
     193  List: TStringList;
     194begin
     195  FioAPI := TFioAPI.Create;
     196  List := TStringList.Create;
     197  try
     198    FioAPI.Format := Format;
     199    FioAPI.Token := Token;
     200    if FioAPI.DownloadMonthly(SpinEditYear.Value, SpinEditId.Value, List) then begin
     201      List.SaveToFile('VÃœpis měsíční ' + IntToStr(SpinEditYear.Value) +
     202        '-' + IntToStr(SpinEditId.Value) +
     203        ExtensionSeparator + DataFormatURL[FioAPI.Format]);
     204    end else ShowMessage(SDownloadNotSuccess);
     205  finally
     206    FioAPI.Free;
     207    List.Free;
     208  end;
     209end;
     210
     211procedure TFormMain.ADownloadIntervalExecute(Sender: TObject);
     212var
     213  FioAPI: TFioAPI;
     214  List: TStringList;
     215begin
     216  FioAPI := TFioAPI.Create;
     217  List := TStringList.Create;
     218  try
     219    FioAPI.Format := Format;
     220    FioAPI.Token := Token;
     221    if FioAPI.DownloadInterval(DateEditStart.Date, DateEditTo.Date, List) then begin
     222      List.SaveToFile('VÃœpis ' + FormatDateTime('yyyy-mm-dd', DateEditStart.Date) +
     223        ' ' + FormatDateTime('yyyy-mm-dd', DateEditTo.Date) +
     224        ExtensionSeparator + DataFormatURL[FioAPI.Format]);
     225    end else ShowMessage(SDownloadNotSuccess);
     226  finally
     227    FioAPI.Free;
     228    List.Free;
    68229  end;
    69230end;
Note: See TracChangeset for help on using the changeset viewer.