unit fMainClient;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  XData.Client, MathService, Vcl.StdCtrls;

type
  TClientForm = class(TForm)
    GroupBox1: TGroupBox;
    edSumA: TEdit;
    edSumB: TEdit;
    edSumResult: TEdit;
    Label1: TLabel;
    btSum: TButton;
    edSubA: TEdit;
    edSubB: TEdit;
    edSubResult: TEdit;
    Label2: TLabel;
    btSub: TButton;
    edPowerBase: TEdit;
    edPowerExponent: TEdit;
    edPowerResult: TEdit;
    Label3: TLabel;
    btPower: TButton;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    edSinAngle: TEdit;
    edSinResult: TEdit;
    btSin: TButton;
    edCosAngle: TEdit;
    edCosResult: TEdit;
    btCos: TButton;
    Label6: TLabel;
    Label7: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btSumClick(Sender: TObject);
    procedure btSubClick(Sender: TObject);
    procedure btPowerClick(Sender: TObject);
    procedure btSinClick(Sender: TObject);
    procedure btCosClick(Sender: TObject);
  private
    Client: TXDataClient;
    Arithmetic: IArithmeticService;
    Trigonometry: ITrigonometryService;
  public
  end;

var
  ClientForm: TClientForm;

implementation

{$R *.dfm}

procedure TClientForm.btSumClick(Sender: TObject);
begin
  edSumResult.Text := FloatToStr(
    Arithmetic.Add(StrToFloat(edSumA.Text), StrToFloat(edSumB.Text)));
end;

procedure TClientForm.btSinClick(Sender: TObject);
begin
  edSinResult.Text := FormatFloat('0.####',
    Trigonometry.Sin(StrToFloat(edSinAngle.Text)));
end;

procedure TClientForm.btSubClick(Sender: TObject);
begin
  edSubResult.Text := FloatToStr(
    Arithmetic.Subtract(StrToFloat(edSubA.Text), StrToFloat(edSubB.Text)));
end;

procedure TClientForm.btCosClick(Sender: TObject);
begin
  edCosResult.Text := FormatFloat('0.####',
    Trigonometry.Cos(StrToFloat(edCosAngle.Text)));
end;

procedure TClientForm.btPowerClick(Sender: TObject);
begin
  edPowerResult.Text := FloatToStr(
    Arithmetic.Power(StrToFloat(edPowerBase.Text), StrToFloat(edPowerExponent.Text)));
end;

procedure TClientForm.FormCreate(Sender: TObject);
begin
  Client := TXDataClient.Create;
  Client.Uri := 'http://localhost:2001/tms/math';
  Arithmetic := Client.Service<IArithmeticService>;
  Trigonometry := Client.Service<ITrigonometryService>;
  edSinAngle.Text := FormatFloat('0.####', PI);
  edCosAngle.Text := FormatFloat('0.####', PI);
end;

procedure TClientForm.FormDestroy(Sender: TObject);
begin
  Client.Free;
end;

end.
