unit uRemesasProveedorReportController;

interface

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

type
  IRemesasProveedorReportController = interface
  ['{A89AAA05-19AD-4455-BAF6-8A5373D15FE7}']
    procedure Preview(const ListaID : TIntegerList);
    function Print(const ListaID : TIntegerList): 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 ListaID : TIntegerList);
    function Print(const ListaID : TIntegerList): 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 ListaID : TIntegerList);
var
  AStream: Binary;
  AEditor : IEditorRemesasProveedorPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ListaID);
    try
      CreateEditor('EditorRemesasProveedorPreview', IEditorRemesasProveedorPreview, 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;

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

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ListaID);
    try
      CreateEditor('EditorRemesasProveedorPreview', IEditorRemesasProveedorPreview, AEditor);
      if Assigned(AEditor) then
        try
          AEditor.LoadFromStream(AStream);
          AEditor.TablaImpresion := nme_RemesasProveedor;
          AEditor.IdTablaImpresion := ListaID.ToString;
            Result := AEditor.Print;
        finally
          AEditor.Release;
        end;
    finally
      FreeAndNil(AStream);
    end;
  finally
    HideHourglassCursor;
  end;
end;

end.
