unit uFacturasProveedorReportController; interface uses Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleFacturasProveedorReport, uClientesController, uDetallesFacturaProveedorController, uBizFacturasProveedor; type IFacturasProveedorReportController = interface ['{551F82DC-B8DC-482E-A20D-15003E845078}'] procedure Preview(const AFacturaID : String); procedure Print(const AFacturaID : String); end; TFacturasProveedorReportController = class(TInterfacedObject, IFacturasProveedorReportController) private FDataModule : IDataModuleFacturasProveedorReport; function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; public constructor Create; destructor Destroy; override; procedure Preview(const AFacturaID : String); procedure Print(const AFacturaID : String); end; implementation uses uROTypes, uEditorRegistryUtils, uIEditorFacturasProveedorPreview, uEditorPreview, uDataModuleFacturasProveedor, uEditorBase, cxControls; { TFacturasProveedorReportController } constructor TFacturasProveedorReportController.Create; begin FDataModule := TDataModuleFacturasProveedor.Create(Nil); end; function TFacturasProveedorReportController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; destructor TFacturasProveedorReportController.Destroy; begin FDataModule := NIL; inherited; end; procedure TFacturasProveedorReportController.Preview(const AFacturaID : String); var AStream: Binary; AEditor : IEditorFacturasProveedorPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AFacturaID); try CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor); if Assigned(AEditor) then with AEditor do begin LoadFromStream(AStream); Preview; Release; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; procedure TFacturasProveedorReportController.Print(const AFacturaID : String); var AStream: Binary; AEditor : IEditorFacturasProveedorPreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetReport(AFacturaID); try CreateEditor('EditorFacturasProveedorPreview', IEditorFacturasProveedorPreview, AEditor); if Assigned(AEditor) then with AEditor do begin LoadFromStream(AStream); Print; Release; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; end.