unit uRemesasProveedorReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleRemesasProveedorReport,
  uBizRemesasProveedor;

type
  IRemesasProveedorReportController = interface
  ['{A89AAA05-19AD-4455-BAF6-8A5373D15FE7}']
    procedure Preview(const ID : String);
    function Print(const ID : String): Boolean;
  end;

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

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


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorRemesasProveedorPreview,
  uEditorPreview, uDataModuleRemesasProveedor, uEditorBase, cxControls,
  schRemesasProveedorClient_Intf;

{ TRemesasProveedorReportController }

constructor TRemesasProveedorReportController.Create;
begin
  FDataModule := TDataModuleRemesasProveedor.Create(Nil);
end;

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


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

procedure TRemesasProveedorReportController.Preview(const ID : String);
var
  AStream: Binary;
  AEditor : IEditorRemesasProveedorPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ID);
    try
      CreateEditor('EditorRemesasProveedorPreview', IEditorRemesasProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

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

function TRemesasProveedorReportController.Print(const ID : String): Boolean;
var
  AStream: Binary;
  AEditor : IEditorRemesasProveedorPreview;
begin
  Result := False;
  AEditor := NIL;

  ShowHourglassCursor;
  try
  AStream := FDataModule.GetReport(ID);
    try
      CreateEditor('EditorRemesasProveedorPreview', IEditorRemesasProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

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

end;

end.
