Jump to content
Fivewin Brasil

Pesquisa Caracter-a-Caracter


sig_gilberto

Recommended Posts

Olá Desenvolvedores, Bom Dia!

Preciso de uma ajuda, dica, ídéia de como fazer isso. Deixa eu ver se consigo explicar o que quero...

Pesquisar, por exemplo, nome do cliente.

Abro um Get, e na medida que eu vá digitando o nome do cliente, automaticamente, irá aparecendo num ListBox/Browse abaixo, todos os cliente do arquivo que contêm parte do nome/campo em relação ao conteúdo do que eu estou digitando... algo assim..

Daí, caso eu digite, por exemplo, SUPERMER, apareça neste ListBox/Browse, todos os registros do arquivo que têm o campo DSRAZSO tenha na sua composição a palavra SUPERMER.

Ainda, que que possa clicar e selecionar o registro depois.

É isso..só sei que foi assim!

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Editado por - sig_gilberto on 31/07/2010 10:56:09

Link to comment
Share on other sites

Olá Desenvolvedores, Bom Dia!

Preciso de uma ajuda, dica, ídéia de como fazer isso. Deixa eu ver se consigo explicar o que quero...

Pesquisar, por exemplo, nome do cliente.

Abro um Get, e na medida que eu vá digitando o nome do cliente, automaticamente, irá aparecendo num ListBox/Browse abaixo, todos os cliente do arquivo que contêm parte do nome/campo em relação ao conteúdo do que eu estou digitando... algo assim..

Daí, caso eu digite, por exemplo, SUPERMER, apareça neste ListBox/Browse, todos os registros do arquivo que têm o campo DSRAZSO tenha na sua composição a palavra SUPERMER.

Ainda, que que possa clicar e selecionar o registro depois.

É isso..só sei que foi assim!

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Editado por - sig_gilberto on 31/07/2010 10:56:09

Link to comment
Share on other sites

Olá Gilberto...

ORDWILDSEEK() resolverá seu problema.

OrdWildSeek() : Searches a value in the controlling index using wild card characters.

Syntax

OrdWildSeek( , ;

[] , ;

[] ) --> lFound

Arguments

This is a character string to search in the controlling index. It may include the wild card characters "?" and "*". The question mark matches a single character, while the asterisk matches one or more characters.

This parameter defaults to .F. (false) causing ORDWILDSEEK() to begin the search with the first record included in the controlling index. When .T. (true) is passed, the function begins the search with the current record.

If .T. (true) is passed, ORDWILDSEEK() searches towards the begin of file. The default value is .F. (false), i.e. the function searches towards the end of file.

Return value

The function returns .T. (true) if a record matching is found in the controlling index, otherwise .F. (false) is returned.

Description

ORDWILDSEEK() searches a character string that may include wild card characters in the controlling index. This allows for collecting subsets of records based on an approximate search string. Records matching the search string are found in the controlling index, and the record pointer is positioned on the found record.

When a matching record is found, the function Found() returns .T. (true) until the record pointer is moved again. In addition, both functions, BoF() and EoF() return .F. (false).

If the searched value is not found, ORDWILDSEEK() positions the record pointer on the "ghost record" (Lastrec()+1), and the function Found() returns .F. (false), while Eof() returns .T. (true). The SET SOFTSEEK setting is ignored by ORDWILDSEEK().

Examples

// The example uses two wildcard search strings to show

// possible search results of OrdWildSeek()

PROCEDURE Main

LOCAL aCust := {}

USE Customer

INDEX ON Upper(LastName) TO Cust01

DO WHILE OrdWildSeek( "*MAN?", .T. )

AAdd( aCust, FIELD->Lastname )

ENDDO

AEval( aCust, {|c| QOut© } )

// Found records:

// Dormann

// Feldman

GO TOP

aCust := {}

DO WHILE OrdWildSeek( "*EL*", .T. )

AAdd( aCust, FIELD->Lastname )

ENDDO

AEval( aCust, {|c| QOut© } )

// Found records:

// Feldman

// Hellstrom

// Keller

// Reichel

USE

RETURN

