unit uFacturasProformaReportController; interface uses Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFacturasProformaReport, uClientesController, uDetallesFacturaProformaController, uBizFacturasProforma, uIntegerListUtils; type IFacturasProformaReportController = interface(IControllerBase) ['{A0F41767-4FF6-4BAE-9FC9-894DD721D756}'] procedure Preview(const AListaID : TIntegerList); function Print(const AListaID : TIntegerList): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean; end; TFacturasProformaReportController = class(TControllerBase, IFacturasProformaReportController) private FDataModule : IDataModuleFacturasProformaReport; function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; public constructor Create; override; destructor Destroy; override; procedure Preview(const AListaID : TIntegerList); function Print(const AListaID : TIntegerList): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean; end; implementation uses uROTypes, uEditorRegistryUtils, uIEditorFacturasProformaPreview, uEditorPreview, uDataModuleFacturasProforma, uEditorBase, cxControls, uStringsUtils, uSistemaFunc, schFacturasProformaClient_Intf; { TFacturasProformaReportController } constructor TFacturasProformaReportController.Create; begin inherited; FDataModule := TDataModuleFacturasProforma.Create(Nil); end; function TFacturasProformaReportController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; destructor TFacturasProformaReportController.Destroy; begin FDataModule := NIL; inherited; end; function TFacturasProformaReportController.ExportToPDF(const AID: Integer; const AFileName: String = ''): Boolean; var AStream: Binary; begin Result := False; if EsCadenaVacia(AFileName) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptPDFFactura(AID); try AStream.SaveToFile(AFileName); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; procedure TFacturasProformaReportController.Preview(const AListaID : TIntegerList); var AStream: Binary; AEditor : IEditorFacturasProformaPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetRptFacturas(AListaID); try CreateEditor('EditorFacturasProformaPreview', IEditorFacturasProformaPreview, AEditor); if Assigned(AEditor) then try AEditor.Controller := Self; AEditor.ListaID := AListaID; AEditor.LoadFromStream(AStream); AEditor.Preview; finally AEditor.Release; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; function TFacturasProformaReportController.Print(const AListaID : TIntegerList): Boolean; var AStream: Binary; AEditor : IEditorFacturasProformaPreview; begin Result := False; AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetRptFacturas(AListaID); try CreateEditor('EditorFacturasProformaPreview', IEditorFacturasProformaPreview, AEditor); if Assigned(AEditor) then try AEditor.Controller := Self; AEditor.LoadFromStream(AStream); AEditor.TablaImpresion := nme_FacturasProforma; AEditor.IdTablaImpresion := AListaID.ToString; Result := AEditor.Print; finally AEditor.Release; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; end.