This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Recibos de cliente/Controller/uRecibosClienteReportController.pas

150 lines
3.8 KiB
ObjectPascal

unit uRecibosClienteReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleRecibosClienteReport,
uBizRecibosCliente, uIntegerListUtils;
type
IRecibosClienteReportController = interface(IControllerBase)
['{3837DFA3-0A38-4BB2-B0DB-D0615249EA49}']
procedure Preview(const ListaID : TIntegerList);
function Print(const ListaID : TIntegerList): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
TRecibosClienteReportController = class(TControllerBase, IRecibosClienteReportController)
private
FDataModule : IDataModuleRecibosClienteReport;
function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
public
constructor Create; override;
destructor Destroy; override;
procedure Preview(const ListaID : TIntegerList);
function Print(const ListaID : TIntegerList): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
implementation
uses
uROTypes, uEditorRegistryUtils, uIEditorRecibosClientePreview,
uEditorPreview, uDataModuleRecibosCliente, uEditorBase, cxControls,
uFactuGES_App, uStringsUtils, uSistemaFunc, schRecibosClienteClient_Intf;
{ TRecibosClienteReportController }
constructor TRecibosClienteReportController.Create;
begin
inherited;
FDataModule := TDataModuleRecibosCliente.Create(Nil);
end;
function TRecibosClienteReportController.CreateEditor(const AName: String;
const IID: TGUID; out Intf): Boolean;
begin
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;
destructor TRecibosClienteReportController.Destroy;
begin
FDataModule := NIL;
inherited;
end;
function TRecibosClienteReportController.ExportToPDF(const AID: Integer; const AFileName: String): Boolean;
var
AStream: Binary;
begin
Result := False;
if EsCadenaVacia(AFileName) then
Exit;
ShowHourglassCursor;
try
// AStream := FDataModule.GetRptPDFRecibo(AID);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TRecibosClienteReportController.Preview(const ListaID : TIntegerList);
var
AStream: Binary;
AEditor : IEditorRecibosClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(ListaID);
try
CreateEditor('EditorRecibosClientePreview', IEditorRecibosClientePreview, AEditor);
if Assigned(AEditor) then
begin
try
AEditor.Controller := Self;
AEditor.ListaID := ListaID;
AEditor.LoadFromStream(AStream);
AEditor.Preview;
finally
AEditor.Release;
end;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
function TRecibosClienteReportController.Print(const ListaID : TIntegerList): Boolean;
var
AStream: Binary;
AEditor : IEditorRecibosClientePreview;
begin
Result := False;
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(ListaID);
try
CreateEditor('EditorRecibosClientePreview', IEditorRecibosClientePreview, AEditor);
if Assigned(AEditor) then
begin
try
AEditor.Controller := Self;
AEditor.ListaID := ListaID;
AEditor.LoadFromStream(AStream);
AEditor.TablaImpresion := nme_RecibosCliente;
AEditor.IdTablaImpresion := ListaID.ToString;
Result := AEditor.Print;
finally
AEditor.Release;
end;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
end.