delphimvcframework/samples/winecellarclient_mobile/MainFormU.pas

158 lines
4.3 KiB
ObjectPascal
Raw Normal View History

2016-11-27 23:17:20 +01:00
unit MainFormU;
interface
uses
2020-10-23 00:27:52 +02:00
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
2016-11-27 23:17:20 +01:00
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.ListView.Types, IPPeerClient, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
FireDAC.DApt.Intf, Data.Bind.EngExt, FMX.Bind.DBEngExt, System.Rtti,
System.Bindings.Outputs, FMX.Bind.Editors, Data.Bind.Components,
Data.Bind.DBScope, REST.Client, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, REST.Response.Adapter, Data.Bind.ObjectScope,
2018-05-15 10:32:25 +02:00
FMX.ListView, FMX.Controls.Presentation, FMX.ListView.Appearances,
2020-10-23 00:27:52 +02:00
FMX.ListView.Adapters.Base, REST.Types, FireDAC.Stan.StorageBin,
System.Net.URLClient, System.Net.HttpClient, System.Net.HttpClientComponent,
FMX.TabControl, System.Actions, FMX.ActnList, FMX.Edit, FMX.Layouts,
FMX.Memo.Types, FMX.ScrollBox, FMX.Memo;
2016-11-27 23:17:20 +01:00
type
THeaderFooterForm = class(TForm)
Header: TToolBar;
Footer: TToolBar;
HeaderLabel: TLabel;
ListView1: TListView;
FDMemTable1: TFDMemTable;
2020-10-23 00:27:52 +02:00
Button1: TButton;
FDMemTable1id: TIntegerField;
FDMemTable1name: TStringField;
FDMemTable1year: TIntegerField;
FDMemTable1grapes: TStringField;
FDMemTable1country: TStringField;
FDMemTable1region: TStringField;
FDMemTable1description: TStringField;
2016-11-27 23:17:20 +01:00
BindSourceDB12: TBindSourceDB;
BindingsList1: TBindingsList;
LinkListControlToField1: TLinkListControlToField;
2020-10-23 00:27:52 +02:00
NetHTTPClient: TNetHTTPClient;
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
ActionList1: TActionList;
NextTabAction1: TNextTabAction;
Layout1: TLayout;
Layout2: TLayout;
Label1: TLabel;
Edit1: TEdit;
Layout3: TLayout;
Label2: TLabel;
Edit2: TEdit;
Layout4: TLayout;
lblYear: TLabel;
Edit3: TEdit;
Layout5: TLayout;
Layout6: TLayout;
Label3: TLabel;
Edit4: TEdit;
Layout7: TLayout;
Label4: TLabel;
Edit5: TEdit;
Layout8: TLayout;
Label5: TLabel;
Memo1: TMemo;
LinkControlToField1: TLinkControlToField;
LinkControlToField2: TLinkControlToField;
LinkControlToField3: TLinkControlToField;
LinkControlToField4: TLinkControlToField;
LinkControlToField5: TLinkControlToField;
LinkControlToField6: TLinkControlToField;
ChangeTabAction1: TChangeTabAction;
Button2: TButton;
PreviousTabAction1: TPreviousTabAction;
2016-11-27 23:17:20 +01:00
procedure Button1Click(Sender: TObject);
2020-10-23 00:27:52 +02:00
procedure NetHTTPClientRequestCompleted(const Sender: TObject;
const AResponse: IHTTPResponse);
procedure ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
procedure FormShow(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
procedure PreviousTabAction1Update(Sender: TObject);
2016-11-27 23:17:20 +01:00
private
2020-10-23 00:27:52 +02:00
procedure LoadWines;
2016-11-27 23:17:20 +01:00
public
{ Public declarations }
end;
2020-10-23 00:27:52 +02:00
const
{$IF Defined(MSWINDOWS)}
URL = 'http://localhost:3000/api';
{$ENDIF}
{$IF Defined(ANDROID)}
URL = 'http://192.168.1.46:3000/api';
{$ENDIF}
2016-11-27 23:17:20 +01:00
var
HeaderFooterForm: THeaderFooterForm;
implementation
2020-10-23 00:27:52 +02:00
uses
MVCFramework.DataSet.Utils;
2016-11-27 23:17:20 +01:00
{$R *.fmx}
procedure THeaderFooterForm.Button1Click(Sender: TObject);
begin
2020-10-23 00:27:52 +02:00
LoadWines;
end;
procedure THeaderFooterForm.FormKeyUp(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
if Key = vkHardwareBack then
begin
ChangeTabAction1.Tab := TabItem1;
ChangeTabAction1.Execute;
Key := 0;
end;
end;
procedure THeaderFooterForm.FormShow(Sender: TObject);
begin
TabControl1.ActiveTab := TabItem1;
LoadWines;
end;
procedure THeaderFooterForm.ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
NextTabAction1.ExecuteTarget(Self);
end;
procedure THeaderFooterForm.LoadWines;
begin
NetHTTPClient.Get(URL + '/wines');
end;
procedure THeaderFooterForm.NetHTTPClientRequestCompleted(const Sender: TObject;
const AResponse: IHTTPResponse);
var
lJSONString: string;
begin
lJSONString := AResponse.ContentAsString();
FDMemTable1.Active := True;
FDMemTable1.EmptyDataSet;
FDMemTable1.LoadFromJSONArray(lJSONString);
FDMemTable1.First;
end;
procedure THeaderFooterForm.PreviousTabAction1Update(Sender: TObject);
begin
PreviousTabAction1.Visible := TabControl1.ActiveTab = TabItem2;
2016-11-27 23:17:20 +01:00
end;
end.