unit Ulogin;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    DBLookupComboBox1: TDBLookupComboBox;
    Label2: TLabel;
    Password: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DBLookupComboBox1CloseUp(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Udm, Uconexion, UPrincipal;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 if not (dm.Tusuario.Locate('Usuario;pass', vararrayof([DBLookupComboBox1.text, Password.Text]), [])) then
   messageDLG('Acceso Denegado',mterror,[mbok],0)
  else
   begin
    visible:=false;
    Fprincipal.caption:='Bienvenido al sistema de administración de datos de ProceSAR';
    Fprincipal.show;
   end
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
 application.Terminate;
end;

procedure TForm1.DBLookupComboBox1CloseUp(Sender: TObject);
begin
Password.SetFocus;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 if messagedlg('¿Desea Abandonar la aplicación?',mtconfirmation,[mbyes, mbno],0) = mryes then
   action:= cafree
 else
 action:= canone;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if not(conectarAccdb(dm.conector,'procesar','',application)) then
 begin
    messageDLG('Error de conexión con la BD', mterror, [mbok],0)
 end
 else
   dm.Tusuario.Active:= true
end;

end.
