unit uRemesasClienteReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleRemesasClienteReport,
  uBizRemesasCliente, uIntegerListUtils;

type
  IRemesasClienteReportController = interface(IControllerBase)
  ['{EA6EAD10-E07B-45A9-9B5E-0D560E2B92DF}']
    procedure Preview(const ListaID : TIntegerList);
    procedure Print(const ListaID : TIntegerList);
  end;

  TRemesasClienteReportController = class(TControllerBase, IRemesasClienteReportController)
  private
    FDataModule : IDataModuleRemesasClienteReport;
    function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
  public
    constructor Create;
    destructor Destroy; override;

    procedure Preview(const ListaID : TIntegerList);
    procedure Print(const ListaID : TIntegerList);
  end;


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorRemesasClientePreview,
  uEditorPreview, uDataModuleRemesasCliente, uEditorBase, cxControls;

{ TRemesasClienteReportController }

constructor TRemesasClienteReportController.Create;
begin
  FDataModule := TDataModuleRemesasCliente.Create(Nil);
end;

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


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

procedure TRemesasClienteReportController.Preview(const ListaID : TIntegerList);
var
  AStream: Binary;
  AEditor : IEditorRemesasClientePreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ListaID);
    try
      CreateEditor('EditorRemesasClientePreview', IEditorRemesasClientePreview, AEditor);
      if Assigned(AEditor) then
      begin
        try
          AEditor.Controller := Self;
          AEditor.ListaID := ListaID;
          AEditor.LoadFromStream(AStream);
          AEditor.Preview;
        finally
          AEditor.Release;
        end;
      end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;
end;

procedure TRemesasClienteReportController.Print(const ListaID : TIntegerList);
var
  AStream: Binary;
  AEditor : IEditorRemesasClientePreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ListaID);
    try
      CreateEditor('EditorRemesasClientePreview', IEditorRemesasClientePreview, AEditor);
      if Assigned(AEditor) then
      begin
        try
          AEditor.Controller := Self;
          AEditor.ListaID := ListaID;
          AEditor.LoadFromStream(AStream);
          AEditor.Print;
        finally
          AEditor.Release;
        end;
      end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;
end;

end.
