In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Footer en TBrowse

Foro de Xailer profesional en español
Responder
Ariel
Mensajes: 26
Registrado: Mar Nov 26, 2019 12:28 pm

Footer en TBrowse

Mensaje por Ariel »

Hola,

como hago para totalizar una columna de un browse? ya puse el lFooter en .t., pero no encuentro como ponerle a la columna especifica que totalice ?

Gracias
Avatar de Usuario
bingen
Mensajes: 565
Registrado: Lun Jul 07, 2014 8:17 pm
Ubicación: Bilbao
Contactar:

Re: Footer en TBrowse

Mensaje por bingen »

Nosotros sobrecargamos el browse para ello:

Method SetFooter( xCol, xValue ) Class TBrowse
Local nCol:=0

::lFooter := .T. //Por si se nos ha olvidado

If ValType(xCol)<>"A"
xCol:={xCol}
Endif
If ValType(xValue)<>"A"
xValue:={xValue}
Endif

For nCol:=1 to Len(xCol)
If ValType(xCol[nCol])="N"
xCol[nCol]:=::aCols[xCol[nCol]]:cHeader
Endif
If ::ColWithHeader(xCol[nCol])<>Nil
::ColWithHeader(xCol[nCol]):cFooter :=AllString(xValue[nCol])
Else
Logdebug("ERROR tBrowse:SetFooter no encuentra la columna "+xCol[nCol])
Endif
Next

Return Nil

Y luego también hicimos otras sobrecarga para sumar, contar, promediar, etc columnas de tDBBROWSE


//Devuelve la suma del campo o array de campos xFieldName que esta/n en el oDataSet del browse
METHOD Sum( xFieldName, lFormatEuro ) CLASS TDBBrowse
LOCAL aDatos:={}, nCampo:=0, aResult:={},nC:=0

Default lFormatEuro To .F.

If ValType(xFieldName)<>"A"
xFieldName:={xFieldName}
Endif

aResult:=Array(Len(xFieldName))
AFill(aResult,0)

IF ::oDataSet == Nil .OR. !::oDataset:lOpen
Return IF(Len(aResult)=1,aResult[1],aResult)
ENDIF

For nCampo:= 1 to Len(xFieldName)
aDatos :={}
nC := ::oDataSet:FieldPos(xFieldName[nCampo])
If nC > 0
if ::oDataSet:oRecords:ClassName() == "TWebRecords" .Or. ::oDataSet:oRecords:ClassName() == "TMemRecords"
aDatos := ArrayCol(::oDataSet:oRecords:aWork,nC)
Else
aDatos := ArrayCol(::oDataSet:oRecords:aData,nC)
ENdif
AEval(aDatos,{|x| aResult[nCampo]+=Val(ToString(x))})
aResult[nCampo]:=If(!lFormatEuro,aResult[nCampo],FormatEuro(aResult[nCampo]))
Else
LogDebug("No existe el campo "+xFieldName[nCampo]+" a Sumar en el DbBrowse.")
Endif
Next

aDatos :={}

Return IF(Len(aResult)=1,aResult[1],aResult)

//Devuelve la cuenta del campo o array de campos xFieldName que esta/n en el oDataSet del browse
METHOD Count( xFieldName ) CLASS TDBBrowse
LOCAL aDatos:={}, nCampo:=0, aResult:={},nC:=0

If ValType(xFieldName)<>"A"
xFieldName:={xFieldName}
Endif

aResult:=Array(Len(xFieldName))
AFill(aResult,0)

IF ::oDataSet == Nil .OR. !::oDataset:lOpen
Return IF(Len(aResult)=1,aResult[1],aResult)
ENDIF

For nCampo:= 1 to Len(xFieldName)
aDatos :={}
nC := ::oDataSet:FieldPos(xFieldName[nCampo])
If nC > 0
aDatos := ArrayCol(::oDataSet:oRecords:aData,nC)
AEval(aDatos,{|x| aResult[nCampo]+=IF(!Vacio(x),1,0)})
Else
LogDebug("No existe el campo "+xFieldName[nCampo]+" a Sumar en el DbBrowse.")
Endif
Next

aDatos :={}

Return IF(Len(aResult)=1,aResult[1],aResult)

