314 lines
8.4 KiB
ObjectPascal
314 lines
8.4 KiB
ObjectPascal
|
|
unit uUsuariosController;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Classes, SysUtils, uDADataTable, uControllerBase,
|
|||
|
|
uIDataModuleUsuarios, uDataModuleUsuarios, UCBase;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IUsuariosController = interface(IObservador)
|
|||
|
|
['{DD963EEC-5880-4DE7-AF55-B5080B538D84}']
|
|||
|
|
|
|||
|
|
{procedure Logoff;
|
|||
|
|
procedure Execute;
|
|||
|
|
procedure StartLogin;
|
|||
|
|
procedure ShowUserManager;
|
|||
|
|
procedure ShowProfileManager;
|
|||
|
|
procedure ShowLogManager;
|
|||
|
|
procedure ShowChangePassword;
|
|||
|
|
procedure ChangeUser(IDUser: Integer; Login, Name, Mail: String; Profile,UserExpired,UserDaysSun: Integer; PrivUser: Boolean);
|
|||
|
|
procedure ChangePassword(IDUser: Integer; NewPassword: String);
|
|||
|
|
procedure AddRight(idUser: Integer; ItemRight: TObject; FullPath: Boolean = True); overload;
|
|||
|
|
procedure AddRight(idUser: Integer; ItemRight: String); overload;
|
|||
|
|
procedure AddRightEX(idUser: Integer; Module, FormName, ObjName: String);
|
|||
|
|
function VerificaLogin(User, Password: String): Boolean;
|
|||
|
|
function GetLocalUserName: String;
|
|||
|
|
function GetLocalComputerName: String;
|
|||
|
|
function AddUser(Login, Password, Name, Mail: String; Profile , UserExpired , DaysExpired : Integer; PrivUser: Boolean): Integer;
|
|||
|
|
function ExisteUsuario(Login: String): Boolean;
|
|||
|
|
property CurrentUser: TUCCurrentUser read FCurrentUser write FCurrentUser;
|
|||
|
|
property CurrentEmpresa : TEmpresaDef read FEmpresaAtual write FEmpresaAtual;
|
|||
|
|
property UserSettings: TUCUserSettings read FUserSettings write SetUserSettings;}
|
|||
|
|
|
|||
|
|
{ function BuscarTodos: IBizFormaPago;
|
|||
|
|
function Buscar(ID: Integer): IBizFormaPago;
|
|||
|
|
procedure VerTodos(AUsuarios: IBizFormaPago);
|
|||
|
|
procedure Ver(AFormaPago: IBizFormaPago);
|
|||
|
|
procedure Anadir(AFormaPago : IBizFormaPago);
|
|||
|
|
function Eliminar(AFormaPago : IBizFormaPago): Boolean;
|
|||
|
|
function Guardar(AFormaPago : IBizFormaPago): Boolean;
|
|||
|
|
procedure DescartarCambios(AFormaPago : IBizFormaPago);
|
|||
|
|
function Localizar(AUsuarios: IBizFormaPago; ADescripcion:String): Boolean;
|
|||
|
|
function DarListaUsuarios: TStringList;}
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TUsuariosController = class(TObservador, IUsuariosController)
|
|||
|
|
protected
|
|||
|
|
FDataModule : IDataModuleUsuarios;
|
|||
|
|
FUserControl: TUserControl;
|
|||
|
|
|
|||
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|||
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
|
|||
|
|
// function ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean;
|
|||
|
|
procedure AsignarDataModule;
|
|||
|
|
procedure InicializarUserControl;
|
|||
|
|
public
|
|||
|
|
constructor Create; virtual;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
|
|||
|
|
{ function Eliminar(AFormaPago : IBizFormaPago): Boolean;
|
|||
|
|
function Guardar(AFormaPago : IBizFormaPago): Boolean; virtual;
|
|||
|
|
procedure DescartarCambios(AFormaPago : IBizFormaPago); virtual;
|
|||
|
|
procedure Anadir(AFormaPago : IBizFormaPago);
|
|||
|
|
function BuscarTodos: IBizFormaPago;
|
|||
|
|
function Buscar(ID: Integer): IBizFormaPago;
|
|||
|
|
procedure VerTodos(AUsuarios: IBizFormaPago);
|
|||
|
|
procedure Ver(AFormaPago: IBizFormaPago);
|
|||
|
|
function Localizar(AUsuarios: IBizFormaPago; ADescripcion:String): Boolean;
|
|||
|
|
function DarListaUsuarios: TStringList;}
|
|||
|
|
|
|||
|
|
published
|
|||
|
|
property UserControl : TUserControl read FUserControl;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
cxControls, DB, uEditorRegistryUtils, schUsuariosClient_Intf,
|
|||
|
|
uDAInterfaces, uDataTableUtils, uDialogUtils,
|
|||
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows;
|
|||
|
|
|
|||
|
|
{ TUsuariosController }
|
|||
|
|
|
|||
|
|
{procedure TUsuariosController.Anadir(AFormaPago: IBizFormaPago);
|
|||
|
|
begin
|
|||
|
|
AFormaPago.Insert;
|
|||
|
|
end;}
|
|||
|
|
|
|||
|
|
procedure TUsuariosController.AsignarDataModule;
|
|||
|
|
begin
|
|||
|
|
FDataModule := TDataModuleUsuarios.Create(Nil);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{function TUsuariosController.Buscar(ID: Integer): IBizFormaPago;
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
Result := BuscarTodos;
|
|||
|
|
with Result.DataTable.Where do
|
|||
|
|
begin
|
|||
|
|
if NotEmpty then
|
|||
|
|
AddOperator(opAND);
|
|||
|
|
OpenBraket;
|
|||
|
|
AddText(fld_UsuariosID + ' = ' + IntToStr(ID));
|
|||
|
|
CloseBraket;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TUsuariosController.BuscarTodos: IBizFormaPago;
|
|||
|
|
begin
|
|||
|
|
Result := FDataModule.GetItems;
|
|||
|
|
end;}
|
|||
|
|
|
|||
|
|
constructor TUsuariosController.Create;
|
|||
|
|
begin
|
|||
|
|
AsignarDataModule;
|
|||
|
|
FUserControl := TUserControl.Create(nil);
|
|||
|
|
InicializarUserControl;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TUsuariosController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
function TUsuariosController.DarListaUsuarios: TStringList;
|
|||
|
|
var
|
|||
|
|
AUsuarios: IBizFormaPago;
|
|||
|
|
begin
|
|||
|
|
AUsuarios := BuscarTodos;
|
|||
|
|
AUsuarios.DataTable.Active := True;
|
|||
|
|
Result := TStringList.Create;
|
|||
|
|
try
|
|||
|
|
with Result do
|
|||
|
|
begin
|
|||
|
|
AUsuarios.DataTable.First;
|
|||
|
|
while not AUsuarios.DataTable.EOF do
|
|||
|
|
begin
|
|||
|
|
Add(AUsuarios.DESCRIPCION);
|
|||
|
|
AUsuarios.DataTable.Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AUsuarios := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TUsuariosController.DescartarCambios(AFormaPago: IBizFormaPago);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(AFormaPago) then
|
|||
|
|
raise Exception.Create ('Forma de pago no asignada');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (AFormaPago.State in dsEditModes) then
|
|||
|
|
AFormaPago.Cancel;
|
|||
|
|
|
|||
|
|
AFormaPago.DataTable.CancelUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
}
|
|||
|
|
destructor TUsuariosController.Destroy;
|
|||
|
|
begin
|
|||
|
|
FreeANDNIL(FUserControl);
|
|||
|
|
FDataModule := NIL;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
procedure TUsuariosController.InicializarUserControl;
|
|||
|
|
begin
|
|||
|
|
FDataModule.InicializarCamposUserControl(FUserControl);
|
|||
|
|
with FUserControl do
|
|||
|
|
begin
|
|||
|
|
Criptografia := cMD5;
|
|||
|
|
AutoStart := False;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
function TUsuariosController.ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(AFormaPago) then
|
|||
|
|
raise Exception.Create ('Forma de pago no asignada');
|
|||
|
|
|
|||
|
|
if (AFormaPago.DataTable.State in dsEditModes) then
|
|||
|
|
AFormaPago.DataTable.Post;
|
|||
|
|
|
|||
|
|
if Length(AFormaPago.REFERENCIA) = 0 then
|
|||
|
|
raise Exception.Create('Debe indicar una referencia para esta forma de pago.');
|
|||
|
|
|
|||
|
|
if Length(AFormaPago.DESCRIPCION) = 0 then
|
|||
|
|
raise Exception.Create('Debe indicar una descripci<63>n para esta forma de pago.');
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TUsuariosController.Ver(AFormaPago: IBizFormaPago);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorFormaPago;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
CreateEditor('EditorFormaPago', IEditorFormaPago, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
FormaPago := AFormaPago;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
AEditor.Release;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TUsuariosController.VerTodos(AUsuarios: IBizFormaPago);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorUsuarios;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
CreateEditor('EditorUsuarios', IEditorUsuarios, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
Usuarios := AUsuarios;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
AEditor.Release;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TUsuariosController.Eliminar(AFormaPago: IBizFormaPago): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(AFormaPago) then
|
|||
|
|
raise Exception.Create ('Forma de pago no asignada');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (AFormaPago.State in dsEditModes) then
|
|||
|
|
AFormaPago.Cancel;
|
|||
|
|
|
|||
|
|
AFormaPago.Delete;
|
|||
|
|
AFormaPago.DataTable.ApplyUpdates;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;}
|
|||
|
|
|
|||
|
|
procedure TUsuariosController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
//
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{function TUsuariosController.Guardar(AFormaPago: IBizFormaPago): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if ValidarFormaPago(AFormaPago) then
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
AFormaPago.DataTable.ApplyUpdates;
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TUsuariosController.Localizar(AUsuarios: IBizFormaPago; ADescripcion: String): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := True;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
with AUsuarios.DataTable do
|
|||
|
|
begin
|
|||
|
|
DisableControls;
|
|||
|
|
First;
|
|||
|
|
if not Locate(fld_UsuariosDESCRIPCION, ADescripcion, []) then
|
|||
|
|
Result := False;
|
|||
|
|
EnableControls;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;}
|
|||
|
|
|
|||
|
|
end.
|