231 lines
6.2 KiB
ObjectPascal
231 lines
6.2 KiB
ObjectPascal
|
|
unit uGruposClienteController;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Classes, SysUtils, uDADataTable, uControllerBase, uEditorDBItem,
|
|||
|
|
uIDataModuleClientes, uBizGruposCliente;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
IGruposClienteController = interface(IObservador)
|
|||
|
|
['{32D31B02-76A6-4C9B-85D4-3C632969AC79}']
|
|||
|
|
function BuscarTodos: IBizGrupoCliente;
|
|||
|
|
procedure VerTodos(AGruposCliente: IBizGrupoCliente);
|
|||
|
|
procedure Anadir(AGrupoCliente : IBizGrupoCliente);
|
|||
|
|
function Eliminar(AGrupoCliente : IBizGrupoCliente): Boolean;
|
|||
|
|
function Guardar(AGrupoCliente : IBizGrupoCliente): Boolean;
|
|||
|
|
procedure DescartarCambios(AGrupoCliente : IBizGrupoCliente);
|
|||
|
|
function Localizar(AGruposCliente: IBizGrupoCliente; ADescripcion:String): Boolean;
|
|||
|
|
function DarListaGruposCliente: TStringList;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TGruposClienteController = class(TObservador, IGruposClienteController)
|
|||
|
|
protected
|
|||
|
|
FDataModule : IDataModuleClientes;
|
|||
|
|
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
|||
|
|
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
function ValidarGrupoCliente(AGrupoCliente: IBizGrupoCliente): Boolean;
|
|||
|
|
procedure AsignarDataModule; virtual;
|
|||
|
|
public
|
|||
|
|
constructor Create; virtual;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
|
|||
|
|
function Eliminar(AGrupoCliente : IBizGrupoCliente): Boolean;
|
|||
|
|
function Guardar(AGrupoCliente : IBizGrupoCliente): Boolean;
|
|||
|
|
procedure DescartarCambios(AGrupoCliente : IBizGrupoCliente); virtual;
|
|||
|
|
procedure Anadir(AGrupoCliente : IBizGrupoCliente);
|
|||
|
|
function BuscarTodos: IBizGrupoCliente;
|
|||
|
|
procedure VerTodos(AGruposCliente: IBizGrupoCliente);
|
|||
|
|
function Localizar(AGruposCliente: IBizGrupoCliente; ADescripcion:String): Boolean;
|
|||
|
|
function DarListaGruposCliente: TStringList;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
cxControls, DB, uEditorRegistryUtils,
|
|||
|
|
uIEditorGruposCliente, uDataModuleClientes,
|
|||
|
|
uDAInterfaces, uDataTableUtils,
|
|||
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows, schContactosClient_Intf;
|
|||
|
|
|
|||
|
|
{ TGruposClienteController }
|
|||
|
|
|
|||
|
|
procedure TGruposClienteController.Anadir(AGrupoCliente: IBizGrupoCliente);
|
|||
|
|
begin
|
|||
|
|
AGrupoCliente.Insert;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TGruposClienteController.AsignarDataModule;
|
|||
|
|
begin
|
|||
|
|
FDataModule := TDataModuleClientes.Create(Nil);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.BuscarTodos: IBizGrupoCliente;
|
|||
|
|
begin
|
|||
|
|
Result := FDataModule.GetGruposCliente;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TGruposClienteController.Create;
|
|||
|
|
begin
|
|||
|
|
AsignarDataModule;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.DarListaGruposCliente: TStringList;
|
|||
|
|
var
|
|||
|
|
AGruposCliente: IBizGrupoCliente;
|
|||
|
|
begin
|
|||
|
|
AGruposCliente := BuscarTodos;
|
|||
|
|
AGruposCliente.DataTable.Active := True;
|
|||
|
|
Result := TStringList.Create;
|
|||
|
|
try
|
|||
|
|
with Result do
|
|||
|
|
begin
|
|||
|
|
AGruposCliente.DataTable.First;
|
|||
|
|
while not AGruposCliente.DataTable.EOF do
|
|||
|
|
begin
|
|||
|
|
Add(AGruposCliente.DESCRIPCION);
|
|||
|
|
AGruposCliente.DataTable.Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
AGruposCliente := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TGruposClienteController.DescartarCambios(AGrupoCliente: IBizGrupoCliente);
|
|||
|
|
begin
|
|||
|
|
if not Assigned(AGrupoCliente) then
|
|||
|
|
raise Exception.Create ('GrupoCliente no asignado');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (AGrupoCliente.State in dsEditModes) then
|
|||
|
|
AGrupoCliente.Cancel;
|
|||
|
|
|
|||
|
|
AGrupoCliente.DataTable.CancelUpdates;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TGruposClienteController.Destroy;
|
|||
|
|
begin
|
|||
|
|
FDataModule := Nil;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.ValidarGrupoCliente(AGrupoCliente: IBizGrupoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(AGrupoCliente) then
|
|||
|
|
raise Exception.Create ('GrupoCliente no asignada');
|
|||
|
|
|
|||
|
|
if (AGrupoCliente.DataTable.State in dsEditModes) then
|
|||
|
|
AGrupoCliente.DataTable.Post;
|
|||
|
|
|
|||
|
|
if Length(AGrupoCliente.DESCRIPCION) = 0 then
|
|||
|
|
raise Exception.Create('Debe indicar al menos la descripci<63>n de este grupo.');
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TGruposClienteController.VerTodos(AGruposCliente: IBizGrupoCliente);
|
|||
|
|
var
|
|||
|
|
AEditor : IEditorGruposCliente;
|
|||
|
|
begin
|
|||
|
|
AEditor := NIL;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
CreateEditor('EditorGruposCliente', IEditorGruposCliente, AEditor);
|
|||
|
|
with AEditor do
|
|||
|
|
begin
|
|||
|
|
Controller := Self; //OJO ORDEN MUY IMPORTANTE
|
|||
|
|
GruposCliente := AGruposCliente;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if Assigned(AEditor) then
|
|||
|
|
try
|
|||
|
|
AEditor.ShowModal;
|
|||
|
|
AEditor.Release;
|
|||
|
|
finally
|
|||
|
|
AEditor := NIL;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.Eliminar(AGrupoCliente: IBizGrupoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if not Assigned(AGrupoCliente) then
|
|||
|
|
raise Exception.Create ('GrupoCliente no asignada');
|
|||
|
|
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (AGrupoCliente.State in dsEditModes) then
|
|||
|
|
AGrupoCliente.Cancel;
|
|||
|
|
|
|||
|
|
AGrupoCliente.Delete;
|
|||
|
|
AGrupoCliente.DataTable.ApplyUpdates;
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TGruposClienteController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
//
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.Guardar(AGrupoCliente: IBizGrupoCliente): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if ValidarGrupoCliente(AGrupoCliente) then
|
|||
|
|
begin
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
if (AGrupoCliente.DataTable.State in dsEditModes) then
|
|||
|
|
AGrupoCliente.DataTable.Post;
|
|||
|
|
|
|||
|
|
AGrupoCliente.DataTable.ApplyUpdates;
|
|||
|
|
|
|||
|
|
Result := True;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TGruposClienteController.Localizar(AGruposCliente: IBizGrupoCliente; ADescripcion: String): Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := True;
|
|||
|
|
ShowHourglassCursor;
|
|||
|
|
try
|
|||
|
|
with AGruposCliente.DataTable do
|
|||
|
|
begin
|
|||
|
|
DisableControls;
|
|||
|
|
First;
|
|||
|
|
if not Locate(fld_GruposClienteDESCRIPCION, ADescripcion, []) then
|
|||
|
|
Result := False;
|
|||
|
|
EnableControls;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
HideHourglassCursor;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|