logoforum.jpg

Link to comment
Share on other sites

Olá Desenvolvedores, boa Tarde!

Se eu estiver errado, me corrijam.....rsrsra

Eu tenho um Get (TexTBox) e nele quero que, a medida eu for digitando caracter-a-caracter de uma string, um ListBox/Browse abaixo deste Get/TextBox irá sendo atualizado:refresh...e dai caso apareça o nome neste ListBox/Browse que eu queira, clico e o seleciono...

É isso as respostas dos colegas quanto ao meu questionamento ?

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Link to comment
Share on other sites

  • 2 weeks later...

Olá Desenvolvedores, boa Tarde!

Fiz um ensaio de uma pesquisa incremental em DBF/CDX

Caso possam, me ajudem :

1º Esta é melhor forma baseado na experiência dos colegas ?

2º Por que que não consigo popular o LixtBox ? Onde errei ?

============================================================

#include "Fivewin.ch"

#Include "Directry.ch"

Function PESQ()

Define Dialog oDLG Of oWnd Title " " From 00,00 to 056,160 STYLE WS_POPUP

@ 001,001 Say oSay1 VAR "CLIENTES" of oDLG FONT oFont8 Size 500,20 COLOR RGB(050,150,100)

DbUseArea(.t.,"DBFCDX","DBF\TB_CLIEN","TB_CLIEN",.t.,.f.)

DBSelectArea("TB_CLIEN")

OrdSEtFocus(2,"TB_CLIEN")

DBGotOP()

PUBLIC vLBX:="",OLBX

PUBLIC vStringBusca:=Space(50)

@ 02.00,02.5 Say "Razão Social" Of oDLG FONT oFont10 Size 999,15 COLOR RGB(050,150,100)

@ 03.20,08.3 Get oStringBusca VAR vStringBusca Pict "@K!" ;

Of oDLG FONT oFont10 Size 255,012 COLOR 0,16777215 ;

UPDATE ON CHANGE(Olbx:reFRESH(), PROCURAR(NkEY,oStringBusca))

@ 004,001 LISTBOX oLBX VAR vLBX OF ODLG SIZE 614,260 FONT oFont2 UPDATE

@ 370,604 BtnBmp oBtnSair of oDLG FILENAME "Icons\BTNSAIR1.BMP" Size 23,23 Action (Odlg:end()) NOBORDER

oBtnSair:ctooltip="Encerrar Processo..."

oDLG:LHELPICON := .F.

Activate Dialog oDLg Center

Return Nil

********************************************************************************

FUNCTION PROCURAR(NKEY)

If (nKey>=32 .or. nKey<=126)

vChave=UPPER(ALLTRIM(oStringBusca:cTITLE))

ElseIf (nKey>=32 .or. nKey<=126)

vChave=substr(UPPER(ALLTRIM(oStringBusca:cTITLE)),01,Len(UPPER(ALLTRIM(oStringBusca:cTITLE)))-1)

endif

X=0

GO TOP

While OrdWildSeek("*"+vCHAVE+"*",.t.)

vLBX=dsrazsoc

X++

EndDo

@ 02.00,60 say oSay9 Var "Achados :"+ STRZERO(X,6,0)+" "+vCHAVE Of oDLG FONT oFont10 Size 999,15 COLOR RGB(050,150,100)

OSAY9:REFRESH()

RETURN NIL

********************************************************************************

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Link to comment
Share on other sites

Olá Desenvolvedores, Bom Dia!

Fiz uma simples função sobre a minha duvida de pesquisa incremental, com DBF/CDX :

Vou melhará0-la mais ainda, mas já está funcionando que é uma beleza:

x = PesqString("CLIENTES","TB_CLIEN",2,"CodClien+'-'+DsrazSoc")

onde...

"CLIENTES" é o titulo da Dialog

"TB_CLIEN" é o nome do arquivo dbf e do alias()

2 é o número do index que será usado (OrdSEtFocus(X))

"NOME DOS CAMPOS A EXIBIR NO LISTBOX"

=========================================================

Function PesqString(b_Titulo,b_arquivo,b_ordindex,b_Campos)

