Jump to content
Fivewin Brasil

PESQUISA INCREMENTAL BANCO DE DADOS MYSQL


marcioe

Recommended Posts

Bom dia,

Eu uso assim para POSTGRESQL e LISTBOX, se servir de consulta para ajudar. 

#include "FiveWin.ch"
#include "common.ch"
#include "postgres.ch"

#define btn_width  12
#define btn_height 10

function listbox_clientes()
         local lobjet
         private salvavarPesCli := "A"
         private opimcli
		 
         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
         corfdojan      = rgb(245,235,223)
         corlstbxnormal = rgb(255,255,255)
         corlstbxdifere = rgb(228,218,191)
         define brush obrush COLOR corfdojan
         define font mtahomapesquisaproduto name 'Tahoma' size 07,19/
		 
         define dialog listbox_clientes title "Clientes" 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","Codigo","Fantasia","Parte do nome","CNPJ","CPF","Cidade","Estado","E-mail"}
                mtipoclientes    = "Nome"
                mpesquisacliente = space(50)
				
                @ 007,101 get opesquisacliente var mpesquisacliente picture "@!" font mtahoma size 405,12 of listbox_clientes color corfrtget,corfdoget pixel
                @ 009,005 say "Pesquisar por: " of listbox_clientes font mtahoma size 050,9 color corfrtsay,corfdosay 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 = .f.
                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()
                @ 007,050 combobox otipoclientes var mtipoclientes items atipoclientes font mtahoma size 050,90 of listbox_clientes color corfrtget,corfdoget pixel


                @ 287,012 BTNBMP olisclibut00 left size 045,19 font obotaof noborder resource "geral_novo"    of listbox_clientes pixel
				@ 287,060 BTNBMP olisclibut01 left size 045,19 font obotaof noborder resource "geral_alterar" of listbox_clientes pixel
				@ 287,460 BTNBMP olisclibut10 left size 045,19 font obotaof noborder resource "geral_sair"    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 = "Codigo"
                cquery := "select * from fncliente where " +;
                          "seqcliente = " + alltrim(opesquisacliente:cText) +;
                          " order by seqcliente 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;"
         elseif mtipoclientes = "E-mail"
                cquery := "select * from fncliente where " +;
                          "email like " + "'%"+alltrim(opesquisacliente:cText)+"%'"+;
                          " order by razaosocial asc;"
         endif
         oquery := oServer:Query(cquery)
         DO WHILE ! oquery:Eof()
            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'))
            g = oquery:Fieldget(oquery:Fieldpos('email'))
            if !empty(a)
               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" ) } )
               aadd( arecclientes,a )
               if !empty(g)		   
                  aadd( asamplzclientes,{"",g,"","",;
                                         "","","" } )
                  aadd( arecclientes,a )
			   endif
		   
            endif
            oquery:Skip()
         END
         oquery:destroy()
         if empty( asamplzclientes )
             asamplzclientes  = {""}
             arecclientes     = {}
         endif
         obrzclientes:SetArray(asamplzclientes)
         obrzclientes:refresh()
return nil

function manutencao_clientes()
         if empty(arecclientes)
            msgStop("Escolha um cliente.","ATENÇÃO")
            return nil
         endif
         mseqcliente = arecclientes[obrzclientes:nat]

         cquery := "select * from fncliente where "+;
                   "seqcliente = " + alltrim(str(mseqcliente)) + " order by seqcliente asc;"
         oquery := oServer:Query(cquery)
         mpessoafisicajuridica      = oquery:Fieldget(oquery:Fieldpos('pessoafisicajuridica'))
		 
		 // restante dos dados...
		 
		 oquery:destroy()
return nil

 

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...