// For testing querys.
// Visual aspect is for testing purposes only and has no affect on the client.
// Authors:
// Cameron Hayes
// Elias Serraf
// Mac ...
unit Data;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Data.DB, Vcl.Grids, AdvObj,
  BaseGrid, AdvGrid, DBAdvGrid, MemDS, DBAccess, Uni, Vcl.StdCtrls, Vcl.Mask,
  vcl.wwdbedit, vcl.wwdotdot, vcl.wwdbcomb, REST.Client, REST.Types, System.JSON,
  System.Generics.Collections, AdvEdit, vcl.wwdblook, vcl.wwdbdatetimepicker,
  System.Hash, Api.Database, Vcl.ExtCtrls;

type
  TFData = class(TForm)
    dsUsers: TDataSource;
    btnFind: TButton;
    Memo1: TMemo;
    DBAdvGrid1: TDBAdvGrid;
    DBAdvGrid2: TDBAdvGrid;
    dsGrid2: TDataSource;
    edtUsername: TEdit;
    edtPassword: TEdit;
    lblHash: TLabel;
    btnAddUser: TButton;
    lblHash2: TLabel;
    uqUsers: TUniQuery;
    cbAdmin: TCheckBox;
    edtFullName: TEdit;
    edtPhoneNumber: TEdit;
    edtEmailAddress: TEdit;
    btnPDF: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure btnFindClick(Sender: TObject);
    procedure btnPDFClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    kgDB: TApiDatabase;
    accountSID: string;
    authHeader: string;
  public
    procedure RunOrdersReport(searchOptions: string);
  end;

var
  FData: TFData;

implementation

{$R *.dfm}

uses uLibrary, rOrders;

procedure TFData.FormCreate(Sender: TObject);
begin
  Timer1.Enabled := True;
end;


procedure TFData.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Screen.Cursor := crHourGlass;
  Memo1.Lines.Add( 'creating kgDB TApiDatabase...' );
  kgDB := TApiDatabase.Create(Self);
  Memo1.Lines.Add( '--kgDB TApiDatabase created!' );
  Screen.Cursor := crDefault;
end;


procedure TFData.btnPDFClick(Sender: TObject);
begin
  RunOrdersReport('&pagenumber=1&pagesize=50&orderby=');
end;


procedure TFData.btnFindClick(Sender: TObject);
// Retrieves calls from a specific number from the database.
// SQL: SQL statement to retrieve calls from the database
// whereSQL: where section of the SQL that is built in the function
var
  SQL: string;
  whereSQL: string;
begin
  Memo1.Lines.Add(uqUsers.Connection.Server);
  SQL := 'select * from users';
  uqUsers.Close;
  uqUsers.SQL.Text := sql;
  uqUsers.Open;

  DBAdvGrid1.AutoSizeColumns(true);
end;


procedure TFData.RunOrdersReport(searchOptions: string);
var
  rptOrders: TrptOrders;
begin
  rptOrders := TrptOrders.Create(nil);
  try
    rptOrders.PrepareReport(searchOptions);
    dsGrid2.DataSet := rptOrders.uqOrders;
  finally
    rptOrders.Free;
  end;
end;


end.
