| 1 | unit UFormAccounts;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 9 | StdCtrls, ExtCtrls, ActnList, Menus, Buttons, SpecializedList;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TFormAccounts }
|
|---|
| 14 |
|
|---|
| 15 | TFormAccounts = class(TForm)
|
|---|
| 16 | AAdd: TAction;
|
|---|
| 17 | ARemove: TAction;
|
|---|
| 18 | ActionList1: TActionList;
|
|---|
| 19 | BitBtnAdd: TBitBtn;
|
|---|
| 20 | BitBtnRemove: TBitBtn;
|
|---|
| 21 | ButtonOk: TButton;
|
|---|
| 22 | ButtonCancel: TButton;
|
|---|
| 23 | LabeledEditToken: TLabeledEdit;
|
|---|
| 24 | LabeledEditName: TLabeledEdit;
|
|---|
| 25 | ListView1: TListView;
|
|---|
| 26 | MenuItem1: TMenuItem;
|
|---|
| 27 | MenuItem2: TMenuItem;
|
|---|
| 28 | PopupMenu1: TPopupMenu;
|
|---|
| 29 | procedure AAddExecute(Sender: TObject);
|
|---|
| 30 | procedure ARemoveExecute(Sender: TObject);
|
|---|
| 31 | procedure FormCreate(Sender: TObject);
|
|---|
| 32 | procedure FormDestroy(Sender: TObject);
|
|---|
| 33 | procedure FormShow(Sender: TObject);
|
|---|
| 34 | procedure LabeledEditTokenChange(Sender: TObject);
|
|---|
| 35 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 36 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
|---|
| 37 | Selected: Boolean);
|
|---|
| 38 | private
|
|---|
| 39 | DisableEditUpdate: Boolean;
|
|---|
| 40 | public
|
|---|
| 41 | Accounts: TListObject;
|
|---|
| 42 | procedure Reload;
|
|---|
| 43 | procedure UpdateInterface;
|
|---|
| 44 | end;
|
|---|
| 45 |
|
|---|
| 46 | var
|
|---|
| 47 | FormAccounts: TFormAccounts;
|
|---|
| 48 |
|
|---|
| 49 | implementation
|
|---|
| 50 |
|
|---|
| 51 | uses
|
|---|
| 52 | UCore;
|
|---|
| 53 |
|
|---|
| 54 | {$R *.lfm}
|
|---|
| 55 |
|
|---|
| 56 | { TFormAccounts }
|
|---|
| 57 |
|
|---|
| 58 | procedure TFormAccounts.ListView1Data(Sender: TObject; Item: TListItem);
|
|---|
| 59 | begin
|
|---|
| 60 | if (Item.Index >= 0) and (Item.Index < Accounts.Count) then
|
|---|
| 61 | with TAccount(Accounts[Item.Index]) do begin
|
|---|
| 62 | Item.Caption := IntToStr(Item.Index + 1);
|
|---|
| 63 | Item.Data := Accounts[Item.Index];
|
|---|
| 64 | Item.SubItems.Add(Name);
|
|---|
| 65 | Item.SubItems.Add(Number);
|
|---|
| 66 | Item.SubItems.Add(BankCode);
|
|---|
| 67 | Item.SubItems.Add(FloatToStr(Balance));
|
|---|
| 68 | Item.SubItems.Add(DateToStr(Time));
|
|---|
| 69 | Item.SubItems.Add(Token);
|
|---|
| 70 | end;
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | procedure TFormAccounts.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
|---|
| 74 | Selected: Boolean);
|
|---|
| 75 | begin
|
|---|
| 76 | if Assigned(ListView1.Selected) then begin
|
|---|
| 77 | DisableEditUpdate := True;
|
|---|
| 78 | LabeledEditToken.Text := TAccount(ListView1.Selected.Data).Token;
|
|---|
| 79 | LabeledEditName.Text := TAccount(ListView1.Selected.Data).Name;
|
|---|
| 80 | DisableEditUpdate := False;
|
|---|
| 81 | end;
|
|---|
| 82 | UpdateInterface;
|
|---|
| 83 | end;
|
|---|
| 84 |
|
|---|
| 85 | procedure TFormAccounts.FormShow(Sender: TObject);
|
|---|
| 86 | begin
|
|---|
| 87 | UpdateInterface;
|
|---|
| 88 | Reload;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TFormAccounts.LabeledEditTokenChange(Sender: TObject);
|
|---|
| 92 | begin
|
|---|
| 93 | if not DisableEditUpdate then begin
|
|---|
| 94 | if Assigned(ListView1.Selected) then begin
|
|---|
| 95 | TAccount(ListView1.Selected.Data).Token := LabeledEditToken.Text;
|
|---|
| 96 | TAccount(ListView1.Selected.Data).Name := LabeledEditName.Text;
|
|---|
| 97 | end;
|
|---|
| 98 | Reload;
|
|---|
| 99 | end;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TFormAccounts.FormCreate(Sender: TObject);
|
|---|
| 103 | begin
|
|---|
| 104 | Accounts := TAccountList.Create;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | procedure TFormAccounts.ARemoveExecute(Sender: TObject);
|
|---|
| 108 | begin
|
|---|
| 109 | if Assigned(ListView1.Selected) then begin
|
|---|
| 110 | Accounts.Delete(Accounts.IndexOf(ListView1.Selected.Data));
|
|---|
| 111 | Reload;
|
|---|
| 112 | end;
|
|---|
| 113 | end;
|
|---|
| 114 |
|
|---|
| 115 | procedure TFormAccounts.AAddExecute(Sender: TObject);
|
|---|
| 116 | begin
|
|---|
| 117 | with Accounts.AddNew(TAccount.Create) do begin
|
|---|
| 118 | end;
|
|---|
| 119 | Reload;
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 | procedure TFormAccounts.FormDestroy(Sender: TObject);
|
|---|
| 123 | begin
|
|---|
| 124 | FreeAndNil(Accounts);
|
|---|
| 125 | end;
|
|---|
| 126 |
|
|---|
| 127 | procedure TFormAccounts.Reload;
|
|---|
| 128 | begin
|
|---|
| 129 | ListView1.Items.Count := Accounts.Count;
|
|---|
| 130 | ListView1.Refresh;
|
|---|
| 131 | UpdateInterface;
|
|---|
| 132 | end;
|
|---|
| 133 |
|
|---|
| 134 | procedure TFormAccounts.UpdateInterface;
|
|---|
| 135 | begin
|
|---|
| 136 | ARemove.Enabled := Assigned(ListView1.Selected);
|
|---|
| 137 | LabeledEditToken.Enabled := Assigned(ListView1.Selected);
|
|---|
| 138 | LabeledEditName.Enabled := Assigned(ListView1.Selected);
|
|---|
| 139 | end;
|
|---|
| 140 |
|
|---|
| 141 | end.
|
|---|
| 142 |
|
|---|