olá achei isso, veja se te ajuda.
William
//
// Recuperar inventario da ANVISA para o SNGPC.
// Manoel Angeiras, 2011
//
#define STRU_TMP { { "NUMMS ", "C", 13, 0 }, { "NOMEPRO ", "C", 46, 0 },;
{ "NUMLOTE ", "C", 20, 0 }, { "QTDLOTE ", "N", 6, 0 } }
***************
FUNCTION MAIN()
***************
if !InternetOK()
Alert("Sem conexão com a Internet. Verifique...")
return .F.
endif
//
// ABERTURA DAS FUNCOES PARA WEBSERVICE DO XHARBOUR
//
try
http := CreateObject( "MSXML2.XMLHTTP" )
catch
try
http := CreateObject( "MSXML2.XMLHTTP" )
catch
Alert("Erro na criação do objeto MSXML2.XMLHTTP : " + Ole2TxtError())
end
end
//
// AS COMUNICACOES SEGUINTES FORAM BASEADAS NA MINHA OBSERVACAO DE LOGIN
// MANUAL NO SITE DA ANVISA, USANDO UM WEB DEBUGGER
//
//
// VERIFICAR A DISPONIBILIDADE DO SITE DA ANVISA
//
cRet := RequestOpen()
//
// CONFIGURAR E LER COOKIE CRIADO POR ESSA COMUNICACAO
//
cCookie := LerCookie()
//
// FAZER LOGIN NO SITE ANVISA
//
cRet := Login( alltrim( cCookie ), SEU_EMAIL, SUA_SENHA )
memowrit("lerinv.txt", cRet)
//
// SALVEI A RESPOSTA EM .TXT, MAS NA VERDADE UM XML, ACHO QUE Dµ PRA LER
// COM A CLASSE TxmlDocument
//
cEmpresa := cRT := cNome := ""
AchaToken("lerinv.txt", @cEmpresa, @cRT, @cNome)
if empty( cEmpresa )
Alert("Problema na identificacao da empresa. Verifique...")
return .F.
endif
if empty( cRT )
Alert("Problema na identificacao do Responsavel Tecnico. Verifique")
return .F.
endif
//
// SELECIONA A EMPRESA. TEM AQUI UMA LIMITACAO : O RESPONSAVEL TECNICO SO
// PODE ESTAR LIGADO A UMA EMPRESA ( FARMACEUTICO NO INTERIOR DOS ESTADOS
// PODEM CONTROLAR AT DUAS FARMACIAS/DROGARIAS ). SE POSSUIR MAIS DE UMA
// EMPRESA, NAO LE CORRETAMENTE
//
cRet := SelEmpresa( cCookie, cEmpresa, cRT, cNome )
memowrit("lerinv.txt", cRet)
cID1 := AchaToken2("lerinv.txt")
//
// SELECIONA RESPONSAVEL TECNICO
//
cRet := SelRT( cCookie, cEmpresa, cRT, cNome, cID1 )
//
// LER MENU DO SITE ANVISA
//
LerMenu( cCookie )
//
// LER INVENTARIO. ACHO QUE ESSE PASSO PODE SER DESCONSIDERADO
//
cRet := VerInv( cCookie )
memowrit("verinv.txt", cRet)
//
// CHAMO A TELA DE FINALIZACAO DO INVENTARIO, QUE CONTEM OS PRODUTOS COM OS
// SEUS LOTES
//
cRet := FimInv( cCookie )
memowrit("lotesinv.txt", cRet)
//
// GRAVO O RESULTADO EM UM DBF PARA PROCESSAR DEPOIS
//
lRet := CriaDBF( "lotesinv.txt" )
RETURN lRet
*****************************
STATIC FUNCTION REQUESTOPEN()
*****************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "GET", "http://homologacao.anvisa.gov.br/sngpc/", .F. )
http:SetRequestHeader( "Accept", "*/*" )
http:SetRequestHeader( "Accept-Language", "pt-br" )
http:SetRequestHeader( "Accept-Encoding", "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
//
// ENDERECOS DE PRODUCAO
//
// http:Open( "GET", "https://sngpc.anvisa.gov.br/", .F. )
// http:SetRequestHeader( "Accept", "*/*" )
// http:SetRequestHeader( "Accept-Language", "pt-br" )
// http:SetRequestHeader( "Accept-Encoding", "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:send()
response := http:statusText
RETURN response
***************************
STATIC FUNCTION LERCOOKIE()
***************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "GET", "http://homologacao.anvisa.gov.br/sngpc/includes/fundo.asp", .F. )
http:SetRequestHeader( "Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" )
http:SetRequestHeader( "Referer", "http://homologacao.anvisa.gov.br/sngpc/" )
http:SetRequestHeader( "Accept-Language", "pt-br" )
http:SetRequestHeader( "Accept-Encoding", "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "GET", "https://sngpc.anvisa.gov.br/includes/fundo.asp", .F. )
// http:SetRequestHeader( "Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" )
// http:SetRequestHeader( "Referer", "https://sngpc.anvisa.gov.br/" )
// http:SetRequestHeader( "Accept-Language", "pt-br" )
// http:SetRequestHeader( "Accept-Encoding", "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:send()
response := http:getResponseHeader("Set-Cookie")
RETURN response
************************************************
STATIC FUNCTION LOGIN( cCookie, memail, msenha )
************************************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "POST", "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/login.asp" )
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Keep-Alive" , "115" )
http:SetRequestHeader( "Cookie" , cCookie )
http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "POST", "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/login.asp" )
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Keep-Alive" , "115" )
// http:SetRequestHeader( "Cookie" , cCookie )
// http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
http:send( "email=" + memail + "&senha=" + msenha + "&Entrar=Entrar" )
response := http:responseText
RETURN response
******************************************************
STATIC FUNCTION SELEMPRESA( cCookie, cID, cRT, cNome )
******************************************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "POST", "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp")
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Keep-Alive" , "115" )
http:SetRequestHeader( "Cookie" , cCookie )
http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "POST", "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp")
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Keep-Alive" , "115" )
// http:SetRequestHeader( "Cookie" , cCookie )
// http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
http:send( "hidPasso=1&hidPessoaRepresentada=" + cID +;
"&hidTipoPessoaRepresentada=&hidPessoaFisica=" + cRT +;
"&hidNomeEmpresa=" + cNome +;
"&hidRepresentante=&hiComboRepresentacao=&hiComboRepresenta=" + cID +;
"&Representa=&Representacao=&IDPESSOAREPRESENTADA=" + cID )
response := http:responseText
RETURN response
*******************************************************
STATIC FUNCTION SELRT( cCookie, cID, cRT, cNome, cID1 )
*******************************************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "POST", "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp")
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Keep-Alive" , "115" )
http:SetRequestHeader( "Cookie" , cCookie )
http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "POST", "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp")
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Keep-Alive" , "115" )
// http:SetRequestHeader( "Cookie" , cCookie )
// http:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
http:send( "hidPasso=2&hidPessoaRepresentada=" + cID +;
"&hidTipoPessoaRepresentada=1" +;
"&hidPessoaFisica=" + cRT +;
"&hidNomeEmpresa=" + cNome +;
"&hidRepresentante=" + cID1 +;
"&hiComboRepresentacao=RESPONS%C1VEL+T%C9CNICO" +;
"&hiComboRepresenta=" + cID +;
"&Representa=" + cID +;
"&Representacao=" +;
"&IDPESSOAREPRESENTADA=" + cID +;
"&CBOTIPOS=1" )
response := http:responseText
RETURN response
**********************************
STATIC FUNCTION LERMENU( cCookie )
**********************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "GET", "http://homologacao.anvisa.gov.br/sngpc/includes/menu.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/AcessoPersistir.asp")
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Cookie" , cCookie )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "GET", "https://sngpc.anvisa.gov.br/includes/menu.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/AcessoPersistir.asp")
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Cookie" , cCookie )
http:send()
response := http:responseText
RETURN response
*********************************
STATIC FUNCTION VERINV( cCookie )
*********************************
//
// ENDERECO DE HOMOLOGACAO
//
http:Open( "GET", "http://homologacao.anvisa.gov.br/sngpc/sngpc_frmVisualizaInventario.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/menu.asp")
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Cookie" , cCookie )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "GET", "https://sngpc.anvisa.gov.br/sngpc_frmVisualizaInventario.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/menu.asp")
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Cookie" , cCookie )
http:send()
response := http:responseText
RETURN response
*********************************
STATIC FUNCTION FIMINV( cCookie )
*********************************
//
// ENDERECO HOMOLOGACAO
//
http:Open( "GET", "http://homologacao.anvisa.gov.br/sngpc/sngpc_frmFinalizaInventario.asp", .F. )
http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
http:SetRequestHeader( "Referer" , "http://homologacao.anvisa.gov.br/sngpc/includes/menu.asp")
http:SetRequestHeader( "Accept-Language" , "pt-br" )
http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
http:SetRequestHeader( "Host" , "homologacao.anvisa.gov.br" )
http:SetRequestHeader( "Connection" , "Keep-Alive" )
http:SetRequestHeader( "Cookie" , cCookie )
//
// ENDERECO DE PRODUCAO
//
// http:Open( "GET", "https://sngpc.anvisa.gov.br/sngpc_frmFinalizaInventario.asp", .F. )
// http:SetRequestHeader( "Accept" , "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" )
// http:SetRequestHeader( "Referer" , "https://sngpc.anvisa.gov.br/includes/menu.asp")
// http:SetRequestHeader( "Accept-Language" , "pt-br" )
// http:SetRequestHeader( "Accept-Encoding" , "gzip, deflate" )
// http:SetRequestHeader( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; BTRS25991; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; AskTB5.6)" )
// http:SetRequestHeader( "Host" , "sngpc.anvisa.gov.br" )
// http:SetRequestHeader( "Connection" , "Keep-Alive" )
// http:SetRequestHeader( "Cookie" , cCookie )
http:send()
response := http:responseText
RETURN response
**************************************************
STATIC FUNCTION ACHATOKEN( cFile, cEmp, cRT, cRS )
**************************************************
local aLines, nHand2, nA, nB, nPos, cRet := ""
aLines := {}
nHand2 := fopen( cFile )
cLine := ""
while HB_FReadLine( nHand2, @cLine ) == 0
aadd( aLines, upper( cLine ) )
enddo
aadd( aLines, cLine )
fClose( nHand2 )
for nA := 1 to len( aLines )
if ( nPos := at( '<INPUT TYPE="HIDDEN" NAME="HIDPESSOAFISICA" VALUE="', aLines[nA] ) ) # 0
for nB := nPos+51 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # '"'
cRT += substr( aLines[ nA ], nB, 1 )
else
exit
endif
next
endif
if ( nPos := at( "<OPTION VALUE='", aLines[nA] ) ) # 0
for nB := nPos+15 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "<"
cEmp += substr( aLines[ nA ], nB, 1 )
else
exit
endif
next
endif
next
x1 := x2 := ""
lOK:= .F.
for nA := 1 to len( cEmp )
if substr( cEmp, nA, 1 ) # "'" .and. !lOk
x1 += substr( cEmp, nA, 1 )
else
if !lOK
nA++
lOk := .T.
else
x2 += substr( cEmp, nA, 1 )
endif
endif
next
cEmp := x1
cRS := strtran( x2, " ", "+" )
RETURN
***********************************
STATIC FUNCTION ACHATOKEN2( cFile )
***********************************
local aLines, nHand2, nA, nB, nPos, cRet := ""
aLines := {}
nHand2 := fopen( cFile )
cLine := ""
while HB_FReadLine( nHand2, @cLine ) == 0
aadd( aLines, alltrim( upper( cLine ) ) )
enddo
aadd( aLines, cLine )
fClose( nHand2 )
for nA := 1 to len( aLines )
if ( nPos := at( "<OPTION ID='", aLines[nA] ) ) # 0
for nB := nPos+12 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "'"
cRet += substr( aLines[ nA ], nB, 1 )
else
exit
endif
next
endif
next
RETURN cRet
********************************
STATIC FUNCTION CRIADBF( cFile )
********************************
local aLines, nHand2, nA, nB, nPos, cRet := ""
aLines := {}
nHand2 := fopen( cFile )
cLine := ""
while HB_FReadLine( nHand2, @cLine ) == 0
aadd( aLines, alltrim( upper( cLine ) ) )
enddo
aadd( aLines, cLine )
fClose( nHand2 )
lMS := lNome := lLote := lQtd := .F.
cMS := cNome := cLote := cQtd := ""
aInv:= {}
for nA := 1 to len( aLines )
//
// LE O MS DO PRODUTO
//
if ( nPos := at( '<TD WIDTH="17%" CLASS="SEMBORDA" HEIGHT="20">', aLines[nA] ) ) # 0
for nB := nPos+45 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "<"
cMS += substr( aLines[ nA ], nB, 1 )
lMS := .T.
else
exit
endif
next
endif
//
// LE O NOME DO PRODUTO
//
if ( nPos := at( '<TD WIDTH="50%" CLASS="SEMBORDA" HEIGHT="20">', aLines[nA] ) ) # 0
for nB := nPos+45 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "<"
cNome += substr( aLines[ nA ], nB, 1 )
lNome := .T.
else
exit
endif
next
endif
//
// LE O LOTE DO PRODUTO
//
if ( nPos := at( '<TD WIDTH="18%" CLASS="SEMBORDA" HEIGHT="20">', aLines[nA] ) ) # 0
for nB := nPos+45 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "<"
cLote += substr( aLines[ nA ], nB, 1 )
lLote := .T.
else
exit
endif
next
endif
//
// LE A QUANTIDADE DO PRODUTO
//
if ( nPos := at( '<TD WIDTH="15%" CLASS="SEMBORDA" HEIGHT="20">', aLines[nA] ) ) # 0
for nB := nPos+45 to len( aLines[ nA ] )
if substr( aLines[ nA ], nB, 1 ) # "<"
cQtd += substr( aLines[ nA ], nB, 1 )
lQtd := .T.
else
exit
endif
next
endif
if lMS .and. lNome .and. lLote .and. lQtd
aadd( aInv, { cMS, cNome, cLote, cQtd } )
lMS := lNome := lLote := lQtd := .F.
cMS := cNome := cLote := cQtd := ""
endif
next
if empty( aInv )
return .F.
endif
dbCreate( "TEMP.DBF", STRU_TMP )
use ("TEMP.DBF") alias tmp exclusive new
if neterr()
return .F.
endif
for nA := 1 to len( aInv )
tmp->(dbAppend())
tmp->numms := TiraPonto( aInv[ nA, 1 ] )
tmp->nomepro := aInv[ nA, 2 ]
tmp->numlote := aInv[ nA, 3 ]
tmp->qtdlote := val( aInv[ nA, 4 ] )
next
tmp->(dbCloseArea())
RETURN .T.
*******************************
STATIC FUNCTION TIRAPONTO( ms )
*******************************
local nA, nLen := len( alltrim( ms ) ), cRet := ""
for nA := 1 to nLen
if isdigit( substr( ms, nA, 1 ) )
cRet += substr( ms, nA, 1 )
endif
next
RETURN cRet
*********************
FUNCTION InternetOK()
*********************
local aHosts, cName, cAddress := "www.google.com.br"
InetInit()
aHosts := InetGetHosts( cAddress )
if aHosts == NIL .or. len(aHosts) == 0
InetCleanup()
return .F.
endif
InetCleanup()
RETURN .T.