Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.0 kB
2
Indexable
Never
cStr = Allt(Upper(This.Value))+' '
If Empty(cStr)
	Return
Endif

* Preparar el string para obtener los elementos a buscar
cStr = StrTran(cStr,' ','^')
nItems = Occurs('^',cStr)

If Empty(_BusqCliCamposBuscar)
	cCamposBuscar = 'NOMCLI+TELEFONO+RFC+NOMCOMER'
Else
	cCamposBuscar = _BusqCliCamposBuscar
Endif
cCamposBuscar =  'STRTRAN(STRTRAN(STRTRAN(STRTRAN('+cCamposBuscar+' ," ",""),"-",""),")",""),"(","")'

cTable = 'Clientes'
cOrderField = 'NOMCLI'

Do Case
Case nItems == 1
	cSql = 'Select * , Recno() As Recno from '+cTable+' '+;
			'Where Val1 $ Upper('+cCamposBuscar+' ) '+;
			'Order By '+cOrderField
			
Case nItems == 2
	cSql = 'Select * , Recno() As Recno from '+cTable+' '+;
			'Where '+;
				'Val1 $ Upper('+cCamposBuscar+' ) and '+;
				'Val2 $ Upper('+cCamposBuscar+' ) '+;
			'Order By '+cOrderField

Case nItems == 3
	cSql = 'Select * , Recno() As Recno from '+cTable+' '+;
			'Where '+;
				'Val1 $ Upper('+cCamposBuscar+' ) and '+;
				'Val2 $ Upper('+cCamposBuscar+' ) and '+;
				'Val3 $ Upper('+cCamposBuscar+' ) '+;
			'Order By '+cOrderField
			
Otherwise
	cSql = 'Select * , Recno() As Recno from '+cTable+' '+;
			'Where '+;
				'Val1 $ Upper('+cCamposBuscar+' ) and '+;
				'Val2 $ Upper('+cCamposBuscar+' ) and '+;
				'Val3 $ Upper('+cCamposBuscar+' ) and '+;
				'Val4 $ Upper('+cCamposBuscar+' ) '+;
			'Order By '+cOrderField
			
EndCase



If not SqlMsl('Temp',cSql,SubLin(cStr,1),SubLin(cStr,2),SubLin(cStr,3),SubLin(cStr,4))
	Alerta('Problemas con sql')
	Return
Endif

Wait Clear

With ThisForm.List1
	Select Temp
	.RowSourceType = 6 && Alias
	.Clear
	If Empty(_BusqCliAnchoCol)
		.ColumnCount=6
		.ColumnWidths='200,30,80,100,100,100'
	Else
		.ColumnCount=Occurs(',',_BusqCliAnchoCol)+1
		.ColumnWidths = _BusqCliAnchoCol
	Endif
	If Empty(_BusqCliCamposMostrar)
		.RowSource='NOMCLI,NUMCLI,TELEFONO,CALLE,CIUDAD,RFC'
	Else
		.RowSource=_BusqCliCamposMostrar
	Endif
	.ListIndex=1
EndWith


If Reccount('Temp')==0
	Alerta('No se encontró ningún cliente con esas palabras')
	Return 0
Endif
Leave a Comment