unit AdminAdd_u;

interface

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

type
  TFrmAdminAdd = class(TForm)
    edtUsername: TEdit;
    edtPassword: TEdit;
    edtIDNum: TEdit;
    Panel1: TPanel;
    chkAdmin: TCheckBox;
    btnGeneratePass: TButton;
    btnAddUser: TButton;
    procedure btnGeneratePassClick(Sender: TObject);
    procedure edtUsernameDblClick(Sender: TObject);
    procedure edtIDNumDblClick(Sender: TObject);
    procedure edtIDNumEnter(Sender: TObject);
    procedure edtUsernameEnter(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnAddUserClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    var
      sRandomPass : string;
      iCount : Integer;
  end;

var
  FrmAdminAdd: TFrmAdminAdd;

implementation

{$R *.dfm}

procedure TFrmAdminAdd.btnAddUserClick(Sender: TObject);
var
  sUser, sPass, sID : string;
  iConfirm : Integer;
begin
  iConfirm:=0;
  sUser:='';
  sPass:='';
  sID:='';

  if Length(edtUsername.Text) >= 7  then
    sUser:= edtUsername.Text
  else
  begin
    ShowMessage('User Name must be 7 or more caractars');
    exit
  end;

  if Length(edtPassword.Text) = 12 then
    sPass:=edtPassword.Text
  else
  begin
    ShowMessage('Press Random pass generator');
    exit
  end;

  if Length(edtIDNum.Text) = 13 then
    sID:=edtIDNum.Text
  else
  begin
    ShowMessage('ID Number must be 13 digets long');
    exit
  end;

  DataUser.adoUser.Close;
  DataUser.adoUser.SQL.Clear;
  DataUser.adoUser.SQL.Add('INSERT INTO Login(Username,IDnum,pass) VALUES(:par0,:par1,:par2)');
  DataUser.adoUser.Parameters.ParamByName('par0').Value:=sUser;
  DataUser.adoUser.Parameters.ParamByName('par1').Value:=sID;
  DataUser.adoUser.Parameters.ParamByName('par2').Value:=sPass;
  iConfirm:= MessageDlg('Confirm Adding Acount', mtConfirmation, mbYesNo, 7);
  if iConfirm = 7 then exit;
  if iConfirm = 6 then DataUser.adoUser.ExecSQL;




end;

procedure TFrmAdminAdd.btnGeneratePassClick(Sender: TObject);
begin
  sRandomPass := '';
  iCount := 0;
  edtPassword.ReadOnly:=False;
  while iCount < 4 do
    begin
      sRandomPass:= sRandomPass + Chr(ord('0') + Random(10));
      sRandomPass:= sRandomPass + Chr(ord('a') + Random(26));
      sRandomPass:= sRandomPass + Chr(ord('A') + Random(26));
      iCount:= iCount + 1;
    end;
  edtPassword.ReadOnly:=True;
  edtPassword.Text:=sRandomPass;



end;

procedure TFrmAdminAdd.edtIDNumDblClick(Sender: TObject);
begin
  edtIDNum.Text:= '';
end;

procedure TFrmAdminAdd.edtIDNumEnter(Sender: TObject);
begin
  edtIDNum.Hint:= 'Dubbel tapp to clear';
  edtIDNum.ShowHint := True;
end;

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

procedure TFrmAdminAdd.edtUsernameEnter(Sender: TObject);
begin
  edtUsername.Hint:= 'Dubbel tap to clear';
  edtUsername.ShowHint:= True;
end;

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

end.
