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.
Noviseda_FactuGES2/Source/Modulos/Albaranes de cliente/Controller/uAlbaranesClienteReportController.pas
2010-01-28 14:06:34 +00:00

277 lines
7.4 KiB
ObjectPascal
Raw Blame History

unit uAlbaranesClienteReportController;
interface
uses
Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleAlbaranesClienteReport,
uClientesController, uAlbaranesClienteController, uDetallesAlbaranClienteController,
uBizAlbaranesCliente, uIntegerListUtils;
type
IAlbaranesClienteReportController = interface(IControllerBase)
['{4BCC7A93-3322-494C-A3FA-118F4B62CB15}']
procedure Preview(const AListaID : TIntegerList);
procedure Print(const AListaID : TIntegerList);
procedure EtiquetasPreview(const AListaID: TIntegerList);
procedure EtiquetasPrint(const AListaID: TIntegerList);
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
end;
TAlbaranesClienteReportController = class(TControllerBase, IAlbaranesClienteReportController)
private
FDataModule : IDataModuleAlbaranesClienteReport;
function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
public
constructor Create; override;
destructor Destroy; override;
procedure Preview(const AListaID : TIntegerList);
procedure Print(const AListaID : TIntegerList);
function ExportToWord(const AID: Integer; const AFileName : String = ''): Boolean;
function ExportToPDF(const AID: Integer; const AFileName : String = ''): Boolean;
procedure EtiquetasPreview(const AListaID: TIntegerList);
procedure EtiquetasPrint(const AListaID: TIntegerList);
end;
implementation
uses
uROTypes, Controls, uEditorRegistryUtils, uIEditorAlbaranesClientePreview,
uIEditorDetalleEtiqueta, uEditorPreview, uDataModuleAlbaranesCliente,
uEditorBase, cxControls, uStringsUtils, uSistemaFunc, uFactuGES_App;
{ TAlbaranesClienteReportController }
constructor TAlbaranesClienteReportController.Create;
begin
inherited;
FDataModule := TDataModuleAlbaranesCliente.Create(Nil);
end;
function TAlbaranesClienteReportController.CreateEditor(const AName: String;
const IID: TGUID; out Intf): Boolean;
begin
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;
destructor TAlbaranesClienteReportController.Destroy;
begin
FDataModule := NIL;
inherited;
end;
procedure TAlbaranesClienteReportController.EtiquetasPreview(const AListaID: TIntegerList);
var
AStream: Binary;
AEditorDetalle : IEditorDetalleEtiqueta;
AEditor : IEditorAlbaranesClientePreview;
Mercancia: String;
Bultos: Integer;
bAceptar: Boolean;
begin
AEditorDetalle := Nil;
AEditor := Nil;
CreateEditor('EditorDetalleEtiqueta', IEditorDetalleEtiqueta, AEditorDetalle);
if Assigned(AEditorDetalle) then
try
bAceptar := (AEditorDetalle.ShowModal = mrOk);
Mercancia := AEditorDetalle.Mercancia;
Bultos := AEditorDetalle.Bultos;
finally
AEditorDetalle.Release;
AEditorDetalle := NIL;
end;
if bAceptar then
begin
ShowHourglassCursor;
try
AStream := FDataModule.GetEtiquetas(AListaID, Mercancia, Bultos);
try
CreateEditor('EditorAlbaranesClientePreview', IEditorAlbaranesClientePreview, AEditor);
if Assigned(AEditor) then
try
AEditor.LoadFromStream(AStream);
AEditor.Preview;
finally
AEditor.Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
end;
procedure TAlbaranesClienteReportController.EtiquetasPrint(const AListaID: TIntegerList);
var
AStream: Binary;
AEditor : IEditorAlbaranesClientePreview;
AEditorDetalle : IEditorDetalleEtiqueta;
Mercancia: String;
Bultos: Integer;
bAceptar: Boolean;
begin
AEditorDetalle := Nil;
AEditor := NIL;
CreateEditor('EditorDetalleEtiqueta', IEditorDetalleEtiqueta, AEditorDetalle);
if Assigned(AEditorDetalle) then
try
bAceptar := (AEditorDetalle.ShowModal = mrOk);
Mercancia := AEditorDetalle.Mercancia;
Bultos := AEditorDetalle.Bultos;
finally
AEditorDetalle.Release;
AEditorDetalle := NIL;
end;
if bAceptar then
begin
ShowHourglassCursor;
try
AStream := FDataModule.GetEtiquetas(AListaID, Mercancia, Bultos);
try
CreateEditor('EditorAlbaranesClientePreview', IEditorAlbaranesClientePreview, AEditor);
if Assigned(AEditor) then
try
AEditor.LoadFromStream(AStream);
AEditor.Print;
finally
AEditor.Release;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
end;
function TAlbaranesClienteReportController.ExportToPDF(const AID: Integer;
const AFileName: String): Boolean;
var
AStream: Binary;
begin
Result := False;
if EsCadenaVacia(AFileName) then
Exit;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptPDFAlbaran(AID);
try
AStream.SaveToFile(AFileName);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
function TAlbaranesClienteReportController.ExportToWord(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.GetRptWordAlbaran(AID);
try
AStream.SaveToFile(AFile);
Result := True;
finally
FreeAndNil(AStream);
end;
finally
HideHourglassCursor;
end;
end;
procedure TAlbaranesClienteReportController.Preview(const AListaID : TIntegerList);
var
AStream: Binary;
AEditor : IEditorAlbaranesClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptAlbaranes(AListaID);
try
CreateEditor('EditorAlbaranesClientePreview', IEditorAlbaranesClientePreview, AEditor);
if Assigned(AEditor) then
begin
try
AEditor.Controller := Self;
AEditor.ListaID := AListaID;
AEditor.Title := 'Albar<61>n - ' + AppFactuGES.EmpresaActiva.NOMBRE;
AEditor.LoadFromStream(AStream);
AEditor.Preview;
finally
AEditor.Release;
end;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
procedure TAlbaranesClienteReportController.Print(const AListaID : TIntegerList);
var
AStream: Binary;
AEditor : IEditorAlbaranesClientePreview;
begin
AEditor := NIL;
ShowHourglassCursor;
try
AStream := FDataModule.GetRptAlbaranes(AListaID);
try
CreateEditor('EditorAlbaranesClientePreview', IEditorAlbaranesClientePreview, AEditor);
if Assigned(AEditor) then
begin
try
AEditor.Controller := Self;
AEditor.ListaID := AListaID;
AEditor.Title := 'Albar<61>n - ' + AppFactuGES.EmpresaActiva.NOMBRE;
AEditor.LoadFromStream(AStream);
AEditor.Print;
finally
AEditor.Release;
end;
end;
finally
FreeAndNil(AStream);
AEditor := Nil;
end;
finally
HideHourglassCursor;
end;
end;
end.