unit UserLogin_u;

interface

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

type
  TfrmUserLogin = class(TForm)
    edtUsername: TEdit;
    edtPassword: TEdit;
    btnLogin: TButton;
    logo: TImage;
    Label1: TLabel;
    procedure edtPasswordDblClick(Sender: TObject);
    procedure edtUsernameDblClick(Sender: TObject);
    procedure btnLoginClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    var
    Closed : Boolean;

  end;

var
  frmUserLogin: TfrmUserLogin;

implementation

{$R *.dfm}

procedure TfrmUserLogin.btnLoginClick(Sender: TObject);
var
  sUsername, sPassword : string;
  iUser : Integer;
  bolAdmin : Boolean;
begin
  sUsername:= edtUsername.Text;
  sPassword:= edtPassword.Text;
  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 = False then
        begin
          frmUserPage.Show;
          frmUserLogin.Hide;
        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 TfrmUserLogin.edtUsernameDblClick(Sender: TObject);
begin
  edtUsername.Text:='';
end;

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

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

end.
