unit uRemesasProveedorReportController;

interface

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

type
  IRemesasProveedorReportController = interface
  ['{A89AAA05-19AD-4455-BAF6-8A5373D15FE7}']
    procedure Preview(const ID : String);
    procedure Print(const ID : String);
  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);
    procedure Print(const ID : String);
  end;


implementation

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

{ 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;

procedure TRemesasProveedorReportController.Print(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.Print
end;

end.
