miércoles, 26 de junio de 2019

Búsqueda Múltiple en Visual Foxpro

Búsqueda Múltiple 

He podido ver como en los foros piden la forma o manera de realizar búsquedas múltiple en Visual Foxpro. Estos tipos de búsquedas por lo general se utilizan para negocios que manejan grandes cantidades de mercancías y requieren buscar artículos ya bien sea por descripción por marca o por modelo o por los tres casos mencionados.

Empresas de ventas de repuestos y ferreterías utilizan mucho este tipo de búsquedas en sus sistema.

Este pequeño ejemplo te ilustra como debes realizar estos procesos de búsquedas para implementarlos en tus sistemas.


Apreciarás los tipos de búsquedas que puedes realizar con tan solamente utilizar un solo texto. El programa tiene la facultad de buscar en diferentes formas los cuales detallamos a continuación :
  • Búsqueda por Concepto
  • Búsqueda por Concepto y Marca(Concepto,Marca)
  • Búsqueda por Concepto,Marca,Modelo(Concepto,Marca,Modelo)
  • Búsqueda por Marca(,Marca)
  • Búsqueda por Modelo(,,Modelo)
  • Búsqueda por Concepto,Modelo(Concepto,Modelo

Además de todos estos tipos de búsqueda, el sistema te permite buscar por la longitud del campo a buscar, es decir, que si no recuerdas el concepto completo a buscar puedes colocar las primeras iniciales del texto a buscar.

Paso 1:Evento Load del formulario

SET TALK OFF

SET SAFETY OFF
SET CONFIRM ON
SET DELETED ON
clear

Paso 2:Evento click del Command1

If !Empty(Thisform.text1.Value)
longitud_texto1=Len(Alltrim(Thisform.text1.Value))
nc=Occurs(',',Alltrim(Thisform.text1.Value))
n1= Atc(',',Alltrim(Thisform.text1.Value),1)
n2= Atc(',',Alltrim(Thisform.text1.Value),2)
Do Case
Case nc=0
longitud1=1
b1=""
b2=""
b3=""
xlen1=longitud_texto1
b1=Substr(Thisform.text1.Value,1,xlen1)
Select * From demo Into Table prueba Where Substr(Alltrim(concepto),1,xlen1)=Substr(Alltrim(b1),longitud1,xlen1)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Case nc=1
longitud1=n1-1
inicio2=n1+1
b1=""
b2=""
b3=""
xlen1=longitud_texto1-1
b1=Substr(Thisform.text1.Value,1,longitud1)
b2=Substr(Thisform.text1.Value,inicio2,xlen1)
If !Empty(b1) And !Empty(b2) And Empty(b3)
Select * From demo Into Table prueba Where Substr(Alltrim(concepto),1,longitud1)=Substr(Alltrim(b1),1,longitud1) And ;
SUBSTR(Alltrim(marca),1,xlen1-longitud1)=Substr(Alltrim(b2),1,xlen1-longitud1)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Endif
If Empty(b1) And !Empty(b2) And Empty(b3)
Select * From demo Into Table prueba Where Substr(Alltrim(marca),1,xlen1-longitud1)=Substr(Alltrim(b2),1,xlen1-longitud1)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Endif
Case nc=2
inicio2=0
longitud1=n1
inicio2=n2+1
xlen1=longitud_texto1
b1=""
b2=""
b3=""
If n1=1
b1=""
Else
b1=Substr(Thisform.text1.Value,1,longitud1-1)
Endif
If n2=2
b2=""
Else
If n2-n1=1
b2=""
Else
b2=Substr(Alltrim(Thisform.text1.Value),longitud1+1,(n2-n1))
Endif
Endif
b3=Substr(Thisform.text1.Value,inicio2,longitud_texto1-n2)
If Empty(b1) And Empty(b2) And !Empty(b3)
Select * From demo Into Table prueba Where Substr(Alltrim(modelo),1,longitud_texto1-n2)=Substr(Alltrim(b3),1,longitud_texto1-n2)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Endif    
If !Empty(b1) And Empty(b2) And !Empty(b3)
Select * From demo Into Table prueba Where Substr(Alltrim(concepto),1,longitud1-1)=Substr(Alltrim(b1),1,longitud1-1);
AND Substr(Alltrim(modelo),1,longitud_texto1-n2)=Substr(Alltrim(b3),1,longitud_texto1-n2)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Endif
If !Empty(b1) And !Empty(b2) And !Empty(b3)
Select * From demo Into Table prueba Where Substr(Alltrim(concepto),1,longitud1-1)=Substr(Alltrim(b1),1,longitud1-1);
AND Substr(Alltrim(marca),1,(longitud_texto1-n2))=Substr(Alltrim(b2),1,(longitud_texto1-n2)) ;
AND Substr(Alltrim(modelo),1,longitud_texto1-n2)=Substr(Alltrim(b3),1,longitud_texto1-n2)
Thisform.list2.RowSource  =""
Thisform.list2.NumberOfElements =0
Thisform.list2.ColumnCount =7
Thisform.list2.ColumnWidths ="40,65,167,30,61,71,50"
Thisform.list2.Requery
Thisform.list2.RowSource ="prueba.codigo,fecha,concepto,cant,precio,marca,modelo"
Thisform.list2.RowSourceType = 2
Endif
Endcase
Endif
Thisform.text1.Value=""
Thisform.text1.SetFocus









0 comentarios:

Publicar un comentario