unit uRemesasProveedorReportController;

interface

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

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

  TRemesasProveedorReportController = class(TControllerBase, IRemesasProveedorReportController)
  private
    FDataModule : IDataModuleRemesasProveedorReport;
    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, uIEditorRemesasProveedorPreview,
  uEditorPreview, uDataModuleRemesasProveedor, uEditorBase, cxControls;

{ TRemesasProveedorReportController }

constructor TRemesasProveedorReportController.Create;
begin
  inherited;
  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;

  AStream := FDataModule.GetReport(ID);
  try
    CreateEditor('EditorRemesasProveedorPreview', IEditorRemesasProveedorPreview, AEditor);
    if Assigned(AEditor) then
      try
        AEditor.LoadFromStream(AStream);
        AEditor.Preview;
      finally
        AEditor.Release;
        AEditor := NIL;
      end;
  finally
    FreeAndNil(AStream);
  end;
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);
      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.
