Esta es una clase parala administracion y diseño de los reportes con fastreport estos se almacenan en una base mysql, uso una especie de macros que se reemplazan con la funcion procesos_sql(cSql) ejemplo $fechas pide un rango de fechas y reemplaza en el query por elrepectivo rango antes de llamar a oserver:query(cSql) .
Code: Select all
#INCLUDE "FIVEWIN.CH"
#INCLUDE "XBROWSE.CH"
#INCLUDE "TCBROWSE.CH"
#INCLUDE "RECURSOS.CH"
#include "FastRepH.ch"
#ifdef _MYSQLDB_
Static oQryGes , oQryCons , oTZonas, oQryCiud
#endif
CLASS TGesRep
METHOD New() CONSTRUCTOR
METHOD Borrar()
METHOD Browse()
METHOD Editar()
METHOD Cargar()
METHOD Grabar()
METHOD Blank()
Method EnviaReporte()
Method MuestraReporte()
METHOD Informe()
ENDCLAss
//---------------------------------------------------------//
METHOD Informe() CLASS TGesRep
cSql := "SELECT * from reportes "
Sql_report("Listado de Reprtes",cSql)
RETURN
//---------------------------------------------------------//
METHOD Blank() CLASS TGesRep
Return
//----------------------------------------------------------//
METHOD New(lLoad) CLASS TGesRep
DEFAULT lload := .f.
xciud:=space(30)
if lLoad
::Cargar()
endif
Return Self
//---------------------------------------------------------//
METHOD Borrar() CLASS TGesRep
Local oQryC, oQryP
If Msgyesno("Esta seguro de Borrar esta Zona ?")
cSql := "UPDATE puertos SET zona = ' ' where zona = '"+oTGRep:codzona+"' "
oQryc := TDolphinQry():New( cSql, oServer )
cSql := "DELETE FROM zonas where id = "+str(oTGRep:id)
oQryP := TDolphinQry():New( cSql, oServer )
endif
Return
//-----------------------------------------------------------//
METHOD Cargar() CLASS TGesRep
oQryCons:SetWhere( " ReportID = "+ClipValue2SQL( oTGrep:id ) )
oQryCons:Refresh()
oQryCons:Gotop()
Return
//------------------------------------------------//
METHOD Grabar() CLASS TGesRep
Local nOrden, lNuevo := .f.
if empty( oTGRep:Reporte )
Msginfo("Debe escribir el nombre del Reporte")
Return
endif
if empty( oTGRep:ReportFileName )
Msginfo("No ha especificado e nombre del archivo de reporte")
Return
endif
oTGRep:Save()
Return
//--------------------------------------------//
METHOD Browse( lBusca, oQry ) CLASS TGesRep
Local oDlg,oBrow,lOk:=.f.,oBrw, oData, cBusca :=Space(80),aGet:=array(1), oQryC
STATIC oxa
oData := oQry
DEFINE DIALOG oDlg RESOURCE "BROWSEB" FONT TFont():New( GetDefaultFontName(), 0, GetDefaultFontHeight(),, ) // TRANSPARENT
oDlg:Settext("Reportes Registrados")
oDlg:lHelpIcon:=.F.
REDEFINE XBROWSE oBrw ; // OBJECT oQry ;
FIELDS oData:Id,;
oData:Reporte,;
oData:ReportFileName ;
HEADERS "Codigo",;
"Nombre del Reporte", ;
"Nombre del Achivo" ;
FIELDSIZES 80,200,200 ;
AUTOSORT ;
ON DBLCLICK ( lok:=.t.,oDlg:End(),cCod := oData:Id )
WITH OBJECT oBrw
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:nColDividerStyle := LINESTYLE_BLACK
:lColDividerComplete := .T.
:nHeaderLines := 1
:nDataLines := 1
:bKeyDown := { |nkey| iif(nKey==13,(lok:=.t.,oDlg:End(), cCod := oData:codzona ),) }
END
SetDolphin( oBrw, oQry, .F.)
oBrw:CreateFromResource( 101 )
REDEFINE GET aGet[1] VAR cBusca ID 111 ;
PICTURE "@!" ;
OF oDlg UPDATE
Redefine Button oBtn1 ID 112 of oDlg Action ( oQry:locate( { alltrim(cBusca) },{"reporte"},,.t. ), ;
oQry:Refresh(),refrecont(aget),;
oBrw:Refresh(),oBrw:SetFocus() )
ACTIVATE DIALOG oDlg ;
CENTERED
Return lOk
//------------------------------------------------------------//
Function Browsecons( lBusca, oQry )
Local oDlg,oBrow,lOk:=.f.,oBrw, oData, cBusca :=Space(80),aGet:=array(1), oQryC
STATIC oxa
oData := oQry
DEFINE DIALOG oDlg RESOURCE "BROWSEB" // TRANSPARENT
oDlg:Settext("Consultas Registradas")
oDlg:lHelpIcon:=.F.
REDEFINE XBROWSE oBrw ; // OBJECT oQry ;
FIELDS oData:codigo,;
oData:Nombre ;
HEADERS "Codigo",;
"Nombre de la Consulta" ;
FIELDSIZES 80,500 ;
AUTOSORT ;
ON DBLCLICK ( lok:=.t.,oDlg:End(),cCod := oData:Id )
WITH OBJECT oBrw
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:nColDividerStyle := LINESTYLE_BLACK
:lColDividerComplete := .T.
:nHeaderLines := 1
:nDataLines := 1
:bKeyDown := { |nkey| iif(nKey==13,(lok:=.t.,oDlg:End(), cCod := oData:Id ),) }
END
SetDolphin( oBrw, oQry, .F.)
oBrw:CreateFromResource( 101 )
REDEFINE GET aGet[1] VAR cBusca ID 111 ;
PICTURE "@!" ;
OF oDlg UPDATE
Redefine Button oBtn1 ID 112 of oDlg Action ( oQry:locate( { alltrim(cBusca) },{"nombre"},,.t. ), ;
oQry:Refresh(),refrecont(aget),;
oBrw:Refresh(),oBrw:SetFocus() )
ACTIVATE DIALOG oDlg ;
CENTERED
Return lOk
//-----------------------------------------------------------//
METHOD Editar( lNuevo, lEdita ) CLASS TGesRep
LOCAL oDlg,oBar,aGet:=array(9)
PRIVATE XCIUD,oBrow, aParams := {{"FECHAS","$fechas"},;
{"CFECHAS","$cfechas"},;
{"OPERADORES","$operadores"},;
{"CIUDADES","$ciudades"},;
{"EQUIPOS","$equipos"}, ;
{"MUELLES","$muelles"} }
DEFAULT lNuevo := .F.
DEFAULT lEdita := .F.
oQryGes := oServer:Query( "Select * From reportes order by ID,reporte" )
oQryCons:= oServer:Query( "Select * From ReportQuerys where reportid = "+ ClipValue2SQL( oQryGes:id ) )
oTGRep := oQryGes:GetRowObj()
::Cargar()
DEFINE DIALOG oDlg RESOURCE "DEFREPORT"
REDEFINE GET aGet[1] VAR oTGrep:Id PICTURE "9999" ID 101 OF oDlg READONLY UPDATE
REDEFINE GET aGet[2] VAR oTGRep:Reporte ID 102 ;
PICTURE "@!" ;
OF oDlg
REDEFINE GET aGet[3] VAR oTGRep:ReportFileName ID 103 ;
PICTURE "@!" ;
OF oDlg UPDATE
REDEFINE BTNBMP oBtn ID 122 RESOURCE "LUPA_16" NOBORDER OF oDlg ;
ACTION ( GETREPORTFILE( oTGRep:ReportFileName ) ,;
Refrecont( aGet ) )
REDEFINE XBROWSE oBrow ;
FIELDS oQryCons:ID ,;
oQryCons:DataSetName ;
HEADERS "Codigo" ,;
"Nombre del DataSet" ;
FIELDSIZES 80,600 ;
AUTOSORT ;
ON DBLCLICK iif(!empty(oTGRep:Id),( RelacionaQuery(.f.,oQryCons,oTGRep:Id), ;
oBrow:Refresh() ),MsgInfo("Debe Grabar Primero") )
WITH OBJECT oBrow
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:nColDividerStyle := LINESTYLE_BLACK
:lColDividerComplete := .T.
:nHeaderLines := 1
:nDataLines := 1
:bKeyDown := { |nkey| iif(nKey==13,iif(!empty(oTGRep:Id),( RelacionaQuery(.f.,oQryCons,oTGRep:Id), ;
oBrow:Refresh() ),MsgInfo("Debe Grabar Primero") ) ,) }
END
oBrow:SetDolphin( oQryCons, .f., .F. )
oBrow:CreateFromResource( 104 )
aGet[4]:=oBrow
REDEFINE BUTTON aGet[5] ID 202 OF oDlg ;
ACTION iif(!empty(oTGRep:Id),( RelacionaQuery(.t.,oQryCons,oTGRep:Id), ;
oBrow:Refresh() ),MsgInfo("Debe Grabar Primero") )
REDEFINE BUTTON aGet[6] ID 203 OF oDlg ;
ACTION iif( oQryCons:lastRec() > 0 ,( QuitaQuery(oQryCons),;
oBrow:Refresh() ),;
msgstop("No hay Consulta que Quitar") )
REDEFINE BUTTON aGet[7] ID 204 OF oDlg ;
ACTION Disenareporte(oTGRep,.f.,aParams)
REDEFINE BUTTON aGet[8] ID 205 OF oDlg ;
ACTION Disenareporte(oTGRep,.t.,aParams)
REDEFINE BUTTON aGet[9] ID 206 OF oDlg ;
ACTION EnviaEmailReporte(oTGRep,aParams)
bActualiza := {|| oQryGes:Refresh(), ;
oTGRep := oQryGes:GetRowObj(), ;
::Cargar(),;
oBrow:Gotop(),;
oBrow:Refresh(),;
refrecont(aGet) ,;
oBrow:SetFocus() }
bnuevo:={|| oTGRep := oQryGes:GetBlankRow() ,;
::Cargar(),;
oBrow:Gotop(),;
oBrow:refresh(),;
REFRECONT(aGet),;
ACTIVA(aGet)[1]:Setfocus() }
bGraba:={|| ::grabar(oTGRep) ,;
Eval( bActualiza ) }
bBusca:={|| ::browse(.t.,oQryGes) ,;
eval( bActualiza ),;
oBrow:Setfocus() }
bprim :={|| oQryGes:Gotop() ,;
eval( bActualiza ),;
REFRECONT(aGet) }
bEdit :={|| aGet[2]:Setfocus() }
bAnte :={|| oQryGes:skip( -1 ) ,;
eval( bActualiza ) }
bsig :={|| oQryGes:skip() ,;
eval( bActualiza ) }
bULTI :={|| oQryGes:gobottom() ,;
eval( bActualiza ) }
bundo :={|| eval( bActualiza ) }
bborrar:={|| ::Borrar(),Eval(bSig) }
bInfo:= {|| ::informe() }
ACTIVATE DIALOG oDlg ;
CENTERED ;
on INIT ( oBar:=BARRACOM(oDlg,{bnuevo,bEdit,bgraba,bundo,bborrar,bprim,bante,;
bsig,bulti,bbusca,binfo}) ) // ,ACTCONTX(oBar:aControls,{2,4}) );
RETURN( NIL )
//------------------------------------------//
FUNCTION GetReportFile( cFile )
Local cFileAnt := cFile
gcFile := cGetFile32("FastReport (*.fr3)| *.fr3 |" + ;
"Todos los Archivos (*.*)| *.* " ;
,"Por favor seleccione un Archivo de FastReport",1)
IF !empty(gcFile)
cFilew := memoread( gcFile ) // D_ReadFile( gcFile )
oTGRep:File := Val2Escape( cFilew )
oTGrep:ReportFileName := getonlyName( gcFile )
ELSE
gcFile := cFileAnt // oImage:Setbmp("NULA")
ENDIF
RETURN gcFile
//-------------------------------------------------------------------------//
Function RelacionaQuery( lnew, oQry, idRep )
LOCAL oDlg,aGet:=ARRAY(8),lsave:=.f., oCons
DEFAULT lnew := .F.
IF lnew
oCons := oQry:GetBlankRow()
oCons:ReportId := IdRep
ELSE
oCons := oQry:GetRowObj()
ENDIF
oQrCs := oServer:Query( "Select * From consulta where codigo="+ClipValue2Sql( oCons:consulta )+" order by codigo,nombre" )
If oQrCs:LastRec() > 0
oMac := oQrCs:GetRowObj()
if Empty( alltrim(oCons:sqlquery) )
oCons:SqlQuery := oMac:sqltxt
Endif
Else
oMac := oQrCs:GetBlankRow()
Endif
DEFINE DIALOG oDlg RESOURCE "AGRECONS"
REDEFINE GET aGet[1] VAR oCons:ID ID 104 OF oDlg READONLY
REDEFINE GET aGet[2] VAR oMac:codigo ID 101 OF oDlg READONLY
REDEFINE GET aGet[3] VAR oMac:nombre ID 107 OF oDlg READONLY
REDEFINE GET aGet[4] VAR oCons:datasetName ID 102 OF oDlg
REDEFINE GET aGet[5] VAR oCons:sqlquery MEMO ID 24 OF oDlg
REDEFINE BTNBMP aGet[6] ID 103 RESOURCE "LUPAP" OF oDlg ;
WHEN LNEW == .T. ;
ACTION ( oQrCs:SetWhere("Codigo like '%%'"),;
IIF( BrowseCons(,oQrCs) ,( oMac := oQrCs:GetRowObj(),;
oCons:consulta := oMac:codigo,;
oCons:sqlquery := oMac:sqltxt,;
Refrecont( aGet ) ), ) )
REDEFINE BUTTON aGet[7] ID 25 OF oDlg ;
ACTION IF( !EMPTY( oCons:Consulta) .and. !empty( oCons:DataSetName ), ( oCons:Save() , oDlg:End() ) , ;
msginfo("No ha seleccionado una consulta o no ha definido dataset") )
REDEFINE BUTTON aGet[8] ID 26 OF oDlg ;
ACTION oDlg:End()
ACTIVATE DIALOG oDlg ;
CENTERED
oQry:refresh()
IF lnew
oQry:GoBottom()
Endif
RETURN
//----------------------------------------------//
Function QuitaQuery( oQry )
Local oQry1
IF MSGNOYES("Esta seguro de borrar este DataSet ?")
oQry:Delete()
oQry:Refresh()
ENDIF
RETURN
//-------------------------------------//
FUNCTION GetOnlyName( cFile )
LOCAL nRat
IF ! Empty( cFile )
nRat = RAt( "\", cFile )
cFile = SubStr( cFile, nRat + 1 )
ENDIF
RETURN cFile
//----------------------------------------------------------------------------//
Function Disenareporte(oGesRep,lver,aParams)
Local oFrP, oQyDst
Local oTip
Private aQrys, cParams := ""
DEFAULT aParams := {{"FECHAS","$fechas"},;
{"CFECHAS","$cfechas"},;
{"OPERADORES","$operadores"},;
{"CIUDADES","$ciudades"},;
{"EQUIPOS","$equipos"}, ;
{"MUELLES","$muelles"} }
// SET DEFAULT TO "data\"
DEFAULT lver := .f.
oQyDst := oServer:Query( "Select d.datasetname,d.sqlquery, c.sqltxt from reportquerys d inner join consulta c on c.codigo=d.consulta where reportid="+ClipValue2Sql( oGesRep:Id ) )
if oQyDst:LastRec() ==0
MsgInfo("No hay DataSet configurado")
Return
Endif
oQyDSt:Gotop()
While ! oQyDst:Eof()
cMsql1 := iif( empty( alltrim( oQyDst:sqlquery ) ), oQyDst:sqltxt, oQyDst:sqlquery )
for xx := 1 to len( aParams )
xParam := aParams[xx,2]
if at( xparam, cMsql1 ) > 0
if at( xparam, cParams ) == 0
cParams := cParams+","+xparam
endif
endif
next
oQyDst:skip()
End
xaParam := listasarray( cParams )
for xx:= 1 to len ( aParams )
for xa := 1 to len ( xaParam )
if aParams[xx,2]== xaparam[ xa ]
aParams[xx,1] := procesos_sql( xaparam[xa] )
endif
next
Next
aQrys := {}
oQyDSt:Gotop()
TRY
While ! oQyDst:Eof()
cmSql := iif( empty( alltrim( oQyDst:sqlquery ) ), oQyDst:sqltxt, oQyDst:sqlquery )
for xx := 1 to len( aParams )
if at( aParams[xx,2], cmSql ) > 0
??? CRLF+aParams[xx,2] + " "+CRLF
cmSql := STRTRAN( cmSql, aParams[ xx, 2 ], aParams[ xx, 1 ] )
??? aParams[ xx, 1 ] +CRLF
??? cmSql+CRLF
endif
next
??? cmSql+CRLF
aadd( aQrys, { alltrim( oQyDst:datasetname ) ,oServer:Query( cmSql ) } )
oQyDst:skip()
End
CATCH oErr
ShowError( oErr )
Return
END
oFrP := frReportManager():new()
with object oFrP
for xx := 1 to len( aQrys )
cVar :="oDataset"+strzero(xx,2)
&cVar := oClone( aQrys[xx,2] )
:SetUserDataSet( aQrys[xx,1] ,;
mysqlfields( &cVar ) ,;
{|| &cVar:GoTop() } ,;
{|| &cVar:SKIP(1) } ,;
{|| &cVar:SKIP(-1) } ,;
{|| &cvar:EOF() } ,;
{ | aField | &cVar:FieldGet( afield ) } )
next
:LoadFromString(oGesRep:file)
if !lver
:SetTitle( "Diseñador de Informes" )
// :SetProperty("Designer", "Restrictions","[drDontCreateReport, drDontLoadReport, drDontSaveReport]")
:DesignReport()
:savetofile(GetEnv("TEMP")+"\"+oGesRep:ReportFileName)
oGesRep:File := Val2Escape( memoread( GetEnv("TEMP")+"\"+oGesRep:ReportFileName ) )
else
:SetTitle( "Visor de Informes" )
:PreviewOptions:SetButtons( FR_PB_PRINT + FR_PB_EXPORT + FR_PB_ZOOM + FR_PB_FIND + FR_PB_OUTLINE + FR_PB_NAVIGATOR )
:PreviewOptions:SetMaximized(.f.)
:PreviewOptions:SetBounds(120, 120, 800, 600)
// :PreviewOptions:SetModal(.f.)
:ShowReport()
endif
:ClearDataSets()
:DestroyFr()
end with
Return
//--------------------------------------------------------------------------------------------//
Function EnviaEmailReporte(oGesRep,aParams)
Local oFrP, oQyDst
Local oTip
Local RepDir := CurDrive() +":\"+ CurDir() + '\REPS\'
Local DataDir := CurDrive() +":\"+ CurDir() + '\DATA\'
Local ResDir := CurDrive() +":\"+ CurDir() + '\LANGRES\'
Private aQrys, cParams := ""
DEFAULT aParams := {{"FECHAS","$fechas"},;
{"CFECHAS","$cfechas"},;
{"OPERADORES","$operadores"},;
{"CIUDADES","$ciudades"},;
{"EQUIPOS","$equipos"}, ;
{"MUELLES","$muelles"} }
// SET DEFAULT TO "data\"
oQyDst := oServer:Query( "Select d.datasetname,d.sqlquery, c.sqltxt from reportquerys d inner join consulta c on c.codigo=d.consulta where reportid="+ClipValue2Sql( oGesRep:Id ) )
if oQyDst:LastRec() ==0
MsgInfo("No hay DataSet configurado")
Return
Endif
oQyDSt:Gotop()
While ! oQyDst:Eof()
for xx := 1 to len( aParams )
xParam := aParams[xx,2]
if at( xparam, oQyDst:sqltxt ) > 0
if at( xparam, cParams ) == 0
cParams := cParams+","+xparam
endif
endif
next
oQyDst:skip()
End
xaParam := listasarray( cParams )
for xx:= 1 to len ( aParams )
for xa := 1 to len ( xaParam )
if aParams[xx,2]== xaparam[ xa ]
aParams[xx,1] := procesos_sql( xaparam[xa] )
endif
next
Next
aQrys := {}
oQyDSt:Gotop()
TRY
While ! oQyDst:Eof()
cmSql := iif( empty( alltrim( oQyDst:sqlquery) ), oQyDst:sqltxt,oQyDst:sqlquery )
for xx := 1 to len( aParams )
if at( aParams[xx,2], cmSql ) > 0
??? aParams[xx,2] + " "
cmSql := STRTRAN( cmSql, aParams[xx,2], aParams[xx,1] )
??? aParams[xx,1] +CRLF
??? cmSql+CRLF
endif
next
??? cmSql+CRLF
aadd( aQrys, { alltrim( oQyDst:datasetname ) ,oServer:Query( cmSql ) } )
oQyDst:skip()
End
CATCH oErr
ShowError( oErr )
Return
END
oFrP := frReportManager():new()
with object oFrP
for xx := 1 to len( aQrys )
cVar :="oDataset"+strzero(xx,2)
&cVar := oClone( aQrys[xx,2] )
:SetUserDataSet( aQrys[xx,1] ,;
mysqlfields( &cVar ) ,;
{|| &cVar:GoTop() } ,;
{|| &cVar:SKIP(1) } ,;
{|| &cVar:SKIP(-1) } ,;
{|| &cvar:EOF() } ,;
{ | aField | &cVar:FieldGet( afield ) } )
next
:LoadFromString(oGesRep:file)
:SetTitle( "Visor de Reportes" )
cSubjectPdf := "Informe de Maniobras "+dtoc( date() )+"_"+Time()
cFileNameRep := "Reporte_de_Maniobras_"+strtran(dtoc( date() ),".","-")+"_"+strtran(Time(),":","-")
cFileNamePdf := ".\"+cFileNameRep+".pdf"
cFileNameHtml := ".\"+cFileNameRep+".html"
:SetProperty("PDFExport", "FileName", cFileNamePdf)
:SetProperty("PDFExport", "EmbeddedFonts", .t.)
:SetProperty("PDFExport", "PrintOptimized", .t.)
:SetProperty("PDFExport", "Creator", "Sistema Manta (Nikosoft)")
:SetProperty("PDFExport", "OpenAfterExport", .f.)
:SetProperty("PDFExport", "ShowDialog",.f.)
:PrepareReport()
:DoExport("PDFExport")
// :SetProperty("MailExport","ShowDialog",.f.)
:SetProperty("HTMLExport", "FileName", cFileNameHtml)
:SetProperty("HTMLExport", "OpenAfterExport", .f.)
:SetProperty("HTMLExport", "ShowDialog",.f.)
:PrepareReport()
:DoExport("HTMLExport")
cHtm := memoread( cFileNameHtml )
cDirEm := "nmartinez@coremar.com"+Space( 500 )
if MsgGet("Correos","Emails :",@cDirEm )
cS := :SendMail( "mail.coremar.com",25,"","","maniobras@coremar.com",cDirEm,;
cSubjectPdf,"Grupo Coremar","Envio de Informe Automatico de Maniobras",;
cFileNamePdf+CHR(13)+CHR(10)+cFileNameHtml )
If ! empty( cS )
msginfo( cS )
Else
Msginfo("Correo enviado" )
Endif
Endif
:ClearDataSets()
:DestroyFr()
end with
Return
//--------------------------------------------------------------------------------//
Method EnviaReporte( ReportID ) CLASS TGesRep
oQryGes := oServer:Query( "Select * From reportes order by ID,reporte" )
oQryCons:= oServer:Query( "Select * From ReportQuerys where reportid = "+ ClipValue2SQL( oQryGes:id ) )
oTGRep := oQryGes:GetRowObj()
Return
//--------------------------------------------------------------------------------//
Method MuestraReporte( ReportID ) CLASS TGesRep
oQryGes := oServer:Query( "Select * From reportes where id = "+ClipValue2SQL( ReportID ) )
oQryCons:= oServer:Query( "Select * From ReportQuerys where reportid = "+ ClipValue2SQL( oQryGes:id ) )
oTGRep := oQryGes:GetRowObj()
Disenareporte(oTgRep,.t.)
Return
//---------------------------------------------------------------------------------//
Static FUNCTION ShowError( oError )
Local cTextError
cTextError := " Descripción : " + oError:Description+CRLF+;
" SubSystem : " + oError:SubSystem+CRLF+;
" Error Number : " + Str( oError:SubCode )+CRLF+;
" Severity : " + Str( oError:Severity )+CRLF
MsgInfo( cTextError, "SQL Error" )
RETURN
//--------------------------------------------------------------//
FUNCTION Sql_Report( cReport, cSql )
LOCAL oAlias
SET DATE FORMAT "yyyy-mm-dd"
cSql:=PROCESA_SQL( cSql )
??? cSql
IF AT("SELECT",upper(cSql))>0 .AND. AT(";",cSql)=0
TRY
oAlias := oServer:Query( cSql )
IF oAlias:Lastrec() > 0
lOk:=.t.
oAlias:Gotop()
reporte(oAlias,cReport)
ELSE
MsgInfo("No Se encontraron registros")
ENDIF
CATCH oErr
ShowError( oErr )
END
ELSE
MsgInfo("No hay una sentencia SQL Valida")
ENDIF
SET DATE ANSI
return nil
//-------------------------------------------------------------//
function Reporte( oAlias, cReport)
local oRpt
local n,oFont1,oFont2
DEFAULT cReport := "Reporte"
DEFINE FONT oFont1 NAME "COURIER NEW" SIZE 0,-8
DEFINE FONT oFont2 NAME "COURIER NEW" SIZE 0,-8 BOLD
REPORT oRpt TITLE "Reporte: " + cReport ;
HEADER "Fecha: " + DToC( Date() ) + ", Hora: " + Time() ;
FOOTER "Pagina: " + Str( oRpt:nPage, 3 ) ;
FONT oFont1,oFont2 ;
CAPTION "Sistema de Informes" ;
PREVIEW
if Empty( oRpt ) .or. oRpt:oDevice:hDC == 0
return nil
endif
oRpt:margin(1,1,2)
oRpt:margin(1,2,2)
for n = 1 to oAlias:FCount()
oRpt:AddColumn( TrColumn():New( { FInfo1( oAlias, n ) },,;
{ FInfo2( oAlias, n ) },, iif(valtype( FInfo2( oAlias, n ) ) == "D",{"@D"},;
iif(valtype( FInfo2( oAlias, n ) ) == "N",{"@Z 999,999,999"},;
{"@X" } ) ) ,,,,,,,, oRpt ) )
next
ENDREPORT
oRpt:bSkip := {|| oAlias:Skip() }
ACTIVATE REPORT oRpt while ! oAlias:Eof()
oAlias:Gotop()
return nil
//----------------------------------------------------------------------------//
static function FInfo1( oAlias, n )
return { || upper( oAlias:FieldName( n ) ) }
static function FInfo2( oAlias, n )
return { || iif(empty( oAlias:FieldGet( n ) )," ",oAlias:FieldGet( n ) ) }
//-------------------------------------------------------------------------------//
function mysqlfields( oQry )
Local clField := ""
nLen := oQry:Fcount()
for x := 1 to oQry:Fcount()
cLfield := cLfield + oQry:FieldName( x ) + iif( x < nLen ,";","" )
Next
Return cLfield