Hola
Alguien esta utilizando Fast Reports con TDolphin?
y si puede poner un ejemplo, mucho mejor
Saludos,
Mauricio
1.-
*--
PROCEDURE CREAREPORT() && Asi llamas al fastreport desde tu aplicacion para crear un reporte nuevo
*--
LOCAL oFr
&& objeto F.R
oFr := frReportManager():New()
&& Creamos la Instancia
*--
WITH OBJECT oFr
&&Asigno datos basicos de la empresa al reporte
:LoadLangRes( "Español.xml" )
:SetIcon(9001)
:AddVariable( "EMPRESA", "NOMBRE", "'" + oApp:cEmpresa + "'" )
:AddVariable( "EMPRESA", "DIRECCION", "'" + oApp:cDirempre + "'" )
:AddVariable( "EMPRESA", "RIF", "'" + oApp:cRifempre + "'" )
:AddVariable( "EMPRESA", "TELEFONOS", "'" + oApp:cTelempre + "'" )
:AddVariable( "EMPRESA", "WEBSITE", "'" + oApp:cWebempre + "'" )
:AddVariable( "EMPRESA", "MAIL", "'" + oApp:cMailempre + "'" )
:AddVariable( "EMPRESA", "PIEDEPAGINA", oApp:cDirempre + CRLF + oApp:cMailempre )
END
oFr:DesignReport()
&& llamo al method de diseño
oFr:DestroyFr()
&& cerramos la instancia
RETURN
*--
2.-
El sigiente ejemplo recibe el objeto Query como parametro
*--
PROCEDURE LISTACONTRA( oQry )
*--
LOCAL oPrn
-> Objeto FastReport
LOCAL cFileMail := "Condominios.pdf"
-> Para enviar por mail si
*--
IF oQry:LastRec() = 0
&& Verifico si hay registros para imprimr o mostrar
MSGINFO( "NO EXISTEN CONDOMINIOS REGISTRADOS", oApp:cSistema )
RETURN
ENDIF
*--
oPrn := frReportManager():New()
&& Aca c crea el objeto FastReport
oPrn:LoadLangRes("Español.xml")
&& Aca le Asignas el idioma para modo diseño y preview
*--
* Aca seleccionamos como manipular los datos del oQry
* se puede hacer mediante dataset o con Array
*--
// esto hay que hacerlo antes de llamar al archvo de reporte
// el data set es como una tabla virtual ( asi lo defino yo personalmente )
// nombre | ------ Campos a mostrar -|
oPrn:SetUserDataSet("Condominios","codigo;nombre;edificios;apartamentos",;
{|| oQry:GoTop() }, {|| oQry:Skip(1) },;
&& code block para manipular los datos
{|| oQry:Skip(-1) },{|| oQry:Eof() },;
{| aField | oQry:FieldGet(aField) } )
*--
IF ! oPrn:LoadFromResource( 8101 )
&& En mi caso tengo los reportes ya diseñados en un Archivo .rc
&& Tambien puedes usar oPrn:LoadFromFile( ".\tu_archivo.frr3")
MSGSTOP("ERROR AL PROCESAR EL REPORTE", oApp:cSistema )
ELSE
WITH OBJECT oPrn
&& Aca le agrego variables del sistema al reporte
:SetIcon(9000)
:SetTitle( "Listado de Condominios" )
:AddVariable( "EMPRESA", "NOMBRE", "'" + oApp:cEmpresa + "'" )
:AddVariable( "EMPRESA", "DIRECCION", "'" + oApp:cDirempre + "'" )
:AddVariable( "EMPRESA", "RIF", "'" + oApp:cRifempre + "'" )
:AddVariable( "EMPRESA", "TELEFONOS", "'" + oApp:cTelempre + "'" )
:AddVariable( "EMPRESA", "WEBSITE", "'" + oApp:cWebempre + "'" )
:AddVariable( "EMPRESA", "MAIL", "'" + oApp:cMailempre + "'" )
:AddVariable( "EMPRESA", "PIEDEPAGINA", oApp:cDirempre + CRLF + oApp:cMailempre )
END
IF oApp:lMaster
&& Verifico si es un usuario con provilegios para poder modificar el reporte
oPrn:DesignReport()
ELSE
&& usuario final
oPrn:PreviewOptions:SetButtons(1+8+16+32+128+256+1024)
&& Selecciono los botones para el preview
oPrn:ShowReport()
&&muestro el previw
ENDIF
ENDIF
*--
cQryCond:Gotop()
oPrn:ClearDataSets("Condominios")
oPrn:DestroyFR()
RETURN
*--
*
3.-
//----------------------------------------------------------------------------//
Function report_manopd()
Local oFrP
cSql := "select distinct m.id,m.maniobra as numero, m.fecini as fecha, .........."
oRpt := oServer:Query( "Select reporte, file from reportes where id = 3")
TRY
oTip := oServer:Query( cSql )
CATCH
Msginfo("Error datos incompletos")
return
END
oFrP := frReportManager():new()
with object oFrP
:SetUserDataSet("manimov",mysqlfields(oTip),;
{|| oTip:GoTop()} ,;
{|| oTip:SKIP(1)},;
{|| oTip:SKIP(-1) },;
{|| oTip:EOF() },;
{ | aField | oTip:FieldGet( afield )} )
:LoadFromString( oRpt:file )
:SetTitle( "Diseñador 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:SetMaximized(.f.)
:PreviewOptions:SetBounds(120, 120, 800, 600)
:ShowReport()
:ClearDataSets()
:DestroyFr()
end with
Return
//--------------------------------------------//
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
//-------------------------------------------------------//
#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
//Solo para incluir informacion para el depurador
#xcommand ??? <xData> [, <xDataN> ] => OutPutDebugString( <xData> ) ;
[; OutPutDebugString( <xDataN>) ]
DEFREPORT DIALOG FIXED IMPURE 65, 56, 348, 266
STYLE WS_POPUP|DS_3DLOOK|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
CAPTION "Gestion de Informes"
FONT 8, "MS Sans Serif"
{
CONTROL "", 104, "TXBrowse", WS_TABSTOP|0x00200000, 4, 126, 334, 112
CONTROL "", 101, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 57, 36, 40, 12
CONTROL "", 102, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 57, 52, 235, 12
CONTROL "", 103, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 57, 67, 164, 12
CONTROL "&Añadir Query", 202, "Button", WS_TABSTOP, 58, 243, 56, 14
CONTROL "&Quitar Query", 203, "Button", WS_TABSTOP, 118, 243, 56, 14
CONTROL "Codigo", 4007, "Static", WS_GROUP, 13, 38, 40, 8
CONTROL "Descripción", 4008, "Static", WS_GROUP, 12, 53, 40, 8
CONTROL "Archivo", 4009, "Static", WS_GROUP, 12, 68, 40, 8
CONTROL "&Diseñador", 204, "Button", WS_TABSTOP, 179, 243, 50, 14
CONTROL "", 122, "Tbtnbmp", 0x00000000, 225, 67, 12, 12
CONTROL "&Vista ", 205, "Button", WS_TABSTOP, 234, 243, 50, 14
CONTROL "", 150, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 57, 83, 280, 30
CONTROL "Parametros", 4001, "Static", WS_GROUP, 9, 93, 40, 8
CONTROL "&Email Report", 206, "Button", WS_TABSTOP, 288, 243, 50, 14
}
CREATE TABLE `consulta` (
`codigo` varchar(4) DEFAULT NULL,
`nombre` varchar(50) DEFAULT NULL,
`sqltxt` text,
`id` bigint(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
KEY `codigo` (`codigo`),
KEY `nombre` (`nombre`)
) ENGINE=MyISAM AUTO_INCREMENT=36 DEFAULT CHARSET=latin1
CREATE TABLE `reportes` (
`ID` bigint(10) NOT NULL AUTO_INCREMENT,
`Reporte` varchar(80) DEFAULT NULL,
`ReportFileName` varchar(25) DEFAULT NULL,
`File` mediumblob,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1
CREATE TABLE `reportquerys` (
`ID` bigint(10) NOT NULL AUTO_INCREMENT,
`ReportID` bigint(10) DEFAULT NULL,
`Consulta` char(4) DEFAULT NULL,
`DataSetName` varchar(20) DEFAULT NULL,
`sqlquery` text,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=latin1
METHOD Reporte2() CLASS TFacturas
local oFr := frReportManager():New()
local cQry := " ", oFacturas, oMovtos, oClientes
local oVars := oMain:oMysql:Query( "SELECT * FROM empresa")
cQry := " "
cQry := " SELECT * FROM facturas WHERE control = " + ClipValue2Sql( ::oFacturas:Control )
oMovtos := oMain:oMysql:Query( cQry )
oFacturas := oMain:oMysql:Query( cQry )
cQry := " "
cQry := " SELECT * FROM clientes WHERE codigo = " + ClipValue2Sql( ::oFacturas:Cliente )
oClientes := oMain:oMysql:Query( cQry )
cQry := " "
cQry := " SELECT * FROM movtos WHERE control = " + ClipValue2Sql( ::oFacturas:Control )
oMovtos := oMain:oMysql:Query( cQry )
WITH OBJECT oFr
:LoadLangRes( "spanish.xml" )
:SetUserDataSet("oFacturas",mysqlfields(oFacturas),;
{|| oFacturas:GoTop()} ,;
{|| oFacturas:SKIP(1)},;
{|| oFacturas:SKIP(-1)},;
{|| oFacturas:EOF() },;
{ | aField | oFacturas:FieldGet( afield )} )
:SetUserDataSet("oMovtos",mysqlfields(oMovtos),;
{|| oMovtos:GoTop()} ,;
{|| oMovtos:SKIP(1)},;
{|| oMovtos:SKIP(-1)},;
{|| oMovtos:EOF() },;
{ | aField | oMovtos:FieldGet( afield )} )
:SetUserDataSet("oVars",mysqlfields(oVars),;
{|| oVars:GoTop()} ,;
{|| oVars:SKIP(1)},;
{|| oVars:SKIP(-1)},;
{|| oVars:EOF() },;
{ | aField | oVars:FieldGet( afield )} )
:SetUserDataSet("oClientes",mysqlfields(oClientes),;
{|| oClientes:GoTop()} ,;
{|| oClientes:SKIP(1)},;
{|| oClientes:SKIP(-1)},;
{|| oClientes:EOF() },;
{ | aField | oClientes:FieldGet( afield )} )
:LoadFromFile("reportes\cfdi1.fr3")
:DesignReport()
:ShowReport()
:ClearDataSets()
:DestroyFr()
END WITH
oVars:end()
oFacturas:end()
oMovtos:end()
oClientes:end()
return nil
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 41 guests