AbetoDesign_FactuGES2/Source/ApplicationBase/Empresas/Controller/uTiendasEmpresaController.pas

121 lines
2.9 KiB
ObjectPascal

unit uTiendasEmpresaController;
interface
uses
Windows, Forms, Classes, Controls, Contnrs, SysUtils, uDADataTable,
uIntegerListUtils, uBizEmpresasTiendas, uIDataModuleEmpresas, uControllerBase;
type
ITiendasEmpresaController = interface(IControllerBase)
['{5DCF4163-7FA0-4560-9E5E-FA2A99EA4F59}']
function Buscar(const ID: Integer): IBizEmpresaTienda;
function BuscarTodas: IBizEmpresaTienda;
procedure Ver(ATienda : IBizEmpresaTienda);
function Nueva : IBizEmpresaTienda;
end;
TTiendasEmpresaController = class(TControllerBase, ITiendasEmpresaController)
private
FDataModule : IDataModuleEmpresas;
function CrearTiendaTodas: IBizEmpresaTienda;
public
constructor Create; override;
destructor Destroy; override;
function Buscar(const ID: Integer): IBizEmpresaTienda;
function BuscarTodas: IBizEmpresaTienda;
procedure Ver(ATienda : IBizEmpresaTienda);
function Nueva : IBizEmpresaTienda;
end;
implementation
{ TTiendasEmpresaController }
uses
uDataModuleEmpresas, schEmpresasClient_Intf, uIEditorTiendaEmpresa,
uEditorRegistryUtils, cxControls, uFactuGES_App, uDataTableUtils;
function TTiendasEmpresaController.Buscar(const ID: Integer): IBizEmpresaTienda;
var
ATienda : IBizEmpresaTienda;
begin
Result := NIL;
if ID = CTE_ID_TODAS then
{ Si ID = 0 entonces hay que devolcer una tienda ficticia para
representar a todas las tiendas. }
ATienda := CrearTiendaTodas
else
ATienda := FDataModule.GetTienda(ID);
Result := ATienda;
end;
function TTiendasEmpresaController.BuscarTodas: IBizEmpresaTienda;
begin
Result := FDataModule.GetTiendas;
end;
constructor TTiendasEmpresaController.Create;
begin
inherited;
FDataModule := TDataModuleEmpresas.Create(Nil);
end;
destructor TTiendasEmpresaController.Destroy;
begin
FDataModule := Nil;
inherited;
end;
function TTiendasEmpresaController.Nueva: IBizEmpresaTienda;
begin
Result := FDataModule.NewTienda;
end;
procedure TTiendasEmpresaController.Ver(ATienda: IBizEmpresaTienda);
var
AEditor : IEditorTiendaEmpresa;
begin
AEditor := NIL;
CreateEditor('EditorTiendaEmpresa', IEditorTiendaEmpresa, AEditor);
if Assigned(AEditor) then
try
AEditor.Tienda := ATienda;
AEditor.Controller := Self;
AEditor.ShowModal;
finally
AEditor.Release;
AEditor := NIL;
end;
end;
function TTiendasEmpresaController.CrearTiendaTodas: IBizEmpresaTienda;
var
ATienda: IBizEmpresaTienda;
begin
ATienda := FDataModule.NewTienda;
ATienda.DataTable.Open;
DesconectarTabla(ATienda.DataTable);
try
ATienda.Edit;
try
ATienda.ID := CTE_ID_TODAS;
ATienda.ID_EMPRESA := AppFactuGES.EmpresaActiva.ID;
ATienda.NOMBRE := CTE_TODAS;
finally
ATienda.Post;
end;
finally
ConectarTabla(ATienda.DataTable);
end;
Result := ATienda;
end;
end.