Ola marcelo, tentei inserir o que voce sugeriu mas não consegui, ficou dando alguns erros, então resolvi posta o codigo do arquivo abaixo para vc dar uma olhadinha para mim.
O codigo ta um poquinho confuso, porque eu andei alterando, hehehe, mas ta funcionando assim como está, soh precisaria fazer essa verificação do cnpj. Otra coisa, é dificil, de quando ele verificar, ao invés de dizer, que este cnpj ja está cadastrado para outro cliente, de aparecer o codigo do cliente para qual eles ja está cadastrado?
EXEMPLO: Este CNPJ ja está cadastrado no sistema, para o cliente de N° xxxxx!!!
Código: Selecionar todos
clear
cbc()
SET EXCLUSIVE OFF
SET CURS ON
SETCOLOR(cor2)
cx(1,0,19,79,"CADASTRO DE CLIENTES",80)
do telacli
STOR CTOD(' / / ') TO XUCOMPRA,CXDATEMI
STOR 0.00 TO XTOTVALOR,XUVALOR
STOR 0 TO XTOTPARES,XTOTCOMPRAS,XUPARES
STOR ('N') TO XCREDAFET
STOR SPACE(63) TO XOBS,XLOCALPGTO,XLOCALENTR,xobsref
STOR SPACE(45) TO XMOTIVO
STOR SPACE(15) TO XCIDADE
STOR SPACE(15) TO XBAIRRO
stor space(26) to XFANTASIA
stor space(40) to Xendereco,XRAZAO
stor space(6) to xnum
STOR SPACE(20) TO XCARIMBO
stor space(02) to xuf
stor space(13) to xfone
stor space(13) to xfax
STOR space(15) TO XINSC
stor space(23) to xcomple
stor space(26) to xcompra
stor space(26) to xemail
stor space(8) to xcep
STOR 0 TO XCODREp,XCODTRASN,xgrade
stor space(15) to xcnpj
//STOR (' . - ') TO XCEP
cxdatemi=date()
SETCOLOR(cor2)
CLOSE data
sele 0
use cadgra inde cadgra alias gra
set index to cadgra
sele 0
use cadtra inde cadtra alias tra
set index to cadtra
SELE 0
USE CADuf INDE CADuf ALIAS ff
SET INDEX TO CADuf
SELE 0
USE CADREp INDE CADREP ALIAS REP
SET INDEX TO CADREP
sele 0
use cadcli inde cadcli alias cli
set index to cadcli,razao
DO while .T.
SELE cli
GOTO BOTT
XCODCLI=CODCLI+1
@ 03,16 SAY XCODCLI PICT "999999"
cc=savescreen(0,0,24,79)
SELE cli
READ
IF LASTKEY()=27
close all
EXIT
ENDIF
// if xcodcli=0 .or. empty(xcodcli)
if lastkey()=28
restscreen(0,0,24,79,cc)
setcolor(cor2)
do selcli
restscreen(0,0,24,79,cc)
set inde to cadcli,razao
@ 03,16 say XCODCLI PICT "999999"
cs=savescreen(0,0,24,79)
read
setcolor(cor2)
if lastkey()=27
loop
endif
if empty(xcodcli) .or. xcodcli=0
restscreen(0,0,24,79,cc)
close all
exit
endif
endif
SELE cli
SEEK XCODCLI
READ
restscreen(0,0,24,79,cc)
IF FOUN()
XCODCLI = CODCLI
XRAZAO = RAZAO
XCODREp = CODREP
XFANTASIA = FANTASIA
XCARIMBO = CARIMBO
XENDERECO = ENDERECO
xnum = num
XBAIRRO = BAIRRO
XUF = UF
XCEP = CEP
XCIDADE = CIDADE
XINSC = INSC
XCNPJ = CNPJ
xfone = fone
xfax = fax
XCODTRASN = CODTRASN
XLOCALPGTO = LOCALPGTO
XLOCALENTR = LOCALENTR
XUCOMPRA = UCOMPRA
XuPARES = uPARES
XuVALOR = uVALOR
XTOTCOMPRAS = TOTCOMPRAS
XTOTPARES = TOTPARES
XTOTVALOR = TOTVALOR
XCREDAFET = CREDAFET
XMOTIVO = MOTIVO
XOBS = OBS
XDATEMI = DATEMI
xcompra = compra
xemail = email
xcomple = comple
@ 03,47 SAY Xdatemi
@ 04,16 SAY XRAZAO PICT "@k!"
@ 05,16 SAY XFANTASIA PICT "@k!"
@ 05,59 SAY XCARIMBO PICT "@k!"
@ 06,16 say xcodrep pict "999999"
@ 07,16 SAY XENDERECO PICT "@k!"
@ 07,73 say xnum pict "@K!"
@ 08,16 SAY XUF PICT "@k!"
@ 08,28 SAY XCEP PICT "@R 99.999-999"
@ 08,56 say xcomple pict "@k!"
@ 09,16 SAY XCIDADE PICT "@K!"
@ 09,56 SAY XBAIRRO PICT "@k!"
@ 10,16 SAY XINSC PICT "@K!"
@ 10,56 SAY XCNPJ PICT "@R 99.999.999/9999-99"
@ 11,16 say xfone pict "(99)999-99999"
@ 11,56 say xfax pict "(99)999-99999"
@ 12,16 say xcompra pict "@K!"
@ 13,16 say xemail pict "@K!"
@ 14,16 SAY XCODTRASN PICT "999999"
@ 15,16 SAY XLOCALPGTO PICT "@k!"
@ 16,16 SAY XLOCALENTR PICT "@K!"
@ 17,16 SAY XOBS PICT "@k!"
xconf="N"
ss=savescreen(0,0,24,79)
tone(800)
@ 24,5 SAY "Deseja o Cadastro deste Cliente? <S/N>" get xconf pict "!" valid xconf $ "SN"
read
IF LASTKEY()=27
DO LIMPAR
LOOP
ENDIF
if xconf="S"
rlock()
delet
commit
unlock
do limpar
loop
endif
if xconf="N"
restscreen(0,0,24,79,ss)
endif
endif
@ 03,47 say cxdatemi
@ 04,16 get XRAZAO PICT "@k!" valid !empt(xrazao)
@ 05,16 get XFANTASIA PICT "@k!"
@ 05,59 get XCARIMBO PICT "@k!"
@ 06,16 get XCODREp PICT "999999"
READ
if lastkey()=27
do limpar
loop
endif
if empty(xcodrep) .or. xcodrep=0
ss=savescreen(00,00,24,79)
do selrep
sele rep
set inde to cadrep
restscreen(0,0,24,79,ss)
set color to (cor2)
@ 06,16 get XCODrep PICT "999999"
read
if lastkey()=27 .or. empty(xcodrep) .or. xcodrep=0
do limpar
loop
endif
endif
SELE rep
SEEK xcodrep
IF FOUNd()
SETCOLOR(cor2)
@ 06,23 SAY SUBS(NOME,1,50)
ELSE
tone(800)
@ 24,5 SAY "Este Representante NÆo est Cadastrado !"
inkey(0)
do limpar
loop
endif
sele cli
@ 07,16 get XENDERECO PICT "@k!"
@ 07,73 get xnum pict "@K!"
@ 08,16 get XUF PICT "!!" valid !empt(xuf)
READ
SELE ff
SEEK xuf
IF !FOUN()
tone(800)
@ 24,5 SAY "AVISO: UF Inv lida!!"
inkey(0)
do limpar
loop
ELSE
endif
sele cli
@ 08,28 get XCEP PICT "@R 99.999-999"
@ 08,56 get xcomple pict "@K!"
@ 09,16 get XCIDADE PICT "@K!"
@ 09,56 get XBAIRRO PICT "@k!"
@ 10,16 get XINSC PICT "@K!" valid !empt(XINSC) .AND. ieok(xuf,xinsc)
@ 10,56 get XCNPJ PICT "@R 99.999.999/9999-99" valid !empt(xcnpj) .AND. vcgc(xcnpj)
@ 11,16 get xfone pict "(99)999-99999"
@ 11,56 get xfax pict "(99)999-99999"
@ 12,16 get xcompra pict "@K!"
@ 13,16 get xemail pict "@K!"
@ 14,16 get XCODTRASN PICT "999999"
READ
if lastkey()=27
do limpar
loop
endif
if empty(xcodtrasn) .or. xcodtrasn=0
ss=savescreen(00,00,24,79)
do seltra
sele tra
set inde to cadtra
restscreen(0,0,24,79,ss)
set color to (cor2)
@ 14,16 get XCODtrasn PICT "999999"
read
if lastkey()=27 .or. empty(xcodtrasn) .or. xcodtrasn=0
do limpar
loop
endif
endif
SELE tra
SEEK xcodtrasn
IF FOUNd()
SETCOLOR(cor2)
@ 14,23 SAY SUBS(razao,1,50)
ELSE
tone(800)
@ 24,5 SAY "Esta Transportadora Nao esta Cadastrada !"
inkey(0)
do limpar
loop
endif
sele cli
@ 15,16 get XLOCALPGTO PICT "@k!"
@ 16,16 get XLOCALENTR PICT "@K!"
@ 17,16 get XOBS PICT "@k!"
read
if lastkey()=27
do limpar
loop
endif
conf=" "
tone(880)
@ 24,5 say "Deseja Gravar o Cadastro deste Cliente! <S/N> " get conf pict "!!" valid conf $ "SN"
read
if conf = "S"
do gravar
do limpar
loop
endif
if lastkey()=27 .or. conf="N"
do limpar
loop
endif
enddo
close all
return
****tela
procedure telacli()
SETCOLOR('N/W')
*/ 0....x....1....x....2....x....3....x....4....x....5....x....6....x....7....x....8/*
@ 03,02 say "C¢d.Client..: Data de Cadastro..: "
@ 04,02 say "RazÆo Social: "
@ 05,02 say "Nome Fantas.: Carimbo Espec.: "
@ 06,02 say "Cod.Repres..: "
@ 07,02 say "Endere‡o....: Nø: "
@ 08,02 say "UF..........: CEP...: Complemento: "
@ 09,02 say "Cidade......: Bairro.....: "
@ 10,02 say "Insc.Estad..: CNPJ.......: "
@ 11,02 say "Fone........: FAX........: "
@ 12,02 say "Comprador...: "
@ 13,02 say "E-mail:.....: "
@ 14,02 say "C¢d.Transp..: "
@ 15,02 say "Local Pgto..: "
@ 16,02 say "Local Entre.: "
@ 17,02 say "Observ......: "
return
**************************************
*********limp cadastro
proc limpar()
STOR CTOD(' / / ') TO XUCOMPRA,CXDATEMI
STOR 0.00 TO XTOTVALOR,XUVALOR
STOR 0 TO XTOTPARES,XTOTCOMPRAS,XUPARES
STOR ('N') TO XCREDAFET
STOR SPACE(63) TO XOBS,XLOCALPGTO,XLOCALENTR,xobsref
STOR SPACE(45) TO XMOTIVO
STOR SPACE(15) TO XCIDADE,XBAIRRO
STOR SPACE(25) TO XFANTASIA
stor space(40) to xendereco,XRAZAO
stor space(6) to xnum
STOR SPACE(20) TO XCARIMBO
stor space(02) to xuf
stor space(13) to xfone
stor space(13) to xfax
STOR space(15) TO XINSC
stor space(23) to xcomple
stor space(26) to xcompra
stor space(26) to xemail
STOR 0 TO XCODREp,XCODTRASN,xgrade
stor space(14) to xcnpj
stor space(8) to xcep
cxdatemi=date()
restscreen(0,0,24,79,cc)
retu
**********gravar
proc gravar()
sele cli
seek xcodcli
if foun()
rlock()
else
appe blank
endif
replace CODCLI with XCODCLI,;
RAZAO with XRAZAO,;
FANTASIA with XFANTASIA,;
CARIMBO with XCARIMBO,;
ENDERECO with XENDERECO,;
NUM with XNUM,;
BAIRRO with XBAIRRO,;
UF with XUF,;
CEP with XCEP,;
CIDADE with XCIDADE,;
INSC with XINSC,;
comple with xcomple,;
CNPJ with XCNPJ,;
LOCALPGTO with XLOCALPGTO,;
localentr with Xlocalentr,;
CREDAFET with XCREDAFET,;
MOTIVO with XMOTIVO,;
OBS with XOBS,;
DATEMI with CXDATEMI,;
CODTRASN with XCODTRASN,;
CODREp with XCODREp,;
fone with xfone,;
compra with xcompra,;
email with xemail,;
fax with xfax
commit
unlock
return