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.

TBrwColumn:FilterEval

Foro público de Xailer en español
User avatar
Marcelo Coelho Silva
Posts: 267
Joined: Sat May 31, 2008 4:49 pm

TBrwColumn:FilterEval

Postby Marcelo Coelho Silva » Thu Jan 28, 2016 1:31 am

Senhores,

Como faço para comparar o valor digitado no Filtro (macro '%') com o valor de cada linha do Browser (Valor da Coluna):

Exemplo:
Ao envez de usar
oCol:FilterEval := "'%' $ UPPER( NAME )"

Gostaria de Saber se existe uma macro que seria o Valor do Buffer da Coluna
oCol:FilterEval := "'%' $ UPPER( '###' )"
Onde '###' (apenas para exemplificar) seria uma macro para o Buffer da Coluna.

Existe uma macro ?


PS: Presciso de uma macro pois utilizo como campo Calculated fields, que não funcionam dentro do :FilterEval.

Obrigado,
Att.

Marcelo Coelho Silva
Brasil.
User avatar
bingen
Posts: 396
Joined: Mon Jul 07, 2014 8:17 pm
Location: Bilbao
Contact:

Re: TBrwColumn:FilterEval

Postby bingen » Thu Jan 28, 2016 12:36 pm

Puedes realizar tu propio tratamiento de los filtros sobrecargando

Class TMySQLRecords From XMySQLRecords

METHOD GetFilterExp( oDBBrowse )

Espero que te sirva.

Salu2
BiSoft Desarrollo de software profesional
http://www.bisoft.es
User avatar
Marcelo Coelho Silva
Posts: 267
Joined: Sat May 31, 2008 4:49 pm

Re: TBrwColumn:FilterEval

Postby Marcelo Coelho Silva » Fri Jan 29, 2016 2:24 pm

Bingen,

Pode me dar um exemplo de como fazer este tratamento?
Att.

Marcelo Coelho Silva
Brasil.
User avatar
bingen
Posts: 396
Joined: Mon Jul 07, 2014 8:17 pm
Location: Bilbao
Contact:

Re: TBrwColumn:FilterEval

Postby bingen » Wed Feb 03, 2016 5:17 pm

Nuestro ejemplo


METHOD GetFilterExp( oDBBrowse ) CLASS TMySQLRecords

LOCAL oCol
LOCAL cExp, cVal, cFil
LOCAL nAt
LOCAL lComBef, lComAft
local cFileTable := ''
Local cFieldName,cText,nPos1,nPos2,nPos3
local aCampos,cSelect
Local lHaving:=.F., cHaving:=""
local nAtHav := 0

oDBBrowse:aSelected:={}

//--- Control de existencia de algun filtro Bisoft
//--- Si no hay filtro indicado, oDBBrowse:cOrgFilter := ''
cExp := ''
FOR EACH oCol IN oDBBrowse:aCols
cExp += oCol:cFilter
NExt
IF Empty(cExp)
oDBBrowse:cOrgFilter := ''
Endif

//3/10/14 para que no genere errores con los having mezclados con los where
nAtHav := At('HAVING',upper(oDBBrowse:cOrgFilter) )
if nAtHav > 0
oDBBrowse:cOrgFilter := Left(oDBBrowse:cOrgFilter,nAtHav-1)
Endif

//--- Obtener nombre de la tabla 1º from por la derecha BiSoft
if At(' ',Alltrim(oDBBrowse:oDataSet:cName)) == 0 //cName es un nombre no una expresion
cFileTable := oDBBrowse:oDataSet:cName
cSelect := ""

ELSEIF At(' UNION ',Alltrim(oDBBrowse:oDataSet:cName)) > 0 .or. Upper(" from (")$upper(oDBBrowse:oDataSet:cName)
cFileTable := ""
ELSE
cSelect := Upper(oDBBrowse:oDataSet:cName )
Do While At(" ",cSelect )>0
cSelect := StrTran(cSelect ," "," ")
Enddo
nPos1 := Rat(' FROM ',cSelect)
if nPos1 > 0
nPos2 := at(' ',Substr(cSelect,nPos1+6))
if nPos2 == 0
cFileTable := Substr(cSelect,nPos1+6)
Else
cFileTable := Alltrim(Substr(cSelect,nPos1+6,nPos2))
Endif
Endif
Endif

if !Empty(cFileTable)
//---- Creo tabla de aCampos------------------
with object tSqlTable():Create()
:oDataSource:= AppData:oSqlSource
:cTableName := cFileTable
:nMaxRecords := 1
:lOpen := .t.
aCampos :=:FieldNames()
:lOpen := .f.
End With
cFileTable += "."
Endif
//-----------------------------------------------------

