Página 1 de 1

Harbour+LetoDB+HTML 5+JavaScript e + outros...

Enviado: 12 Dez 2013 13:42
por Itamar M. Lins Jr.
Ola!
Terminando com a exclusividade de uma só linguagem!
Tudo junto e misturado!

Código: Selecionar todos

#include "rddleto.ch"

MEMVAR _SERVER, _REQUEST, _GET, _POST, _COOKIE, _SESSION, _HTTP_REQUEST, _HTTP_RESPONSE
REQUEST DBFNTX, DBFCDX, DBFFPT, DBFDBT, LETO
REQUEST HB_LANG_PT,HB_CODEPAGE_PTISO,HB_CODEPAGE_PT850

FUNCTION HRBMAIN(...)

LOCAL cHtml := "", cCodVendedor,cLogin,cSenha,cPDV,cEscolha,cCodCliente,cCliente
LOCAL cLoginCripto, cSenhaCripto, cEOL := hb_eol()
LOCAL cPATH := "//localhost:2812/"
LOCAL cCargo := ""

cPDV         := uhttpd_GetField( "cPDV"  )
cLogin       := uhttpd_GetField( "cLogin" )
cSenha       := uhttpd_GetField( "cSenha" )
cCargo       := uhttpd_GetField( "cCargo" )

cEscolha     := uhttpd_GetField( "cEscolha"  )
cCodCliente  := uhttpd_GetField( "cCodCliente" )
cCliente     := uhttpd_GetField( "cCliente" )
cCodVendedor := uhttpd_GetField( "cCodVendedor" )

hb_default( @cPDV  , "" )
hb_default( @cLogin, "" )
hb_default( @cSenha, "" )
hb_default( @cCargo, "" )
hb_default( @cEscolha  , "" )
hb_default( @cCodCliente, "" )
hb_default( @cCliente, "" )
hb_default( @cCodVendedor, "" )


HB_CDPSELECT([PTISO])
hb_langselect([PT])
Set Deleted On

RDDSetDefault("LETO")

leto_commit()
DBCloseAll()

If cEscolha = "LANCAR_MAIS"
Else
   If select('vd') > 0
      vd->(DBCloseArea())
   EndIf

   cIndex := cPATH+"vendedor.cdx"
   DbUseArea(.t.,'LETO',cPATH+"vendedor.dbf","vd",.T.,.F.,'PTISO')
   DBSETINDEX( cIndex )

   vd->(OrdSetFocus(2)) //Vendedor
   cLogin := pad(cLogin,len(vd->vendedor))
   If vd->(DbSeek(cLogin))
   Else
      Return html_erro(cLogin,cSenha)
   EndIf

   If alltrim(cSenha) == alltrim(vd->senha)
   Else
      Return html_erro(cLogin,cSenha)
   EndIf

   cCargo       := vd->cargo
   cCodVendedor := vd->cod_vended
   vd->(dbCloseArea())

   If select("me") > 0
      me->(DBCloseArea())
   EndIf

   cIndex := cPATH+"mesas.cdx"
   DbUseArea(.t.,'LETO',cPATH+"mesas.dbf","me",.T.,.F.,'PTISO')
   DBSETINDEX( cIndex )

   If me->(DbSeek(cPDV))

      If me->status == 'U'
         If alltrim(me->dono) == "ESPERA"
         Else
            Return FarolWebErro('PDV em uso por: '+me->dono,cPDV,cLogin,cSenha,cCargo)
         EndIf
      EndIf

      If MyRlock('me')
         me->status := "U"
         me->dono   := cLogin
      Else
         Return FarolWebErro('Falha travando registro PDV. ')
      EndIf

   Else

      Do While .T.
         me->(DbAppend())
         If neterr()
            Inkey(.1)
         Else
            exit
         EndIf
      EndDo

      me->mesa   := cPDV
      me->status := 'U'
      me->dono   := cLogin

   EndIf

   me->(dbCloseArea())

   //--------------------------Ver itens comandados
   If cEscolha == "VER" .or. cEscolha == "FECHAR"
      Return PDVProdutosVer(cPATH,cPDV,cCodVendedor,cLogin,cSenha,cCargo,cCodCliente,cCliente)
   EndIf
   //-------------------------
EndIf

If select('gr') > 0
   gr->(DbCloseArea())
EndIf

cIndex := cPATH+"grupos.cdx"
DbUseArea(.t.,'LETO',cPATH+"grupos.dbf","gr",.T.,.F.,'PTISO')
DBSETINDEX( cIndex )

cLoginCripto := cLogin //cripto(cLogin,.T.)
cSenhaCripto := cSenha //cripto(cSenha,.T.)
//#pragma __cstream | cHtml += %s