//Devuelve la media aritmética del campo o array de campos xFieldName que esta/n en el oDataSet del browse
METHOD Avg( xFieldName, lFormatEuro, nDecimales ) CLASS TDBBrowse
LOCAL aDatos:={}, nSuma:=0, nCuenta:=0, nCampo:=0, aResult:={} ,nC:=0

Default lFormatEuro To .F.
Default nDecimales To 2

If ValType(xFieldName)<>"A"
xFieldName:={xFieldName}
Endif

aResult:=Array(Len(xFieldName))
AFill(aResult,0)

IF ::oDataSet == Nil .OR. !::oDataset:lOpen
Return IF(Len(aResult)=1,aResult[1],aResult)
ENDIF

For nCampo:= 1 to Len(xFieldName)
aDatos :={}
nC := ::oDataSet:FieldPos(xFieldName[nCampo])
If nC > 0
aDatos := ArrayCol(::oDataSet:oRecords:aData,nC)
AEval(aDatos,{|x| nSuma+=Val(ToString(x))})
AEval(aDatos,{|x| nCuenta+=IF(!Vacio(x),1,0)})
aResult[nCampo]:=If(!lFormatEuro,Round(nSuma/nCuenta,nDecimales),FormatEuro(nSuma/nCuenta))
Else
LogDebug("No existe el campo "+xFieldName[nCampo]+" a Sumar en el DbBrowse.")
Endif
Next

aDatos :={}

Return IF(Len(aResult)=1,aResult[1],aResult)



//Devuelve el valor mínimo del campo cFieldName que esta en el oDataSet del browse
METHOD Min( cFieldName, lFormatEuro, lNoCero ) CLASS TDBBrowse
LOCAL aDatos:={}, nMin:=9999999999999999

Default lFormatEuro To .F.
Default lNoCero To .F.

IF ::oDataSet == Nil .OR. !::oDataset:lOpen
Return nMin
ENDIF

with object ::oDataSet
:SaveState(.T.)
aDatos:=::oDataSet:SaveToArray( cFieldName )
:RestoreState(.T.)
END WITH

If ::oDataSet:FieldExist(cFieldName)
AEval(aDatos,{|x| nMin:=IF(lNoCero .And. Val(ToString(x[1]))=0,nMin,Min(nMin,Val(ToString(x[1])))) })
Else
LogDebug("No existe el campo "+cFieldName+" a calcular el mínimo en el DbBrowse")
Endif

nMin:=IF(nMin=9999999999999999,0,nMin)

aDatos :={}

Return If(!lFormatEuro,nMin,FormatEuro(nMin))

//Devuelve el valor máximo del campo cFieldName que esta en el oDataSet del browse
METHOD Max( cFieldName, lFormatEuro ) CLASS TDBBrowse
LOCAL aDatos:={}, nMax:=0

Default lFormatEuro To .F.

IF ::oDataSet == Nil .OR. !::oDataset:lOpen
Return nMax
ENDIF

with object ::oDataSet
:SaveState(.T.)
aDatos:=::oDataSet:SaveToArray( cFieldName )
:RestoreState(.T.)
END WITH


If ::oDataSet:FieldExist(cFieldName)
AEval(aDatos,{|x| nMax:=Max(nMax,Val(ToString(x[1])))})
Else
LogDebug("No existe el campo "+cFieldName+" a calcular el máximo en el DbBrowse")
Endif

aDatos :={}

Return If(!lFormatEuro,nMax,FormatEuro(nMax))
BiSoft Desarrollo de software profesional
http://www.bisoft.es
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: Footer en TBrowse

Mensaje por ignacio »

Hola Ariel,

Código: Seleccionar todo

   LOCAL nValue := 0

   WITH OBJECT ::oDbfDataSet1
      :SaveState( .T. )
      :GoTop()
      DO WHILE !:Eof()
         nValue += :Salary
         :Skip()
      ENDDO
      :RestoreState( .T. )
   END WITH

   ::oDBBrowse1:aCols[?]:cFooter := Transform(  nValue, "99,999,999.99" )
Saludos
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Ariel
Mensajes: 26
Registrado: Mar Nov 26, 2019 12:28 pm

Re: Footer en TBrowse

Mensaje por Ariel »

Bingen e Ignacio,

Muchas gracias
Responder