Define Dialog oDLG_Pesq Of oWnd Title " " From 00,00 to 056,160 STYLE WS_POPUP

@ 001,001 Say oSay1 VAR b_titulo of oDLG_Pesq FONT oFont8 Size 500,20 COLOR RGB(050,150,100)

If DBF()#b_Arquivo

DbUseArea(.t.,"DBFCDX","DBF\"+b_arquivo,b_arquivo,.t.,.f.)

EndIf

DBSelectArea(b_arquivo)

OrdSEtFocus(b_ordindex,b_arquivo)

DBGotOP()

PUBLIC oLBX_STR,vLBX_STR:="",mLBX_STR:={}

PUBLIC vStringBusca:=Space(50)

Public b_LstCampos:=b_campos

@ 02.00,02.5 Say "A Pesquisar:" Of oDLG_Pesq FONT oFont10 Size 999,15 COLOR RGB(050,150,100)

@ 02.40,10 Get oStringBusca VAR vStringBusca Pict "@K!" ;

Of oDLG_Pesq FONT oFont10 Size 255,012 COLOR 0,16777215 ;

UPDATE ON CHANGE(PROCURAR(NkEY,oStringBusca),Iif(Len(oStringBusca:CTitle)>0,oLBX_STR:Refresh(),))

@ 007,604 BtnBmp oBtnSair of oDLG_Pesq FILENAME "Icons\BTNSAIR1.BMP" Size 23,23 Action Finalizar() NOBORDER

oBtnSair:ctooltip="Encerrar Processo..."

oDLG_Pesq:LHELPICON := .F.

Activate Dialog oDLG_Pesq Center

Return (vLBX_Str)

********************************************************************************

Static FUNCTION PROCURAR(NKEY)

If (nKey>=32 .or. nKey<=126)

vChave=UPPER(ALLTRIM(oStringBusca:cTITLE))

ElseIf (nKey>=32 .or. nKey<=126)

vChave=substr(UPPER(ALLTRIM(oStringBusca:cTITLE)),01,Len(UPPER(ALLTRIM(oStringBusca:cTITLE)))-1)

endif

vQTAchada=0

GO TOP

mLBX_STR:={}

vLBX_STR:=""

If ValType(oLBX_STR)="O"

oLBX_STR:End()

OLBX_STR:Refresh()

EndIf

Public oLBX_STR

While OrdWildSeek("*"+vCHAVE+"*",.t.)

AAdd(mLBX_STR,&B_LSTCampos)

vQTAchada++

EndDo

@ 04.20,115 say oSay9 Var iif(vQTAchada>0 .and. !Empty(Alltrim(oStringBusca:CTitle)),StrZero(vQTAchada,6,0)+;

" Registro(s) Achado(s)","Nenhum Registro Encontrado") ;

Of oDLG_Pesq FONT oFont10 ;

Size 999,20 COLOR iif(vQTAchada>0,rgb(000,000,255),rgb(255,000,100))

@ 008,004 LISTBOX oLBX_STR VAR vLBX_STR Of oDLG_Pesq PROMPTS mLBX_STR siZE 1200,730 ;

FONT oFont12 ;

COLOR RGB(000,000,255), RGB(255,255,255);

MESSAGE "Selecione o Cliente e Clique com o Mouse..." ;

UPDATE ;

ON DBLCLICK(finalizar(),vLBX_STR)

OSAY9:REFRESH()

vQtAchada:=0

RETURN NIL

********************************************************************************

Static Function Finalizar()

oDLG_Pesq:End()

Return Nil

*********************************************************************************

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Link to comment
Share on other sites

Eu faço de forma simples e funciona, é assim:

Procedure Cad_Produtos(nTp)

Local oDlg, oBrw

PRIVATE oFont

If ValType(nTp) <> "N"

nTp := 1

End

Sel("BanMerca",2)

DbGoTop()

DEFINE FONT oFont SIZE 0,-15 NAME "Times"

cProcura := Space(30)

cCampo := PadL("Descrição",20)

DEFINE DIALOG oDlg RESOURCE "DLG_CON_MER" TITLE "..:: Manutenção de Dados .::. PRODUTOS ::.."

oDlg:lTransparent := .T.

oDlg:lHelpIcon := .F.

oBrw := TxBrowse():New( oDlg )

oBrw:CreateFromResource( 101 )

oBrw:cAlias := 'BanMerca'

ADD COLUMN TO XBROWSE oBrw TITLE "" SIZE 30

*

ADD COLUMN TO XBROWSE oBrw DATA M_FAMILIA TITLE "Família" SIZE 200 ALIGN LEFT

ADD COLUMN TO XBROWSE oBrw DATA M_CODIGO TITLE "Código" SIZE 80 COLORS 128 ALIGN LEFT

ADD COLUMN TO XBROWSE oBrw DATA M_DESCRICA TITLE "Descrição" SIZE 350 COLORS 128 ALIGN LEFT

ADD COLUMN TO XBROWSE oBrw DATA M_REFERENC TITLE "Referência" SIZE 100 ALIGN LEFT

ADD COLUMN TO XBROWSE oBrw DATA M_CODBAR TITLE "Código de Barras" SIZE 100 ALIGN LEFT

*

If nTp = 1

ADD COLUMN TO XBROWSE oBrw DATA M_QUANTIDA TITLE "Estoque" PICTURE "@E 999,999.99" SIZE 90 ALIGN RIGHT

Else

ADD COLUMN TO XBROWSE oBrw DATA M_QUANTIDA TITLE "Estoque" PICTURE "@E 999,999.99" SIZE 90 ALIGN RIGHT

ADD COLUMN TO XBROWSE oBrw DATA M_CUSTO TITLE "Preço Custo" PICTURE "@E 999,999.99" SIZE 90 COLORS 128 ALIGN RIGHT

End

*

ADD COLUMN TO XBROWSE oBrw DATA M_VENDA TITLE "Preço Venda" PICTURE "@E 999,999.99" SIZE 90 COLORS 128 ALIGN RIGHT

ADD COLUMN TO XBROWSE oBrw DATA M_FORNECED TITLE "Fornecedor" SIZE 200 ALIGN LEFT

ADD COLUMN TO XBROWSE oBrw DATA M_EMINIMO TITLE "Est.Min." SIZE 50 ALIGN RIGHT

*

oBrw:nRowHeight := 30

oBrw:lColDividerComplete := .F.

oBrw:nDataLines := 2 // Number of lines of the data rows

oBrw:nHeaderLines := 2 // Number of lines of the header

oBrw:nFooterLines := 2 // Number of lines of the footer

oBrw:nDataType := 0 // Data type to be used: 0->rdd, 1->array, ... (more to come) If navigation codeblocks are not specified then get automatically initialized when adjusting the browse depending on this DATA value

oBrw:nHeaderHeight := 30

oBrw:bSeek := {|c| DbSeek(Upper( c )) }

oBrw:nFreeze := 1

oBrw:nMarqueeStyle := 5 // Marquee style (row selected) 0 No Marquee 1 Dotted cell 2 Solid cell 3 Highlight cell 4 Highlight row & Raise Cell 5 Highlight row 6 Highlight row & multiselect

oBrw:bClrSelFocus := {|| {cCorFrente, cCorFundo} }

oBrw:nColDividerStyle := 2 // Column divider style: 0 No lines 1 Black line 2 Dark gray line 3 Raised 4 Inset 5 Fore Color 6 Light gray

oBrw:nRowDividerStyle := 2 // Column divider style: 0 No lines 1 Black line 2 Dark gray line 3 Raised 4 Inset 5 Fore Color 6 Light gray

*

oBrw:aCols[3]:AddBmpFile( "BMP\Organiza.bmp" )

oBrw:aCols[3]:nHeadBmpNo := 0

oBrw:aCols[3]:nHeadBmpAlign := 1

*

oBrw:aCols[4]:AddBmpFile( "BMP\Organiza.bmp" )

oBrw:aCols[4]:nHeadBmpNo := 1

oBrw:aCols[4]:nHeadBmpAlign := 1

*

oBrw:aCols[1]:AddBmpFile( "BMP\Up.Bmp" )

oBrw:aCols[1]:AddBmpFile( "BMP\Down.Bmp" )

oBrw:aCols[1]:AddBmpFile( "BMP\Down1.Bmp" )

oBrw:aCols[1]:bBmpData := { || If( BanMerca->M_CN <= 0, 3, If(BanMerca->M_CN <= BanMerca->M_EMINIMO, 2, 1 )) }

oBrw:aCols[1]:nDataBmpAlign := 3

*

oBrw:aCols[3]:bLClickHeader := {|| Sel("BanMerca",1), oBrw:aCols[3]:nHeadBmpNo := 1, oBrw:aCols[4]:nHeadBmpNo := 0, oBrw:Refresh() }

oBrw:aCols[4]:bLClickHeader := {|| Sel("BanMerca",2), oBrw:aCols[3]:nHeadBmpNo := 0, oBrw:aCols[4]:nHeadBmpNo := 1, oBrw:Refresh() }

*

REDEFINE COMBOBOX oCbx VAR cCampo PROMPTS {"Descrição","Código","Codigo de Barras","Referência","Família","Fornecedor"} UPDATE ID 108 OF oDlg

*

REDEFINE GET oGet VAR cProcura ID 106 OF oDlg ON CHANGE (BcDdProduto(oGet,cCampo,oBrw), oDlg:Refresh())

*

REDEFINE BUTTON ID 107 OF oDlg ACTION (EditProduto(1), oDlg:Update(), oDlg:Refresh())

REDEFINE BUTTON ID 105 OF oDlg ACTION (MsgAlert("Finalizar Consulta","Mensagem"), oDlg:End())

REDEFINE BUTTON ID 102 OF oDlg ACTION (EditProduto(2), oDlg:Update(), oDlg:Refresh())

REDEFINE BUTTON ID 103 OF oDlg ACTION (Excluir(oBrw), oDlg:Update(), oDlg:Refresh())

*

ACTIVATE DIALOG odlg CENTER

*

DbCloseAll()

Return

*

Function BcDdProduto(cP,cC,oB)

Local cPro := cP:cText()

Do Case

Case AllTrim(cC) == "Descrição"

Sel(DBF(),2)

cC := "M_DESCRICA"

Case AllTrim(cC) == "Família"

Sel(DBF(),4)

cC := "M_FAMILIA"

Case AllTrim(cC) == "Fornecedor"

Sel(DBF(),3)

cC := "M_FORNECED"

Case AllTrim(cC) == "Código"

Sel(DBF(),1)

cC := "M_CODIGO"

Case AllTrim(cC) == "Codigo de Barras"

Sel(DBF(),6)

cC := "M_CODBAR"

Case AllTrim(cC) == "Referência"

Sel(DBF(),5)

cC := "M_REFERENC"

OTHERWISE

cC := "M_DESCRICA"

EndCase

*

dbSetOrder( INDEXORD() ) // define a ordem de filtro

ordScope( 0, RTrim(cPRO) ) // TOP (De...)

ordScope( 1, RTRim(cPro) ) // BOTTOM (..Até)

dbGoTop()

*

Return(.T.)

Em Cristo!

Rone - Itajubá(MG)id=red>

xHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 7.12 + xDevStudio

A pessoa que pensa que sabe alguma coisa, ainda não tem a sabedoria que precisa. (1 Cor 8, 2)id=blue>

Link to comment
Share on other sites

É isso ai!!

É que da forma que eu fiz, consigo atender todo o meu Aplicativo...

Ao passa os parâmetros de titulo, ArqDbf,... eu posso utilizar esta classe em varias outras opções como em funcionarios, clientes, fornecedores, produtos..e por ai vai...

Mas é isso ai!! SUCESSO !!

________________________

Gilberto Herminio - Programador Pleno III - Mogi das Cruzes-SP

C# / xxHB build 1.1.0 (SimpLex) & BCC 5.5.1 & FW 9.03 + xDev v0.65

"Não Desenvolvo Software, crio arte Binaria...."

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...