cHtml := ""
cHtml += '<!DOCTYPE html>' + cEOL
cHtml += '<html manifest="nocache.manifest" lang="pt-BR">' + cEOL
cHtml += '<head>' + cEOL
cHtml += '<title>FAROL PDV WEB - GRUPOS</title>' + cEOL
cHtml += '<meta charset="WINDOWS-1252">' + cEOL
cHtml += '<div align="left">' + cEOL
cHtml += '<link rel="stylesheet" type="text/css" href="/css/estilo.css"/>' + cEOL
cHtml += '</head>' + cEOL
cHtml += '<body>'
cHtml += '<h1>Farol WEB GRUPOS</h1>' + cEOL
cHtml += '<hr>' + cEOL

cHtml += '<form name=grupos method="post" action="produtos.hrb">' + cEOL

cHtml += '<input type="hidden" name="cCodVendedor" value="'+ cCodVendedor + '">' + cEOL
cHtml += '<input type="hidden" name="cLogin"       value="'+ cLoginCripto + '">' + cEOL
cHtml += '<input type="hidden" name="cSenha"       value="'+ cSenhaCripto + '">' + cEOL
cHtml += '<input type="hidden" name="cCargo"       value="'+ cCargo + '">'       + cEOL
cHtml += '<input type="hidden" name="cPDV"         value="'+ cPDV + '">'         + cEOL
cHtml += '<input type="hidden" name="cCodCliente"  value="'+ cCodCliente + '">'  + cEOL
cHtml += '<input type="hidden" name="cCliente"     value="'+ cCliente + '">'     + cEOL

gr->(DBGoTop())
Do While gr->(!Eof())
   //cHtml += '<a class="bt" name="cCodGrupo">'
   cHtml += '<button class="bt" style="width:600px;" name="cCodGrupo" type="submit" value="'+gr->cod_grupo+'-'+gr->grupo+ '">' + ;
                                          '<img src="/imagens/icons/accept.png" alt="" /> ' + gr->grupo +'</button><p><p>' + cEOL
   //cHtml += '</a>'
   gr->(DBSkip())
EndDo

cHtml += '</form></body></div></html>' + cEOL

hb_MemoWrit("grupos.html",cHtml)
leto_commit()
DBCloseAll()
RETURN cHtml

SET PROCEDURE TO "farol_lib.prg" //lib de funções
Outro com Harbour + JavaScript + [ER] Expressão regular para colocar mascara no HTML "@E 99,999.99" e outras validações do lado cliente.

Código: Selecionar todos

******************************************************************************************************
Function FecharPDV(cPATH,cPDV,cCodVendedor,cLogin,cSenha,cCargo,cCodCliente,cCliente,nTotal,nComissao)
******************************************************************************************************
*
*
Local cHtml := ""
nTotal := Val(StrTran(nTotal,",",".")) + Val(strtran(nComissao,",","."))
nTotal := AllTrim(Transform(nTotal,"@E 99,999,999.99"))

cHtml += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
cHtml += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
cHtml += '<html><head>'+hb_eol()
cHtml += '<title>Sistema Farol Web</title>'+hb_eol()
cHtml += '<meta http-equiv = "Content-Type" content="text/html; charset=iso-8859-1">'+hb_eol()
cHtml += '<script type="text/javascript" src="/cgi-bin/mascara.js"> </script>'+hb_eol()
cHtml += '<link rel="stylesheet" href="/css/radiocheck.css"/>'+hb_eol()
//scHtml +=	'<style type="text/css"> label {margin-right:20px;} </style>'
cHtml += '<script type="text/javascript">'+hb_eol()
cHtml += '        function somarValores(){'+hb_eol()
cHtml += '        var s1 = document.getElementById("xTotal").value.replace(/,/gi, ".");'+hb_eol()
cHtml += '        var s2 = document.getElementById("nPago").value.replace(/,/gi, ".");'+hb_eol()
cHtml += '        var s3 = parseFloat(s2) - parseFloat(s1);'+hb_eol()
cHtml += '        s3 = Math.round(s3*100)/100;'+hb_eol()
cHtml += '        var s4 = s3.toString().replace(/\./gi, ",");'+hb_eol()
cHtml += '        document.getElementById("nTroco").value = s4'
cHtml += '    }'+hb_eol()
cHtml += '</script>'+hb_eol()

cHtml += '</head>'+hb_eol()
cHtml += '<div align="left">'+hb_eol()
cHtml += '<body>'+hb_eol()
cHtml += '<form name=fechamento action="/cgi-bin/fechar.hrb" method="post">'  +hb_eol()

cHtml += '<input type="hidden" name="cCodVendedor" value="'+ cCodVendedor + '">'+hb_eol()
cHtml += '<input type="hidden" name="cLogin"       value="'+ cLogin + '">'      +hb_eol()
cHtml += '<input type="hidden" name="cSenha"       value="'+ cSenha + '">'      +hb_eol()
cHtml += '<input type="hidden" name="cCargo"       value="'+ cCargo + '">'      +hb_eol()
cHtml += '<input type="hidden" name="cPDV"         value="'+ cPDV + '">'        +hb_eol()
cHtml += '<input type="hidden" name="cCodCliente"  value="'+ cCodCliente + '">' +hb_eol()
cHtml += '<input type="hidden" name="cCliente"     value="'+ cCliente + '">'    +hb_eol()
cHtml += '<input type="hidden" name="nTotal"       value="'+ nTotal + '">'      +hb_eol()

