unit uRemesasClienteReportController;

interface

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

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

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

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


implementation

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

{ TRemesasClienteReportController }

constructor TRemesasClienteReportController.Create;
begin
  inherited;
  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 ID : String);
var
  AStream: Binary;
  AEditor : IEditorRemesasClientePreview;
begin
  AEditor := NIL;

  AStream := FDataModule.GetReport(ID);
  try
    CreateEditor('EditorRemesasClientePreview', IEditorRemesasClientePreview, AEditor);
    if Assigned(AEditor) then
      try
        AEditor.LoadFromStream(AStream);
        AEditor.Preview;
      finally
        AEditor.Release;
        AEditor := NIL;
      end;
  finally
    FreeAndNil(AStream);
  end;
end;

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

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(ID);
    try
      CreateEditor('EditorRemesasClientePreview', IEditorRemesasClientePreview, AEditor);
      if Assigned(AEditor) then
        try
          AEditor.LoadFromStream(AStream);
          AEditor.Print;
        finally
          AEditor.Release;
          AEditor := NIL;
        end;
    finally
      FreeAndNil(AStream);
    end;
  finally
    HideHourglassCursor;
  end;
end;

end.
