unit AdminLogin_u;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Imaging.pngimage,
  Vcl.ExtCtrls, Login_u, AdminAdd_u, Vcl.Menus;

type
  TfrmAdminLogin = class(TForm)
    logo: TImage;
    Label1: TLabel;
    edtUsername: TEdit;
    edtPassword: TEdit;
    btnLogin: TButton;
    MainMenu1: TMainMenu;
    Cancel1: TMenuItem;
    procedure btnLoginClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Cancel1Click(Sender: TObject);
    procedure edtPasswordDblClick(Sender: TObject);
    procedure edtUsernameDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmAdminLogin: TfrmAdminLogin;

implementation

{$R *.dfm}

uses UserPage_u, UserLogin_u, Business_u;

procedure TfrmAdminLogin.btnLoginClick(Sender: TObject);
 var
  sUsername, sPassword : string;
  iUser : Integer;
  bolAdmin : Boolean;
begin
  sUsername:= edtUsername.Text;
  sPassword:= edtPassword.Text;
  DataUser.adoUser.Close;
  DataUser.adoUser.SQL.Clear;
  DataUser.adoUser.SQL.Add('SELECT ID, Admin FROM Login WHERE Username = :reg0 AND pass = :reg1');
  DataUser.adoUser.Parameters.ParamByName('reg0').Value:= sUsername;
  DataUser.adoUser.Parameters.ParamByName('reg1').Value:= sPassword;
  DataUser.adoUser.Open;
  iUser:= DataUser.adoUser.FieldByName('ID').AsInteger;
  bolAdmin := DataUser.adoUser.FieldByName('Admin').AsBoolean;
  //ShowMessage(IntToStr(iUser));

  if iUser > 0 then
    begin
      if bolAdmin = True then
        begin
          frmAdminLogin.Hide;
          FrmAdminAdd.show;
        end
      else
        begin
          ShowMessage('User is Admin pleas use Admin login page');
          exit
        end;


    end
  else
    begin
      ShowMessage('Username or Password incorect');
      DataUser.adoUser.Close;
      exit
    end;
end;

procedure TfrmAdminLogin.Cancel1Click(Sender: TObject);
begin
  frmBusiness.Show;
  edtUsername.Text:='Username';
  edtPassword.Text:='Password';
  frmAdminLogin.Hide;
end;

procedure TfrmAdminLogin.edtPasswordDblClick(Sender: TObject);
begin
  edtPassword.Text := '';
end;

procedure TfrmAdminLogin.edtUsernameDblClick(Sender: TObject);
begin
  edtUsername.Text:= '';
end;

procedure TfrmAdminLogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Application.Terminate;
end;

end.