cHtml += '<h1>Farol Web Iniciando Fechamento</h1>' +hb_eol()
cHtml += '<h1>PDV: '+cPDV+' '+cCliente+'</h2>'+hb_eol()

cHtml += '<h2>Caixa: '+cCodVendedor+" - "+cLogin+hb_eol()+'</h2>'+hb_eol()
cHtml += '<hr>'
cHtml += '<table>'
cHtml += '<tr><td><xlabel style="font-size:35px;">Somente itens marcados </label></td><td><input id="chk1" type="checkbox" name="cMarcados" value="chk1"><label for="chk1"></label></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Desconto concedido     </label></td><td><input style="font-size:40px;width:270px;" type="text"   name="nDesconto" value="0" onkeypress="mascara(this,mvalor);" maxlength="15"></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Divisão por pessoas    </label></td><td><input style="font-size:40px;width:075px;" type="number" name="nDivisao"  value="1"></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Total do PDV           </label></td><td><input style="font-size:40px;width:270px;" type="text"   name="xTotal"    value="'+nTotal+'" disabled=true id="xTotal"></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Valor Pago             </label></td><td><input style="font-size:40px;width:270px;" type="text"   name="nPago"     value="0" onkeypress="mascara(this,mvalor);" maxlength="15" onblur="somarValores()" id="nPago"></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Total da Comissão      </label></td><td><input style="font-size:40px;width:270px;" type="text"   name="nComissao" value="'+nComissao+'" onkeypress="mascara(this,mvalor);" maxlength="15"></td></tr>'+hb_eol()
cHtml += '<tr><td><xlabel style="font-size:35px;">Troco                  </label></td><td><input style="font-size:40px;width:270px;" type="text"   name="nTroco"    onkeypress="mascara(this,mvalor);" maxlength="15" id="nTroco"></td></tr>'+hb_eol()
cHtml += '</table>'
cHtml += '<button class="bt-02" style="font-size:40px;width:300px" name="cEscolha" value="PAGAMENTO" type="submit"> <img src="/imagens/icons/printer.png" alt=""/> FECHAR </button>'
cHtml += '<button class="bt-02" style="font-size:40px;width:300px" name="cEscolha" value="PREVIA" type="submit"> <img src="/imagens/icons/printer.png" alt=""/> PRÉVIA </button>'

cHtml += '</form></body></div></html>'

Return cHtml
Ps. Ah! sim ia me esquecendo, funciona em qualquer coisa! Tablet, POCKET, IPHONE, Smartfone...

Saudaçõe,
Itamar M. Lins Jr.

Harbour+LetoDB+HTML 5+JavaScript e + outros...

Enviado: 31 Dez 2013 11:51
por sygecom
O Vagner mostrou algo assim alguns anos atrás, porém não deu continuidade no projeto, não compilou mais com versões mais recentes do xHarbour e Harbour e acredito que o projeto deva está parado( que é uma pena ).
http://www.vagucs.com.br/cgi-bin/vagucs ... dioma=ptbr

Harbour+LetoDB+HTML 5+JavaScript e + outros...

Enviado: 31 Dez 2013 21:54
por marcosgambeta
sygecom escreveu:O Vagner mostrou algo assim alguns anos atrás, porém não deu continuidade no projeto, não compilou mais com versões mais recentes do xHarbour e Harbour e acredito que o projeto deva está parado( que é uma pena ).
Além deste projeto do Vagner, tivemos iniciativas da parte do Vailton Renato, Lailton Mariano, Antonio Linares e Roberto Lopez.

Não sei dizer qual o status dos respectivos projetos, pois preciso me atualizar, mas é inegável que dá para fazer muita coisa interessante usando Harbour/xHarbour e cgi's (combinando HTML, CSS, Javascript, JQuery ou outra biblioteca similar).

Dependendo do serviço de hospedagem, nem seria preciso um servidor próprio. Me recordo de um teste que fiz, poucos anos atrás, usando o serviço de hospedagem Linux do UOL Host. Instalei um CentOS virtual, compilei alguns cgi's nele (usando xHarbour) e consegui executá-los no site do UOL. Funcionou bem, mas acabamos por optar por um servidor virtual com Windows Server, por causa de outros fatores.

Mas se o serviço de hospedagem for Linux e aceitar cgi's em C/C++, então pode ser que seja possível usar cgi's criados com Harbour/xHarbour nele. Naturalmente, é preciso pesar o custo/benefício, pois hoje temos PHP, ASP.NET e outras opções para criação de sites.