Tecsitel_FactuGES2/Source/Modulos/Presupuestos de cliente/Controller/uPresupuestosClienteReportController.pas

145 lines
3.9 KiB
ObjectPascal

unit uPresupuestosClienteReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModulePresupuestosClienteReport,
uClientesController, uPresupuestosClienteController, uDetallesPresupuestoClienteController,
uBizPresupuestosCliente;
type
IPresupuestosClienteReportController = interface(IControllerBase)
['{D0686358-251C-43C4-9927-6112F2F4D3B8}']
procedure Preview(const AListaID : String);
procedure Print(const AListaID : String);
function ExportToWord(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;
destructor Destroy; override;
procedure Preview(const AListaID : String);
procedure Print(const AListaID : String);
function ExportToWord(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
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.ExportToWord(const AID: Integer; const AFileName : String) : Boolean;
var
AStream: Binary;
AFile : String;
begin
AFile := AFileName;
if EsCadenaVacia(AFile) and (not DarFicheroWordExportar(AFile)) then
Exit;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptWordPresupuesto(AID);
try
AStream.SaveToFile(AFile);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TPresupuestosClienteReportController.Preview(const AListaID : String);
var
AStream: Binary;
AEditor : IEditorPresupuestosClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPresupuestos(AListaID);
try
CreateEditor('EditorPresupuestosClientePreview', IEditorPresupuestosClientePreview, AEditor);
if Assigned(AEditor) then
with AEditor do
begin
AEditor.Controller := Self;
AEditor.ListaID := AListaID;
Title := 'Presupuesto - ' + AppFactuGES.EmpresaActiva.NOMBRE;
LoadFromStream(AStream);
Preview;
Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
procedure TPresupuestosClienteReportController.Print(const AListaID : String);
var
AStream: Binary;
AEditor : IEditorPresupuestosClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPresupuestos(AListaID);
try
CreateEditor('EditorPresupuestosClientePreview', IEditorPresupuestosClientePreview, AEditor);
if Assigned(AEditor) then
with AEditor do
begin
AEditor.Controller := Self;
AEditor.ListaID := AListaID;
AEditor.LoadFromStream(AStream);
AEditor.Print;
AEditor.Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
if Assigned(AEditor) then
end;
end.