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 : integer);
    procedure Print(const AID : integer);
  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 : integer);
    procedure Print(const AID : integer);
  end;


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorPedidosProveedorPreview,
  uEditorPreview, uDataModulePedidosProveedor, uEditorBase, cxControls;

{ 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 : integer);
var
  AStream: Binary;
  AEditor : IEditorPedidosProveedorPreview;
begin
  AEditor := NIL;

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

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

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

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

  if Assigned(AEditor) then
    AEditor.Print
end;

end.
