unit InformeBaseFR3;

interface

uses
  SysUtils, Classes, frxCross, frxClass, frxIBXComponents, IBDatabase, DB,
  IBCustomDataSet;

type
  TdmInformeBaseFR3 = class(TDataModule)
    frxIBXComponents1: TfrxIBXComponents;
    frxCrossObject1: TfrxCrossObject;
    FReport: TfrxReport;
  private
    //FPreview : TfrPreview;
    function DarTextoDireccion(Index : Integer) : String;
    function DarTextoTelefonos(Index : Integer) : String;
  protected
    FBaseDatos : TIBDatabase;
    FTransaccion : TIBTransaction;
    FNombreInforme : String;
    procedure CargarInforme;
    procedure CrearVariables; virtual;
    procedure PrepararConsultas; virtual; abstract;
{    procedure RellenarCabecera(Band: TfrBand); virtual;
    procedure RellenarBanda(Band: TfrBand); virtual;}
    procedure PrepararInforme; virtual;
//    procedure FReportBeginBand(Band: TfrBand); virtual;
//    procedure SetPreview (Value : TfrPreview);
  public
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure Previsualizar;
    procedure Imprimir;
  published
//    property Preview : TfrPreview read FPreview write SetPreview;
    property Report : TfrxReport read FReport;
  end;

var
  dmInformeBaseFR3: TdmInformeBaseFR3;

implementation

uses BaseDatos;

{$R *.dfm}

{ TDataModule1 }

procedure TdmInformeBaseFR3.CargarInforme;
var
  RutaAux : String;
begin
  RutaAux := ExtractFileDir(ParamStr(0))+ '\informes\' + FNombreInforme;
  if not FileExists(RutaAux) then
    raise Exception.CreateFmt('No se ha encontrado el informe %s.',[RutaAux]);
  FReport.LoadFromFile(RutaAux);
end;

procedure TdmInformeBaseFR3.CrearVariables;
begin

end;

constructor TdmInformeBaseFR3.Create(AOwner: TComponent);
begin
  inherited;
  FBaseDatos := dmBaseDatos.BD;
  FTransaccion := dmBaseDatos.Transaccion;
//  FReport := TfrReport.Create(Self);
end;

function TdmInformeBaseFR3.DarTextoDireccion(Index: Integer): String;
begin

end;

function TdmInformeBaseFR3.DarTextoTelefonos(Index: Integer): String;
begin

end;

destructor TdmInformeBaseFR3.Destroy;
begin

  inherited;
end;

procedure TdmInformeBaseFR3.Imprimir;
begin
  PrepararInforme;
  FReport.PrepareReport;
//  FReport.PrintPreparedReportDlg;
  FReport.PrintOptions.ShowDialog := True;
  FReport.Print;
end;

procedure TdmInformeBaseFR3.PrepararInforme;
begin
  PrepararConsultas;
  CargarInforme;
  CrearVariables;
//  FReport.OnBeginBand := FReportBeginBand;
//  FReport.Preview := FPreview;
end;

procedure TdmInformeBaseFR3.Previsualizar;
begin
  PrepararInforme;
  FReport.ShowReport;
end;


end.