IF ! Empty( oDBBrowse:cOrgFilter )
cFil := "( " + oDBBrowse:cOrgFilter + ")"
ELSE
cFil := ""
ENDIF

FOR EACH oCol IN oDBBrowse:aCols
cVal := oCol:cFilter

IF ! Empty( cVal )
cExp := oCol:FilterEval

WITH OBJECT oCol:oDataField
lHaving := .F.
cFieldName := ""

//Si encuentro el campo de búsqueda entre los campos de la tabla
if Ascan(aCampos,{|x| Upper(x)==Upper(:cDbfName)}) != 0
cFieldName := cFileTable+:cDbfName
Else
//Y si no lo encuentro lo paso al Having
lHaving:=.T.
cFieldName := :cDbfName
Endif

DO CASE
Case cVal=="<>"
If :cType == "C" .OR. :cType == "M"
cExp := "(Length("+cFieldName+")=0 or "+cFieldName+" is Null)"
ElseIf :cType == "N"
cExp := "("+cFieldName+"=0 or "+cFieldName+" is Null)"
ElseIf :cType == "D"
cExp := "("+cFieldName+"<='0000-00-00' or "+cFieldName+" is Null)"
ElseIf :cType == "L"
cExp := "("+cFieldName+"=0 Or "+cFieldName+" is Null)"
Else
cExp := cFieldName+' is Null'
Endif

CASE :cType == "C" .OR. :cType == "M" //Campo Caracter
if Left(cVal,1)="!"
cExp := GeneraExpChar(cVal,'&',cFieldName)
Endif
if ('&' $ cVal) .or. ('#' $ cVal)
cExp := GeneraExpChar(cVal,'&',cFieldName)
ElseIF ('%' $ cVal) .and. at('%' , cVal) != 1 .and. at('%' , cVal) != len(cVal) // % Desde Hasta
cExp := GeneraExpChar(cVal,'%',cFieldName)
Else
IF Empty( cExp )
lComBef := ( Left( cVal, 1 ) == "%" )
lComAft := ( Right( cVal, 1 ) == "%" )
IF lComBef .AND. !lComAft
cVal := Substr( cVal, 2 )
cExp := cFieldName + " LIKE '%" + StrMySql( cVal ) + "'"
ELSEIF !lComBef .AND. lComAft
cVal := Substr( cVal, 1, Len( cVal ) - 1 )
cExp := cFieldName + " LIKE '" + StrMySql( cVal ) + "%'"
ELSE
IF lComBef .AND. lComAft
cVal := Substr( cVal, 2, Len( cVal ) - 2 )
ENDIF
cExp := cFieldName + " LIKE '%" + StrMySql( cVal ) + "%'"
ENDIF
ENDIF
Endif

CASE :cType == "N"
cVal:=OnlyNum(cVal,.T.,"><-.%") //Filtrar caracteres válidos para búsqueda numérica

If Vacio(cVal) .Or. Vacio(OnlyNum(cVal))
Return ""
Endif
IF ('%' $ cVal)
cExp := GeneraExpNum(cVal,'%',cFieldName)
Else
IF Empty( cExp )
cExp := cFieldName + IIF( !Left(cVal, 1) $ "<>", " = " , " " ) + Allstring(strtran(cVal,",","."))
ENDIF
Endif

CASE :cType == "D"
IF ('%' $ cVal)
cExp := GeneraExpDate(cVal,'%',cFieldName)
Else
IF Left(cVal,1) $ "<>"
nAt := 1
IF SubStr(cVal,2,1) == "="
nAt ++
ENDIF
cExp := cFieldName + " " + Left( cVal, nAt ) + " '" + DToSql( CTOD( Substr( cVal, nAt + 1 ) ) ) + "'"
ELSE
cExp := cFieldName + " = '" + DToSql( CTOD( cVal ) ) + "'"
ENDIF
Endif

CASE :cType == "L"
IF Empty( cExp )
cExp := cFieldName + " = " + IIF( Upper( Left(cVal,1) ) $ "YST1", "1" , "0" )
ENDIF
END CASE

END WITH

If !lHaving
cFil += IIF( ! Empty( cFil ), " AND ", "" ) + cExp
Else
cHaving += IIF( ! Empty( cHaving ), " AND ", "" ) + cExp
Endif

ENDIF
NEXT

cHaving:=If(!Empty(cHaving)," HAVING "+cHaving,"")
cFil:=If(Empty(cFil) .And. !Empty(cHaving),cFileTable+"Id>0 ",cFil)


Try
Application:oMainForm:oFolder:aItems[ Application:oMainForm:oFolder:nIndex ]:oLabelReg:SetText(" Reg. 0 ")
Catch
End

*MsgMemo(cFil+cHaving)

RETURN cFil+cHaving
BiSoft Desarrollo de software profesional
http://www.bisoft.es

Return to “Spanish”