Valdir Posted May 4, 2016 Report Share Posted May 4, 2016 Olá pessoal... Com o DBF, utilizo esta estrutura para realizar uma pesquisa incremental nas minhas Listbox. DEFINE DIALOG oDlg FROM 0, 0 TO 39, 120 ; TITLE OemToAnsi("Tabela de Aliqotas de I.C.M.S. nas Opera‡äe Interestaduais") ICON oIco ; STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_BORDER ); COLORS CLR_HBLUE, CLR_AZULCLARO TRANSPARENT oDlg:lHelpicon:=.f. @ 280, 000 SAY OemToAnsi("Origem :") OF oDlg ; SIZE 80,12 PIXEL RIGHT FONT oFontLbx @ 280, 085 GET oGet[1] VAR cDesc1 PICTURE "@!" PIXEL OF oDlg ; ON CHANGE ( ::Assign(), ALI->(OrdSetFocus("ORI")),; DbSeek(UPPER( SubStr( cDesc1, 1, ::nPos + " " ) + "" ),; oBrw:UpStable(), oBrw:Refresh(), .t. )) ; SIZE 100,12 COLORS CLR_HBLUE, CLR_CREME UPDATE oGet[1]:cToolTip = "Digite o Local de Origem para Pesquisar" @ 280, 200 SAY OemToAnsi("Destino :") OF oDlg ; SIZE 80,12 PIXEL RIGHT FONT oFontLbx @ 280, 285 GET oGet[2] VAR cDesc2 PICTURE "@!" PIXEL OF oDlg ; ON CHANGE ( ::Assign(), ALI->(OrdSetFocus("DES")),; DbSeek(UPPER( SubStr( cDesc2, 1, ::nPos + " " ) + ""),; oBrw:UpStable(), oBrw:Refresh(), .t. )) ; SIZE 100,12 COLORS CLR_HBLUE, CLR_CREME UPDATE oGet[2]:cToolTip = "Digite o Local de Destino para Pesquisar" É possível fazer algo parecido com a SQL ? Obrigado. Quote Link to comment Share on other sites More sharing options...
evandro Posted May 4, 2016 Report Share Posted May 4, 2016 Olá, Veja com o Alex 2002 ( não pode chamá-lo mais de Baixinho. Dizem que é buling ). Ele fez uma rotina destas que funciona perfeitamente. Acho que até publicou em "Dicas". Quote Link to comment Share on other sites More sharing options...
Wellington Vieira Posted May 5, 2016 Report Share Posted May 5, 2016 Boa noite Valdir, Em postgreSQL uma das formas que faço é assim. Espero que possa ajudá-lo. #include "FiveWin.ch" #include "common.ch" #include "postgres.ch" #include "Folder.ch" #define btn_width 12 #define btn_height 10 function listbox_clientes() private salvavarPesCli := "A" private opimcli oTitleListboxClientes = "Cliente" define brush obrush COLOR rgb(245,235,223) corfrtsay = rgb(000,000,000) // cor de frente para o say corfdosay = rgb(245,235,223) // cor de fundo para o say corfrtget = rgb(064,078,089) // cor de frente para a edi‡Æo dos campos corfdoget = rgb(255,255,255) // cor de fundo para a edi‡Æo dos campos define font mtahomapesquisaproduto name 'Tahoma' size 07,19 // define font mtahoma name "Tahoma" size 6.0,15 // font padrao para Say/Get/Botoes define font obotaof name 'MS Sans Serif' size 6,15 // font padrao para botoes define dialog listbox_clientes title oTitleListboxClientes from 000,000 to 620,1020 pixel brush obrush //transparent //STYLE nOr( WS_BORDER, WS_POPUP, WS_VISIBLE ) @ 0.1,0.3 to 1.5,72.7 label "" of listbox_clientes color corfrtsay,corfdosay @ 1.7,0.3 to 19.9,72.7 label "" of listbox_clientes color corfrtsay,corfdosay @ 20,0.3 to 22,72.7 label "" of listbox_clientes color corfrtsay,corfdosay asamplzclientes = {""} arecclientes = {} atipoclientes = {"Nome","Fantasia","Parte do nome","CNPJ","CPF","Cidade","Estado"} mtipoclientes = "Nome" mpesquisacliente = space(50) @ 009,005 say "Pesquisar por: " of listbox_clientes font mtahoma size 050,9 color corfrtsay,corfdosay pixel @ 007,050 combobox otipoclientes var mtipoclientes items atipoclientes font mtahoma size 050,25 of listbox_clientes color corfrtget,corfdoget pixel @ 007,101 get opesquisacliente var mpesquisacliente picture "@!" font mtahoma size 405,12 of listbox_clientes color corfrtget,corfdoget pixel @ 029.5,005 listbox obrzclientes fields asamplzclientes[obrzclientes:nat,1],asamplzclientes[obrzclientes:nat,2],; asamplzclientes[obrzclientes:nat,3],asamplzclientes[obrzclientes:nat,4],asamplzclientes[obrzclientes:nat,5],; asamplzclientes[obrzclientes:nat,6],asamplzclientes[obrzclientes:nat,7]; headers "Codigo","Cliente","Fantasia","CNPJ/CPF","Cidade","Estado","Estado" FIELDSIZES 050,305,210,150,160,050,045; size 500,247 on dblclick( manutencao_clientes() ) ; pixel of listbox_clientes font mtahomapesquisaproduto obrzclientes:nClrPane := {|| iif(asamplzclientes[obrzclientes:nat,7] = 'Ativo',corlstbxnormal,iif(empty(asamplzclientes[obrzclientes:nat,7]),corlstbxnormal,corlstbxdifere)) } obrzclientes:nLineStyle := 2 obrzclientes:lCellStyle = .t. obrzclientes:lAutoSkip = .t. obrzclientes:SetArray(asamplzclientes) obrzclientes:bGoTop = { || obrzclientes:nat := 1 } obrzclientes:bGoBottom = { || obrzclientes:nat := Eval( obrzclientes:bLogicLen ) } obrzclientes:bSkip = { | nWant, nOld | nOld := obrzclientes:nat, obrzclientes:nat += nWant,; obrzclientes:nat := Max( 1, Min( obrzclientes:nat, Eval( obrzclientes:bLogicLen ) ) ),; obrzclientes:nat - nOld } obrzclientes:bLogicLen = { || Len( asamplzclientes ) } obrzclientes:cAlias = "Array" obrzclientes:nColAct := 1 obrzclientes:lMChange := .F. obrzclientes:SetFocus() obrzclientes:Refresh() @ 289,012 buttonbmp olisclibut00 bitmap "bmpnovo" left prompt "Novo" textright size 040,12 font obotaof of listbox_clientes pixel @ 289,056 buttonbmp olisclibut01 bitmap "bmpalterar" left prompt "Alterar" textright size 040,12 font obotaof of listbox_clientes pixel @ 289,100 buttonbmp olisclibut03 bitmap "" left prompt "Inativar" textright size 040,12 font obotaof of listbox_clientes pixel @ 289,452 buttonbmp olisclibut10 bitmap "bmpsair" left prompt "Sair" textright size 040,12 font obotaof of listbox_clientes pixel action ( listbox_clientes:end() ) activate dialog listbox_clientes center on init pesquisa_cliente() salvavarPesCli := "A" opimcli:end() return nil function pesquisa_cliente() define timer opimcli interval 70 action psq_cliente() activate timer opimcli return nil function psq_cliente() if salvavarPesCli <> opesquisacliente:cText salvavarPesCli := opesquisacliente:cText enche_cliente() endif return nil function enche_cliente() if empty(opesquisacliente:cText) asamplzclientes = {""} arecclientes = {} obrzclientes:SetArray(asamplzclientes) obrzclientes:refresh() return .t. endif asamplzclientes = {} arecclientes = {} if mtipoclientes = "Nome" cquery := "select * from fncliente where " +; "substr(razaosocial,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " order by razaosocial asc;" elseif mtipoclientes = "Fantasia" cquery := "select * from fncliente where " +; "substr(fantasia,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " order by fantasia asc;" elseif mtipoclientes = "Parte do nome" cquery := "select * from fncliente where " +; "razaosocial like " + "'%"+alltrim(opesquisacliente:cText)+"%'"+; " order by razaosocial asc;" elseif mtipoclientes = "CNPJ" cquery := "select * from fncliente where " +; "substr(numerodocumentonacional,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " and pessoafisicajuridica = 'J'"+; " order by numerodocumentonacional asc;" elseif mtipoclientes = "CPF" cquery := "select * from fncliente where " +; "substr(numerodocumentonacional,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " and pessoafisicajuridica = 'F'"+; " order by numerodocumentonacional asc;" elseif mtipoclientes = "Cidade" cquery := "select * from fncliente where " +; "substr(cidadeibge,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " order by cidadeibge asc, razaosocial asc;" elseif mtipoclientes = "Estado" cquery := "select * from fncliente where " +; "substr(uf,1"+","+alltrim(str(len(alltrim(opesquisacliente:cText))))+")"+; " = " + "'"+alltrim(opesquisacliente:cText)+"'" +; " order by uf asc, razaosocial asc;" endif oquery := oServer:Query(cquery) DO WHILE ! oquery:Eof() // dados da tabela cliente...... a = oquery:Fieldget(oquery:Fieldpos('seqcliente')) b = oquery:Fieldget(oquery:Fieldpos('razaosocial')) fantasia = oquery:Fieldget(oquery:Fieldpos('fantasia')) c = oquery:Fieldget(oquery:Fieldpos('pessoafisicajuridica')) d = oquery:Fieldget(oquery:Fieldpos('numerodocumentonacional')) e = oquery:Fieldget(oquery:Fieldpos('cidadeibge')) f = oquery:Fieldget(oquery:Fieldpos('uf')) ativo = oquery:Fieldget(oquery:Fieldpos('ativo')) // fim dos dasdos da tabela cliente.... if !empty(a) // guarda as informações a serem vizualizadas no listbox.... aadd( asamplzclientes,{alltrim(str(a)),b,fantasia,iif(c = "J",transform(d,"@r 99.999.999/9999-99"),transform(d,"@r 999.999.999-99")),; e,f,iif( ativo = .t.,"Ativo","Inativo" ) } ) // guarda o registro onde se encontra a informação na tabela... aadd( arecclientes,a ) endif oquery:Skip() END oquery:destroy() if empty( asamplzclientes ) asamplzclientes = {""} arecclientes = {} endif obrzclientes:SetArray(asamplzclientes) obrzclientes:refresh() return nil // Cadastro de clientes ........................................................ function manutencao_clientes() if empty(arecclientes) msgStop("Escolha um cliente.","ATENÇÃO") return nil endif cquery := "select * from fncliente where "+; "seqcliente = " + alltrim(str(arecclientes[obrzclientes:nat])) + " order by seqcliente asc;" oquery := oServer:Query(cquery) mrazaosocial = oquery:Fieldget(oquery:Fieldpos('razaosocial')) oquery:destroy() msginfo(mrazaosocial) return nil Quote Link to comment Share on other sites More sharing options...
Wellington Vieira Posted May 5, 2016 Report Share Posted May 5, 2016 Só uma observação. Neste caso acima, estou utilizando a contrib do xharbour pgsql para o xharbour.. Quote Link to comment Share on other sites More sharing options...
Valdir Posted May 5, 2016 Author Report Share Posted May 5, 2016 Amigos Evandro e Wellington... Obrigado pelas respostas. Wellington, não acredito que neste caso aja diferenças entre MySql e Postgrees, más em todo caso vou dar uma estudada neste seu exemplo. Brigadão. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.