unit uPresupuestosClienteReportController; interface uses Classes, SysUtils, uDADataTable, uControllerBase, uIDataModulePresupuestosClienteReport, uClientesController, uPresupuestosClienteController, uDetallesPresupuestoClienteController, uBizPresupuestosCliente, uIntegerListUtils; type IPresupuestosClienteReportController = interface(IControllerBase) ['{41AE4B36-6114-4DDE-8BCF-288AA0E12449}'] procedure Preview(const AListaID : TIntegerList; Const AVerSello: Integer); procedure Print(const AListaID : TIntegerList; Const AVerSello: Integer); function ExportToWord(const AID: Integer; const AFileName : String = ''; Const AVerSello: Integer=1): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''; Const AVerSello: Integer=1): Boolean; function GenerarCertificados(const AID: Integer; const AFileName : String): Boolean; end; TPresupuestosClienteReportController = class(TControllerBase, IPresupuestosClienteReportController) private FDataModule : IDataModulePresupuestosClienteReport; function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; public constructor Create; override; destructor Destroy; override; procedure Preview(const AListaID : TIntegerList; Const AVerSello: Integer); procedure Print(const AListaID : TIntegerList; Const AVerSello: Integer); function ExportToWord(const AID: Integer; const AFileName : String = ''; Const AVerSello: Integer=1): Boolean; function ExportToPDF(const AID: Integer; const AFileName : String = ''; Const AVerSello: Integer=1): Boolean; function GenerarCertificados(const AID: Integer; const AFileName : String): Boolean; end; implementation uses uROTypes, uEditorRegistryUtils, uIEditorPresupuestosClientePreview, uEditorPreview, uDataModulePresupuestosCliente, uEditorBase, cxControls, uFactuGES_App, uStringsUtils, uSistemaFunc; { TPresupuestosClienteReportController } constructor TPresupuestosClienteReportController.Create; begin inherited; FDataModule := TDataModulePresupuestosCliente.Create(Nil); end; function TPresupuestosClienteReportController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; destructor TPresupuestosClienteReportController.Destroy; begin FDataModule := NIL; inherited; end; function TPresupuestosClienteReportController.ExportToPDF(const AID: Integer; const AFileName: String; Const AVerSello: Integer): Boolean; var AStream: Binary; begin Result := False; if EsCadenaVacia(AFileName) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptPDFPresupuesto(AID, AVerSello); try AStream.SaveToFile(AFileName); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; function TPresupuestosClienteReportController.ExportToWord(const AID: Integer; const AFileName : String; Const AVerSello: Integer) : Boolean; var AStream: Binary; AFile : String; begin Result := False; AFile := AFileName; if EsCadenaVacia(AFile) and (not PreguntarFicheroWordExportar(AFile)) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptWordPresupuesto(AID, AVerSello); try AStream.SaveToFile(AFile); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; function TPresupuestosClienteReportController.GenerarCertificados( const AID: Integer; const AFileName : String): Boolean; var AStream: Binary; AFile : String; begin Result := False; AFile := AFileName; if EsCadenaVacia(AFile) and (not PreguntarFicheroWordExportar(AFile)) then Exit; ShowHourglassCursor; try AStream := FDataModule.GetRptWordCertificadoTrabajos(AID); try AStream.SaveToFile(AFile); Result := True; finally FreeAndNil(AStream); end; finally HideHourglassCursor; end; end; procedure TPresupuestosClienteReportController.Preview(const AListaID : TIntegerList; Const AVerSello: Integer); var AStream: Binary; AEditor : IEditorPresupuestosClientePreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetRptPresupuestos(AListaID, AVerSello); try CreateEditor('EditorPresupuestosClientePreview', IEditorPresupuestosClientePreview, AEditor); if Assigned(AEditor) then begin try AEditor.Controller := Self; AEditor.ListaID := AListaID; AEditor.Title := 'Presupuesto - ' + AppFactuGES.EmpresaActiva.NOMBRE; AEditor.LoadFromStream(AStream); AEditor.Preview; finally AEditor.Release; end; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; procedure TPresupuestosClienteReportController.Print(const AListaID : TIntegerList; Const AVerSello: Integer); var AStream: Binary; AEditor : IEditorPresupuestosClientePreview; begin AEditor := NIL; ShowHourglassCursor; try AStream := FDataModule.GetRptPresupuestos(AListaID, AVerSello); try CreateEditor('EditorPresupuestosClientePreview', IEditorPresupuestosClientePreview, AEditor); if Assigned(AEditor) then begin try AEditor.Controller := Self; AEditor.ListaID := AListaID; AEditor.Title := 'Presupuesto - ' + AppFactuGES.EmpresaActiva.NOMBRE; AEditor.LoadFromStream(AStream); AEditor.Print; finally AEditor.Release; end; end; finally FreeAndNil(AStream); AEditor := Nil; end; finally HideHourglassCursor; end; end; end.