unit uPedidosProveedorReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModulePedidosProveedorReport,
  uClientesController, uPedidosProveedorController, uDetallesPedidoProveedorController,
  uBizPedidosProveedor;

type
  IPedidosProveedorReportController = interface
  ['{D0686358-251C-43C4-9927-6112F2F4D3B8}']
    procedure Preview(const AID : String);
    function Print(const AID : String): Boolean;
  end;

  TPedidosProveedorReportController = class(TInterfacedObject, IPedidosProveedorReportController)
  private
    FDataModule : IDataModulePedidosProveedorReport;
    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, uIEditorPedidosProveedorPreview,
  uEditorPreview, uDataModulePedidosProveedor, uEditorBase, cxControls,
  schPedidosProveedorClient_Intf;

{ TPedidosProveedorReportController }

constructor TPedidosProveedorReportController.Create;
begin
  FDataModule := TDataModulePedidosProveedor.Create(Nil);
end;

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


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

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

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

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

function TPedidosProveedorReportController.Print(const AID : String): boolean;
var
  AStream: Binary;
  AEditor : IEditorPedidosProveedorPreview;
begin
  Result := False;
  AEditor := NIL;

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

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

end.
