git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@1062 0c75b7a4-871f-7646-8a2f-f78d34cc349f
172 lines
4.5 KiB
ObjectPascal
172 lines
4.5 KiB
ObjectPascal
unit uEditorLogin;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, StdCtrls, ExtCtrls, ComCtrls, cxGraphics, cxControls,
|
||
cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit,
|
||
cxImageComboBox, ImgList, PngImageList, pngimage, ToolWin, JvExControls,
|
||
JvComponent, JvGradient, JvGIF, JvComponentBase, JvFormPlacement,
|
||
JvAppStorage, JvAppRegistryStorage, uIEditorLogin, uUsuariosController,
|
||
ActnList;
|
||
|
||
type
|
||
TfEditorLogin = class(TForm, IEditorLogin)
|
||
Panel1: TPanel;
|
||
Label3: TLabel;
|
||
Label4: TLabel;
|
||
edtPassword: TEdit;
|
||
bAceptar: TButton;
|
||
bCancelar: TButton;
|
||
Label1: TLabel;
|
||
edtUser: TEdit;
|
||
JvGradient1: TJvGradient;
|
||
Button1: TButton;
|
||
Timer1: TTimer;
|
||
JvAppRegistryStorage1: TJvAppRegistryStorage;
|
||
JvFormStorage1: TJvFormStorage;
|
||
Image1: TImage;
|
||
cbConexiones: TComboBox;
|
||
Label2: TLabel;
|
||
ActionList1: TActionList;
|
||
actAceptar: TAction;
|
||
procedure ToolButton4Click(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure Timer1Timer(Sender: TObject);
|
||
procedure FormCreate(Sender: TObject);
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure edtUserKeyPress(Sender: TObject; var Key: Char);
|
||
procedure actAceptarExecute(Sender: TObject);
|
||
procedure actAceptarUpdate(Sender: TObject);
|
||
private
|
||
FController : IUsuariosController;
|
||
FIntentos : Integer;
|
||
function GetController : IUsuariosController;
|
||
procedure SetController (const AValue : IUsuariosController);
|
||
procedure RellenarConexiones;
|
||
published
|
||
property Controller : IUsuariosController read GetController write SetController;
|
||
end;
|
||
|
||
|
||
implementation
|
||
|
||
uses
|
||
uFactuGES_App, uDataModuleConexion;
|
||
|
||
{$R *.dfm}
|
||
|
||
const
|
||
NO_CONEXIONES = '<No hay conexiones>';
|
||
|
||
{
|
||
********************************* TfEditorLogin **********************************
|
||
}
|
||
procedure TfEditorLogin.actAceptarExecute(Sender: TObject);
|
||
var
|
||
bOk : Boolean;
|
||
begin
|
||
Timer1.Enabled := False;
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
dmConexion.EstablecerConexion(cbConexiones.ItemIndex);
|
||
bOK := FController.ComprobarUsuario(edtUser.Text, edtPassword.Text);
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
|
||
if bOk then
|
||
ModalResult := mrOK
|
||
else begin
|
||
Application.MessageBox('Usuario no v<>lido. Compruebe si ha escrito correctamente'
|
||
+ #13 + #10 + 'el usuario y la contrase<73>a.', 'Atenci<63>n', MB_OK);
|
||
Inc(FIntentos);
|
||
if (Controller.MaxIntentosLogin > 0) and (FIntentos = Controller.MaxIntentosLogin) then
|
||
ModalResult := mrCancel;
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorLogin.actAceptarUpdate(Sender: TObject);
|
||
begin
|
||
(Sender as TAction).Enabled := (cbConexiones.Items.IndexOf(NO_CONEXIONES) = -1);
|
||
end;
|
||
|
||
procedure TfEditorLogin.ToolButton4Click(Sender: TObject);
|
||
var
|
||
ATimer : Boolean;
|
||
begin
|
||
ATimer := False;
|
||
if Timer1.Enabled then
|
||
begin
|
||
ATimer := True;
|
||
Timer1.Enabled := False;
|
||
end;
|
||
|
||
dmConexion.ConfigurarConexion;
|
||
RellenarConexiones;
|
||
|
||
if ATimer then
|
||
Timer1.Enabled := True;
|
||
end;
|
||
|
||
procedure TfEditorLogin.edtUserKeyPress(Sender: TObject; var Key: Char);
|
||
begin
|
||
// Desactivar el timer cuando el usuario empieza a escribir
|
||
Timer1.Enabled := False;
|
||
end;
|
||
|
||
procedure TfEditorLogin.FormCreate(Sender: TObject);
|
||
begin
|
||
FIntentos := 0;
|
||
end;
|
||
|
||
procedure TfEditorLogin.FormDestroy(Sender: TObject);
|
||
begin
|
||
FController := NIL;
|
||
end;
|
||
|
||
procedure TfEditorLogin.FormShow(Sender: TObject);
|
||
begin
|
||
Self.Caption := AppFactuGES.AppFullName;
|
||
JvFormStorage1.RestoreFormPlacement;
|
||
RellenarConexiones;
|
||
|
||
// Hacer login autom<6F>tica si hay usuario/password y no hay m<>s de una base
|
||
// de datos como opci<63>n para conectarse.
|
||
if ((cbConexiones.Items.Count > 0) and (Length(edtUser.Text) > 0) and (Length(edtPassword.Text) > 0)) then
|
||
Timer1.Enabled := True;
|
||
end;
|
||
|
||
function TfEditorLogin.GetController: IUsuariosController;
|
||
begin
|
||
Result := FController;
|
||
end;
|
||
|
||
procedure TfEditorLogin.RellenarConexiones;
|
||
begin
|
||
cbConexiones.Clear;
|
||
cbConexiones.Items := dmConexion.ListaConexiones;
|
||
|
||
if cbConexiones.Items.Count > 0 then
|
||
cbConexiones.ItemIndex := 0
|
||
else begin
|
||
cbConexiones.Items.Add(NO_CONEXIONES);
|
||
cbConexiones.ItemIndex := 0
|
||
end;
|
||
end;
|
||
|
||
procedure TfEditorLogin.SetController(const AValue: IUsuariosController);
|
||
begin
|
||
FController := AValue;
|
||
end;
|
||
|
||
procedure TfEditorLogin.Timer1Timer(Sender: TObject);
|
||
begin
|
||
Timer1.Enabled := False;
|
||
bAceptar.Click;
|
||
end;
|
||
|
||
end.
|