227 lines
6.2 KiB
ObjectPascal
227 lines
6.2 KiB
ObjectPascal
|
|
unit uEditorUsuario;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, uEditorDBItem, JvAppStorage, JvAppRegistryStorage, DB, uDAInterfaces,
|
|||
|
|
uDADataTable, JvComponentBase, JvFormPlacement, ImgList, PngImageList,
|
|||
|
|
StdActns, ActnList, ComCtrls, JvExComCtrls, JvStatusBar, TBX, TB2Item,
|
|||
|
|
TB2Dock, TB2Toolbar, pngimage, ExtCtrls, JvExControls, JvNavigationPane,
|
|||
|
|
uIEditorUsuario, uUsuariosController, uCustomView, uViewBase, uViewUsuario,
|
|||
|
|
uBizUsuarios, dxLayoutLookAndFeels;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfEditorUsuario = class(TfEditorDBItem, IEditorUsuario)
|
|||
|
|
frViewUsuario1: TfrViewUsuario;
|
|||
|
|
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
|
|||
|
|
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
|
|||
|
|
actCambiarPassword: TAction;
|
|||
|
|
TBXSubmenuItem2: TTBXSubmenuItem;
|
|||
|
|
TBXItem7: TTBXItem;
|
|||
|
|
TBXSeparatorItem6: TTBXSeparatorItem;
|
|||
|
|
TBXItem33: TTBXItem;
|
|||
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|||
|
|
procedure actCambiarPasswordExecute(Sender: TObject);
|
|||
|
|
procedure actCambiarPasswordUpdate(Sender: TObject);
|
|||
|
|
private
|
|||
|
|
FController : IUsuariosController;
|
|||
|
|
FUsuario : IBizUsuario;
|
|||
|
|
FViewUsuario : IViewUsuario;
|
|||
|
|
protected
|
|||
|
|
function GetController : IUsuariosController;
|
|||
|
|
procedure SetController (const Value : IUsuariosController);
|
|||
|
|
|
|||
|
|
function GetUsuario: IBizUsuario;
|
|||
|
|
procedure SetUsuario(const Value: IBizUsuario);
|
|||
|
|
|
|||
|
|
procedure GuardarInterno; override;
|
|||
|
|
procedure EliminarInterno; override;
|
|||
|
|
procedure RefrescarInterno; override;
|
|||
|
|
|
|||
|
|
procedure PonerTitulos(const ATitulo: string = ''); override;
|
|||
|
|
|
|||
|
|
function GetViewUsuario: IViewUsuario;
|
|||
|
|
procedure SetViewUsuario(const Value: IViewUsuario);
|
|||
|
|
property ViewUsuario: IViewUsuario read GetViewUsuario write SetViewUsuario;
|
|||
|
|
public
|
|||
|
|
constructor Create(AOwner: TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
property Controller : IUsuariosController read GetController write SetController;
|
|||
|
|
property Usuario: IBizUsuario read GetUsuario write SetUsuario;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uDialogUtils, cxControls;
|
|||
|
|
|
|||
|
|
{ TfEditorUsuario }
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
FIDNuevoGuardado : Integer = -1;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.actCambiarPasswordExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FController.CambiarPassword(FUsuario.ID);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.actCambiarPasswordUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := not FUsuario.EsNuevo;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.actEliminarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if (Sender as TAction).Enabled then
|
|||
|
|
(Sender as TAction).Enabled := (FUsuario.PRIVILEGED = 0);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TfEditorUsuario.Create(AOwner: TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
pgPaginas.ActivePageIndex := 0;
|
|||
|
|
FViewUsuario := frViewUsuario1;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TfEditorUsuario.Destroy;
|
|||
|
|
begin
|
|||
|
|
// Utilizar mejor OnClose;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.EliminarInterno;
|
|||
|
|
begin
|
|||
|
|
if (ShowConfirmMessage('Eliminar un usuario', '<27>Desea borrar este usuario?') = IDYES) then
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if not FController.EliminarUsuario(FUsuario.ID) then
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorUsuario.GetController: IUsuariosController;
|
|||
|
|
begin
|
|||
|
|
Result := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorUsuario.GetUsuario: IBizUsuario;
|
|||
|
|
begin
|
|||
|
|
Result := FUsuario;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfEditorUsuario.GetViewUsuario: IViewUsuario;
|
|||
|
|
begin
|
|||
|
|
Result := FViewUsuario;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.GuardarInterno;
|
|||
|
|
var
|
|||
|
|
AMensaje : String;
|
|||
|
|
AContinuar : Boolean;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if FUsuario.EsNuevo then
|
|||
|
|
begin
|
|||
|
|
if (frViewUsuario1.ePassword.Text <> frViewUsuario1.eConfirmarPassword.Text) then
|
|||
|
|
raise Exception.Create('La contrase<73>a no se confirm<72> correctamente' + #10#13 +
|
|||
|
|
'Aseg<65>rese de que la contrase<73>a y su confirmaci<63>n sean iguales.')
|
|||
|
|
else
|
|||
|
|
if not FController.ValidarPassword(frViewUsuario1.ePassword.Text,
|
|||
|
|
frViewUsuario1.eUsuario.Text, frViewUsuario1.eNombre.Text, AMensaje) then
|
|||
|
|
raise Exception.Create(AMensaje)
|
|||
|
|
else begin
|
|||
|
|
FUsuario.Edit;
|
|||
|
|
FUsuario.PASS := frViewUsuario1.ePassword.Text;
|
|||
|
|
FUsuario.Edit;
|
|||
|
|
AContinuar := True;
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
AContinuar := True;
|
|||
|
|
|
|||
|
|
if AContinuar then
|
|||
|
|
begin
|
|||
|
|
if FController.GuardarUsuario(FUsuario) then
|
|||
|
|
begin
|
|||
|
|
FIDNuevoGuardado := FUsuario.ID;
|
|||
|
|
FUsuario.DataTable.CancelUpdates;
|
|||
|
|
Modified := False;
|
|||
|
|
actRefrescar.Execute;
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.PonerTitulos(const ATitulo: string);
|
|||
|
|
var
|
|||
|
|
FTitulo : String;
|
|||
|
|
begin
|
|||
|
|
if Assigned(Usuario) then
|
|||
|
|
begin
|
|||
|
|
if Usuario.EsNuevo then
|
|||
|
|
FTitulo := 'Nuevo usuario'
|
|||
|
|
else
|
|||
|
|
FTitulo := 'Usuario';
|
|||
|
|
|
|||
|
|
if Length(Usuario.USERNAME) > 0 then
|
|||
|
|
FTitulo := FTitulo + ' - ' + Usuario.USERNAME;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
inherited PonerTitulos(FTitulo);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.RefrescarInterno;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
|
|||
|
|
if (FIDNuevoGuardado > 0) and (FUsuario.ID <> FIDNuevoGuardado) then
|
|||
|
|
begin
|
|||
|
|
if (dsDataTable.DataTable.IsEmpty) or (not ModifiedQuery) then
|
|||
|
|
Exit; // No continuar con el refresco
|
|||
|
|
|
|||
|
|
dsDataTable.DataTable.DisableControls; //<- No descomentar
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
dsDataTable.DataTable.First;
|
|||
|
|
if dsDataTable.DataTable.Locate('ID', FIDNuevoGuardado, []) then
|
|||
|
|
FIDNuevoGuardado := -1;
|
|||
|
|
finally
|
|||
|
|
dsDataTable.DataTable.EnableControls; //<- No descomentar
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.SetController(const Value: IUsuariosController);
|
|||
|
|
begin
|
|||
|
|
FController := Value;
|
|||
|
|
if Assigned(FViewUsuario) and Assigned(FController) then
|
|||
|
|
FViewUsuario.Controller := FController;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.SetUsuario(const Value: IBizUsuario);
|
|||
|
|
begin
|
|||
|
|
FUsuario := Value;
|
|||
|
|
dsDataTable.DataTable := FUsuario.DataTable;
|
|||
|
|
|
|||
|
|
if Assigned(FViewUsuario) and Assigned(Usuario) then
|
|||
|
|
FViewUsuario.Usuario := Usuario;
|
|||
|
|
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfEditorUsuario.SetViewUsuario(const Value: IViewUsuario);
|
|||
|
|
begin
|
|||
|
|
FViewUsuario := Value;
|
|||
|
|
|
|||
|
|
if Assigned(FViewUsuario) and Assigned(Usuario) then
|
|||
|
|
FViewUsuario.Usuario := Usuario;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|