292 lines
7.9 KiB
ObjectPascal
292 lines
7.9 KiB
ObjectPascal
|
|
unit uInstaladoresController;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Classes, uCustomEditor,
|
|||
|
|
uContactosController, uBizContactos,
|
|||
|
|
uIEditorInstaladores, uIEditorInstalador, uIDataModuleContactos, uIDataModuleInstaladores;
|
|||
|
|
|
|||
|
|
const
|
|||
|
|
CTE_INSTALADOR = 'Instalador';
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IInstaladoresController = interface(IContactosController)
|
|||
|
|
['{EB88FC03-720E-47FA-9864-11BB096DDD35}']
|
|||
|
|
function EsEliminable(AInstalador: IBizContacto): Boolean;
|
|||
|
|
function Eliminar(AInstalador: IBizContacto; AllItems: Boolean = false): Boolean; overload;
|
|||
|
|
function DarListaInstaladores : TStringList;
|
|||
|
|
function BuscarTodos: IBizContacto; overload;
|
|||
|
|
function BuscarTodos(const CadenaIDs: String): IBizContacto; overload;
|
|||
|
|
// function DarIDInstaladorDeUsuario(const AUsuario: Integer): Integer;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TInstaladoresController = class(TContactosController, IInstaladoresController)
|
|||
|
|
public
|
|||
|
|
constructor Create; override;
|
|||
|
|
function Duplicar(AContacto: IBizContacto): IBizContacto; override;
|
|||
|
|
function Buscar(const ID: Integer): IBizContacto; override;
|
|||
|
|
function BuscarTodos: IBizContacto; overload; override;
|
|||
|
|
function BuscarTodos(const CadenaIDs: String): IBizContacto; overload;
|
|||
|
|
function Nuevo : IBizContacto; override;
|
|||
|
|
procedure Ver(AContacto : IBizContacto); override;
|
|||
|
|
procedure VerTodos(AContactos: IBizContacto); override;
|
|||
|
|
function ElegirContacto(AContactos : IBizContacto;
|
|||
|
|
AMensaje: String; AMultiSelect: Boolean): IBizContacto; override;
|
|||
|
|
|
|||
|
|
function DarListaInstaladores : TStringList;
|
|||
|
|
|
|||
|
|
function Eliminar(AInstalador: IBizContacto; AllItems: Boolean = false): Boolean; overload;
|
|||
|
|
function EsEliminable(AInstalador: IBizContacto): Boolean;
|
|||
|
|
// function DarIDInstaladorDeUsuario(const AUsuario: Integer): Integer;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, SysUtils, Controls, cxControls, Dialogs, uDataModuleInstaladores, uEditorRegistryUtils,
|
|||
|
|
uDataTableUtils, uDADataTable, DB, schContactosClient_Intf,
|
|||
|
|
uEditorGridBase, uDAInterfaces, uIEditorElegirInstaladores;
|
|||
|
|
|
|||
|
|
{ TInstaladorController }
|
|||
|
|
|
|||
|
|
function TInstaladoresController.Buscar(const ID: Integer): IBizContacto;
|
|||
|
|
begin
|
|||
|
|
Result := (FDataModule as IDataModuleInstaladores).GetItem(ID);
|
|||
|
|
FiltrarEmpresa(Result);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.BuscarTodos: IBizContacto;
|
|||
|
|
begin
|
|||
|
|
Result := (FDataModule as IDataModuleInstaladores).GetItems;
|
|||
|
|
FiltrarEmpresa(Result);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.BuscarTodos(const CadenaIDs: String): IBizContacto;
|
|||
|
|
var
|
|||
|
|
Cadena : TStringList;
|
|||
|
|
Condicion: TDAWhereExpression;
|
|||
|
|
i: Integer;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
Result := BuscarTodos;
|
|||
|
|
|
|||
|
|
if (Length(CadenaIDs) > 0) then
|
|||
|
|
begin
|
|||
|
|
Cadena := TStringList.Create;
|
|||
|
|
Cadena.CommaText := CadenaIDs;
|
|||
|
|
|
|||
|
|
//Vamos generando todas las where de cada uno de los ID recibidos
|
|||
|
|
for i := 0 to Cadena.Count - 1 do
|
|||
|
|
with Result.DataTable.DynamicWhere do
|
|||
|
|
begin
|
|||
|
|
//Todas aquellos Instaladores que no esten asociados a la liquidaci<63>n actual
|
|||
|
|
Condicion := NewBinaryExpression(NewField('', fld_InstaladoresID), NewConstant(StrToInt(Cadena.Strings[i]), datInteger), dboNotEqual);
|
|||
|
|
|
|||
|
|
if IsEmpty then
|
|||
|
|
Expression := Condicion
|
|||
|
|
else
|
|||
|
|
Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
Cadena.Free;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TInstaladoresController.Create;
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FDataModule := TDataModuleInstaladores.Create(Nil);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
{function TInstaladoresController.DarIDInstaladorDeUsuario(
|
|||
|
|
const AUsuario: Integer): Integer;
|
|||
|
|
var
|
|||
|
|
AInstaladores: IBizInstalador;
|
|||
|
|
begin
|
|||
|
|
AInstaladores := (BuscarTodos as IBizInstalador);
|
|||
|
|
AInstaladores.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
with AInstaladores.DataTable do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
if (AInstaladores.ID_USUARIO = AUsuario) then
|
|||
|
|
begin
|
|||
|
|
Result := AInstaladores.ID;
|
|||
|
|
Break;
|
|||
|
|
end
|
|||
|
|
else Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end; }
|
|||
|
|
|
|||
|
|
function TInstaladoresController.DarListaInstaladores: TStringList;
|
|||
|
|
var
|
|||
|
|
AInstaladores: IBizContacto;
|
|||
|
|
begin
|
|||
|
|
AInstaladores := BuscarTodos;
|
|||
|
|
AInstaladores.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
Result := TStringList.Create;
|
|||
|
|
try
|
|||
|
|
with Result do
|
|||
|
|
begin
|
|||
|
|
AInstaladores.DataTable.First;
|
|||
|
|
while not AInstaladores.DataTable.EOF do
|
|||
|
|
begin
|
|||
|
|
Add(Format('%s=%d', [AInstaladores.NOMBRE, AInstaladores.ID]));
|
|||
|
|
AInstaladores.DataTable.Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AInstaladores := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.Duplicar(AContacto: IBizContacto): IBizContacto;
|
|||
|
|
begin
|
|||
|
|
Result := inherited Duplicar(AContacto);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.ElegirContacto(AContactos: IBizContacto;
|
|||
|
|
AMensaje: String; AMultiSelect: Boolean): IBizContacto;
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorElegirInstaladores;
|
|||
|
|
begin
|
|||
|
|
Result := NIL;
|
|||
|
|
|
|||
|
|
CreateEditor('EditorElegirInstaladores', IEditorElegirInstaladores, AEditor);
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.Contactos := AContactos;
|
|||
|
|
AEditor.Controller := Self;
|
|||
|
|
AEditor.MultiSelect := AMultiSelect;
|
|||
|
|
AEditor.Mensaje := AMensaje;
|
|||
|
|
if IsPositiveResult(AEditor.ShowModal) then
|
|||
|
|
Result := AEditor.ContactosSeleccionados;
|
|||
|
|
finally
|
|||
|
|
AEditor.Release;
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.Eliminar(AInstalador: IBizContacto; AllItems: Boolean = false): Boolean;
|
|||
|
|
//En el caso de eliminar almenos un elemento del conjunto se devuelve true
|
|||
|
|
var
|
|||
|
|
bEliminado: Boolean;
|
|||
|
|
begin
|
|||
|
|
bEliminado := False;
|
|||
|
|
|
|||
|
|
if not Assigned(AInstalador) then
|
|||
|
|
raise Exception.Create ('Contacto no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if not AInstalador.DataTable.Active then
|
|||
|
|
AInstalador.DataTable.Active := True;
|
|||
|
|
|
|||
|
|
if (AInstalador.State in dsEditModes) then
|
|||
|
|
AInstalador.Cancel;
|
|||
|
|
|
|||
|
|
//Siempre eliminaremos el seleccionado
|
|||
|
|
if EsEliminable(AInstalador) then
|
|||
|
|
begin
|
|||
|
|
AInstalador.Delete;
|
|||
|
|
bEliminado := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
//En el caso de querer eliminar todos los items del objeto AInstalador
|
|||
|
|
if AllItems then
|
|||
|
|
begin
|
|||
|
|
with AInstalador.DataTable do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
if EsEliminable(AInstalador) then
|
|||
|
|
begin
|
|||
|
|
AInstalador.Delete;
|
|||
|
|
bEliminado := True
|
|||
|
|
end
|
|||
|
|
else Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if bEliminado then
|
|||
|
|
begin
|
|||
|
|
AInstalador.DataTable.ApplyUpdates;
|
|||
|
|
Result := True;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.EsEliminable(AInstalador: IBizContacto): Boolean;
|
|||
|
|
begin
|
|||
|
|
if not Assigned(AInstalador) then
|
|||
|
|
raise Exception.Create ('Contacto no asignado: EsEliminable');
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TInstaladoresController.Nuevo: IBizContacto;
|
|||
|
|
var
|
|||
|
|
AContacto : IBizInstalador;
|
|||
|
|
begin
|
|||
|
|
AContacto := (FDataModule as IDataModuleInstaladores).NewItem;
|
|||
|
|
FiltrarEmpresa(AContacto);
|
|||
|
|
AContacto.DataTable.Active := True;
|
|||
|
|
AContacto.Insert;
|
|||
|
|
Result := AContacto;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TInstaladoresController.Ver(AContacto: IBizContacto);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorInstalador;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
|
|||
|
|
CreateEditor('EditorInstalador', IEditorInstalador, AEditor);
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.Contacto := AContacto;
|
|||
|
|
AEditor.Controller := Self;
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
finally
|
|||
|
|
AEditor.Release;
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TInstaladoresController.VerTodos(AContactos: IBizContacto);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorInstaladores;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
|
|||
|
|
CreateEditor('EditorInstaladores', IEditorInstaladores, AEditor);
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Contactos := AContactos;
|
|||
|
|
Controller := Self;
|
|||
|
|
MultiSelect := True;
|
|||
|
|
ShowEmbedded;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|