Ver Mensaje Individual
  #12  
Antiguo 13-03-2007
Avatar de axesys
axesys axesys is offline
Miembro
 
Registrado: ene 2007
Ubicación: Los Mochis Sinaloa
Posts: 208
Reputación: 18
axesys Va por buen camino
Puedes usar Reportman

Código Delphi [-]
unit uReportes;
interface
uses
  SysUtils, StrUtils, Reportman.Drawing.Forms, Reportman.Reporting, FirebirdSql.Data.Firebird;
type
  TParametrosRep = record
    sParametro: String;
    sValor: String;
  end;
  TDatosReportes = record
    FBDataBase: FbConnection;
    sArchivo: String;
    sTitulo: String;
    iCopias: integer;
    bPreliminar: boolean;
    bDialogo: boolean;
    sArchivoConexion: String;
    sMensaje: string;
  end;
  TReportes = class
  private
    arrParametros: array of TParametrosRep;
    Datos: TDatosReportes;
  public
    rptReporte: Report;
    rptPreview: PrintOutWinForms;
    constructor Create;
    destructor Destroy; override;
    procedure AgregarParametro(sParametro, sValor: String);
    function Ejecutar: boolean;
    property DataBase: FbConnection write Datos.FBDatabase;
    property Archivo: String write DAtos.sArchivo;
    property Titulo: String write Datos.sTitulo;
    property Copias: integer write Datos.iCopias;
    property VistaPreliminar: boolean write Datos.bPreliminar;
    property ElegirImpresora: boolean write Datos.bDialogo;
    property ArchivoConexion: String write Datos.sArchivoConexion;
    property Mensaje: String read Datos.sMensaje;
  end;
implementation
procedure TReportes.AgregarParametro(sParametro, sValor: String);
begin
  SetLength(arrParametros, Length(arrParametros) + 1);
  arrParametros[Length(arrParametros) - 1].sParametro:= sParametro;
  arrParametros[Length(arrParametros) - 1].sValor:= sValor;
end;
constructor TReportes.Create;
begin
  inherited;
  rptReporte:= Report.Create;
  rptPreview:= PrintOutWinForms.Create;
end;
destructor TReportes.Destroy;
begin
  FreeAndNil(rptPreview);
  FreeAndNil(rptReporte);
  inherited;
end;
function TReportes.Ejecutar: boolean;
var
  i: integer;
begin
  Result:= true;
  try
    rptReporte.Language:= 1;
    rptReporte.LoadFromFile(Datos.sArchivo);
    if(Datos.sArchivoConexion = EmptyStr) then
      rptReporte.DatabaseInfo[0].Connection := Datos.FBDataBase
    else
      rptReporte.DataInfo.Item[0].MyBaseFilename:= Datos.sArchivoConexion;
    if(Datos.iCopias = 0) then
      rptReporte.Copies:= 1
    else
      rptReporte.Copies:= Datos.iCopias;
    //rptPreview.Title:= Datos.sTitulo;
    rptPreview.ShowPrintDialog:= Datos.bDialogo;
    rptPreview.Preview:= Datos.bPreliminar;
    for i:= 0 to Length(arrParametros) -1 do
      rptReporte.Params.Item[rptReporte.Params.IndexOf(arrParametros[i].sParametro)].Value:= arrParametros[i].sValor;
    rptPreview.Print(rptReporte.MetaFile);
  except
    on e: exception do
    begin
      if(AnsiContainsStr(e.Message, 'filename')) then
        Datos.sMensaje:= 'El nombre del archivo de reporte es incorrecto'
      else if(AnsiContainsStr(e.Message, 'No data')) then
        Datos.sMensaje:= 'No hay datos disponibles para imprimir'
      else
        Datos.sMensaje:= 'Ocurrió un error al intentar imprimir';
      Result:= false;
    end;
  end;
  SetLength(arrParametros, 0);
end;
end.
Responder Con Cita