unit uAlbaranesProveedorReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleAlbaranesProveedorReport,
  uAlbaranesProveedorController, uDetallesAlbaranProveedorController,
  uBizAlbaranesProveedor;

type
  IAlbaranesProveedorReportController = interface
  ['{AAE252CE-D407-4FF4-AF2A-350C5A421C89}']
    procedure Preview(const AID : String);
    procedure Print(const AID : String);
  end;

  TAlbaranesProveedorReportController = class(TInterfacedObject, IAlbaranesProveedorReportController)
  private
    FDataModule : IDataModuleAlbaranesProveedorReport;
    function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
  public
    constructor Create;
    destructor Destroy; override;

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


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorAlbaranesProveedorPreview,
  uEditorPreview, uDataModuleAlbaranesProveedor, uEditorBase, cxControls;

{ TAlbaranesProveedorReportController }

constructor TAlbaranesProveedorReportController.Create;
begin
  FDataModule := TDataModuleAlbaranesProveedor.Create(Nil);
end;

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


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

procedure TAlbaranesProveedorReportController.Preview(const AID : String);
var
  AStream: Binary;
  AEditor : IEditorAlbaranesProveedorPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(AID);
    try
      CreateEditor('EditorAlbaranesProveedorPreview', IEditorAlbaranesProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

  if Assigned(AEditor) then
    AEditor.Preview;
end;

procedure TAlbaranesProveedorReportController.Print(const AID : String);
var
  AStream: Binary;
  AEditor : IEditorAlbaranesProveedorPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetReport(AID);
    try
      CreateEditor('EditorAlbaranesProveedorPreview', IEditorAlbaranesProveedorPreview, AEditor);
      AEditor.LoadFromStream(AStream);
    finally
      AStream.Free;
    end;
  finally
    HideHourglassCursor;
  end;

  if Assigned(AEditor) then
    AEditor.Print
end;

end.
