unit uMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.WebBrowser, FMX.Controls.Presentation, System.JSON, System.IOUtils;
type
TFMain = class(TForm)
PMain: TPanel;
PConf: TPanel;
WBMain: TWebBrowser;
BOK: TButton;
RBBor: TRadioButton;
RBKay: TRadioButton;
RBKros: TRadioButton;
RBZel: TRadioButton;
LCity: TLabel;
procedure BOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure zelcheck;
procedure kaycheck;
procedure kroscheck;
procedure borcheck;
procedure readparam;
procedure paramthereis;
procedure defaultconf;
private
{ Private declarations }
public
{ Public declarations }
end;
var
FMain: TFMain;
ConfFileName: string;
AOptions: TJSONObject;
AGroup: TJSONObject;
AParam: TJSONValue;
APair: TJSONPair;
AParamz,AParamk,AParamb,AParamkr: TJSONValue;
implementation
{$R *.fmx}
procedure TFMain.zelcheck;
begin
PConf.Visible:=false;
PMain.Visible:=true;
WBMain.Visible:=true;
WBMain.URL:='https://сайт/1/';
end;
procedure TFMain.kaycheck;
begin
PConf.Visible:=false;
PMain.Visible:=true;
WBMain.Visible:=true;
WBMain.URL:='https://сайт/2/';
end;
procedure TFMain.kroscheck;
begin
PConf.Visible:=false;
PMain.Visible:=true;
WBMain.Visible:=true;
WBMain.URL:='https://сайт/3/';
end;
procedure TFMain.borcheck;
begin
PConf.Visible:=false;
PMain.Visible:=true;
WBMain.Visible:=true;
WBMain.URL:='https://сайт/4/';
end;
procedure TFMain.readparam;
begin
AParamz := AGroup.GetValue('zel');
AParamk := AGroup.GetValue('kay');
AParamb := AGroup.GetValue('bor');
AParamkr := AGroup.GetValue('kros');
end;
procedure TFMain.paramthereis;
begin
RBZel.IsChecked := AParamz is TJSONTrue;
if RBZel.IsChecked then
zelcheck
else
begin
RBbor.IsChecked := AParamb is TJSONTrue;
if RBbor.IsChecked then
borcheck
else
begin
RBkay.IsChecked := AParamk is TJSONTrue;
if RBkay.IsChecked then
kaycheck
else
begin
RBkos.IsChecked := AParamkr is TJSONTrue;
if RBkos.IsChecked then
kroscheck;
end;
end;
end;
exit;
end;
procedure TFMain.defaultconf;
begin
PConf.Visible:=true;
PMain.Visible:=false;
WBMain.Visible:=false
end;
procedure TFMain.BOKClick(Sender: TObject);
begin
AOptions := TJSONObject.Create;
AGroup := TJSONObject.Create;
if RBZel.IsChecked=false or RBKay.IsChecked=false or
RBKros.IsChecked=false or RBBor.IsChecked=false then
begin
if RBZel.IsChecked then
begin
zelcheck;
AGroup.AddPair('zel', TJSONTrue.Create);
end
else
AGroup.AddPair('zel', TJSONFalse.Create);
if RBKay.IsChecked then
begin
kaycheck;
AGroup.AddPair('kay', TJSONTrue.Create);
end
else
AGroup.AddPair('kay', TJSONFalse.Create);
if RBKros.IsChecked then
begin
kroscheck;
AGroup.AddPair('kros', TJSONTrue.Create);
end
else
AGroup.AddPair('kros', TJSONFalse.Create);
if RBBor.IsChecked then
begin
borcheck;
AGroup.AddPair('bor', TJSONTrue.Create);
end
else
AGroup.AddPair('bor', TJSONFalse.Create);
end
else
ShowMessage('Сначала нужно выбрать город');
AOptions.AddPair('city', AGroup);
TFile.WriteAllText(ConfFileName, AOptions.ToString);
end;
procedure TFMain.FormCreate(Sender: TObject);
begin
{$IFDEF ANDROID}
ConfFileName := TPath.Combine(TPath.GetDocumentsPath, 'Options.json');
{$ENDIF}
{$IFDEF MSWINDOWS}
ConfFileName := ExtractFilePath(ParamStr(0)) + 'Options.json';
{$ENDIF}
end;
procedure TFMain.FormShow(Sender: TObject);
begin
if FileExists(ConfFileName) then
begin
AOptions := TJSONObject(TJSONObject.ParseJSONValue(TFile.ReadAllText(ConfFileName)));
AGroup := TJSONObject(AOptions.GetValue('city'));
if AGroup <> nil then
begin
readparam;
if AParamz <> nil then
paramthereis
else exit;
end
else
defaultconf;
end
else
defaultconf;
end;
end.