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_FactuGES/Source/Modulos/Pedidos de cliente/Controller/uPedidosClienteReportController.pas

136 lines
3.3 KiB
ObjectPascal

unit uPedidosClienteReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModulePedidosClienteReport,
uClientesController, uPedidosClienteController, uDetallesPedidoClienteController,
uBizPedidosCliente;
type
IPedidosClienteReportController = interface
['{D0686358-251C-43C4-9927-6112F2F4D3B8}']
procedure Preview(const AID : String);
function Print(const AID : String): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
TPedidosClienteReportController = class(TInterfacedObject, IPedidosClienteReportController)
private
FDataModule : IDataModulePedidosClienteReport;
function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
public
constructor Create;
destructor Destroy; override;
procedure Preview(const AID : String);
function Print(const AID : String): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
implementation
uses
uROTypes, uEditorRegistryUtils, uIEditorPedidosClientePreview,
uEditorPreview, uDataModulePedidosCliente, uEditorBase, cxControls,
schPedidosClienteClient_Intf, uStringsUtils;
{ TPedidosClienteReportController }
constructor TPedidosClienteReportController.Create;
begin
FDataModule := TDataModulePedidosCliente.Create(Nil);
end;
function TPedidosClienteReportController.CreateEditor(const AName: String;
const IID: TGUID; out Intf): Boolean;
begin
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;
destructor TPedidosClienteReportController.Destroy;
begin
FDataModule := NIL;
inherited;
end;
function TPedidosClienteReportController.ExportToPDF(const AID: Integer;
const AFileName: String): Boolean;
var
AStream: Binary;
begin
Result := False;
if EsCadenaVacia(AFileName) then
Exit;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPDF(AID, True);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TPedidosClienteReportController.Preview(const AID : String);
var
AStream: Binary;
AEditor : IEditorPedidosClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(AID, True);
try
CreateEditor('EditorPedidosClientePreview', IEditorPedidosClientePreview, AEditor);
AEditor.LoadFromStream(AStream);
finally
AStream.Free;
end;
finally
HideHourglassCursor;
end;
if Assigned(AEditor) then
AEditor.Preview;
end;
function TPedidosClienteReportController.Print(const AID : String): Boolean;
var
AStream: Binary;
AEditor : IEditorPedidosClientePreview;
begin
Result := False;
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetReport(AID);
try
CreateEditor('EditorPedidosClientePreview', IEditorPedidosClientePreview, AEditor);
AEditor.LoadFromStream(AStream);
finally
AStream.Free;
end;
finally
HideHourglassCursor;
end;
if Assigned(AEditor) then
begin
AEditor.TablaImpresion := nme_PedidosCliente;
AEditor.IdTablaImpresion := AID;
Result := AEditor.Print;
end;
end;
end.