unit uAlbaranesProveedorReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleAlbaranesProveedorReport,
  uAlbaranesProveedorController, uDetallesAlbaranProveedorController,
  uBizAlbaranesProveedor;

type
  IAlbaranesProveedorReportController = interface
  ['{AAE252CE-D407-4FF4-AF2A-350C5A421C89}']
    procedure Preview(const AID : String);
    function Print(const AID : String): Boolean;
  end;

  TAlbaranesProveedorReportController = class(TInterfacedObject, IAlbaranesProveedorReportController)
  private
    FDataModule : IDataModuleAlbaranesProveedorReport;
    function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
  public
    constructor Create;
    destructor Destroy; override;

    procedure Preview(const AID : String);
    function Print(const AID : String): Boolean;
  end;


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorAlbaranesProveedorPreview,
  uEditorPreview, uDataModuleAlbaranesProveedor, uEditorBase, cxControls,
  schAlbaranesProveedorClient_Intf;

{ TAlbaranesProveedorReportController }

constructor TAlbaranesProveedorReportController.Create;
begin
  FDataModule := TDataModuleAlbaranesProveedor.Create(Nil);
end;

function TAlbaranesProveedorReportController.CreateEditor(const AName: String;
  const IID: TGUID; out Intf): Boolean;
begin
  Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;


destructor TAlbaranesProveedorReportController.Destroy;
begin
  FDataModule := NIL;
  inherited;
end;

procedure TAlbaranesProveedorReportController.Preview(const AID : String);
var
  AStream: Binary;
  AEditor : IEditorAlbaranesProveedorPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(AID);
    try
      CreateEditor('EditorAlbaranesProveedorPreview', IEditorAlbaranesProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

  if Assigned(AEditor) then
    AEditor.Preview;
end;

function TAlbaranesProveedorReportController.Print(const AID : String): Boolean;
var
  AStream: Binary;
  AEditor : IEditorAlbaranesProveedorPreview;
begin
  Result := False;
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(AID);
    try
      CreateEditor('EditorAlbaranesProveedorPreview', IEditorAlbaranesProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

  if Assigned(AEditor) then
  begin
    AEditor.TablaImpresion := nme_AlbaranesProveedor;
    AEditor.IdTablaImpresion := AID;
    Result := AEditor.Print;
  end;
end;

end.
