Professional Documents
Culture Documents
anterior prxima pgina e pgina final. O usurio tambm poder digitar o nmero da pgina desejada ou selecion-la na listbox. Ser mostrado o total de pginas e a quantidade de registros da tabela. Abaixo, o formulrio de login e a listview proposta no projeto.
Pre-processadores:
O Net Express possui os pr-processadores ESQL e EHTML que permitem acessar bases de dados relacionais embutindo instrues SQL e cdigo HTML dentro de seu programa COBOL. Com o ESQL voc pode acessar uma base de dados relacional atravs de um driver ODBC embutindo instrues SQL dentro de seu programa COBOL. O EHTML permite incluir pginas HTML completas como copyfiles dentro do seu programa bem como, fragmentos de cdigos HTML como copyfiles, ou de sada individuais declaraes HTML e construir uma pgina completa sob controle CGI-COBOL.
Etapas:
Instalar ferramentas acima Criar uma conexo ODBC Criar formulrio de login e de mensagem Criar copybooks (cabec.html, detalhe.html e rodape.html) Criar projeto vazio com o Net Conectar ao database via OpenESQL Testar conexo e gerar copybook customer.cpy a ser inserido do CGI-cobol Escrever CGI-cobol Compilar, testar e exportar para o Apache
2 Etapa - Criar uma conexo ODBC Este processo bem simples mas para quem ainda no o fez, vamos aos procedimentos: Painel de controle / Ferramentas administrativas / Fontes de dados ODBC / Fontes de dados de sistema
Caso seu sistema no tenha o drive ODBC ser necessrio a instalao do mesmo.
Primeiramente crie a pasta de trabalho C:\Net31\Exemplo03. Se voc tem um formulrio prprio e prefere us-lo fique a vontade apenas altere a linha do link para action="/cgibin/viewmysql.exe" e os nomes dos campos de entrada de dados para scrUsuario e scrSenha. Mas antes de editar os cdigos HTML importante definir as imagens que sero utilizadas na pgina. Neste exemplo, a pasta imagens (C:\Net31\Exemplo03\imagens) contm os seguintes arquivos:
Edite o arquivo login.html conforme cdigo HTML abaixo e salve-o na pasta de trabalho
Dica:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <LINK rel=stylesheet href="/cobol/login.css"> <title>Cobol Web - Net Express 5.1 ListView MySQL</title> <SCRIPT language=javaScript> function validaForm(){ var frm = document.loginform; if (frm.scrUsuario.value == "") { alert("Informe o Usurio"); frm.scrUsuario.focus(); } else if (frm.scrSenha.value == "") { alert("Informe a senha"); frm.scrSenha.focus(); } else frm.submit(); } </SCRIPT> </head> <body> <div class="container"> <form action="/cgi-bin/viewmysql.exe" method="post" name="loginform" id="loginform" class="rounded" > <div class="style2"> <div align="center"><span class="style5"><img src="/cobol/imagens/ne.png" /> <span class="style6">Cobol Web</span></span> - <span class="style3">Net Express 5.1 Listview acessando MySQL </span></div>
</div> <h3> </h3> <h3 class="style6">Log in</h3> <div class="field"> <label for="name">Usurio:</label> <input name="scrUsuario" type="text" class="input" id="scrUsuario" size="15" maxlength="15" /> <p class="hint">Usurio.</p> </div> <div class="field"> <label for="email">Senha:</label> <input name="scrSenha" type="password" class="input" id="scrSenha" size="15" maxlength="15" /> <p class="hint">Senha.</p> </div> <input onClick="javascript: return validaForm()" type="button" name="button" class="button" value="Submit" /> </form> <div align="center"><span class="field">By Altair Borges</span> <br /> </div> </div> </body> </html>
</body> </html>
background: rgba(0, 0, 0, 0.6); -moz-border-radius: 7px; -webkit-border-radius: 7px; border-radius: 7px; } .button{ float: right; margin:10px 55px 10px 0; font-weight: bold; line-height: 1; padding: 6px 10px; cursor:pointer; color: #fff; text-align: center; text-shadow: 0 -1px 1px #64799e; /* Background gradient */ background: #a5b8da; background: -moz-linear-gradient(top, #a5b8da 0%, #7089b3 100%); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#a5b8da), to(#7089b3)); /* Border style */ border: 1px solid #5c6f91; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; /* Box shadow */ -moz-box-shadow: inset 0 1px 0 0 #aec3e5; -webkit-box-shadow: inset 0 1px 0 0 #aec3e5; box-shadow: inset 0 1px 0 0 #aec3e5; } .button:hover { background: #848FB2; cursor: pointer; } .style2 {color: #3333FF} .style3 { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 16px; color: #CC9933; font-weight: bold; } .style5 {color: #3333FF; font-size: 24px; } .style6 {font-size: 18px} --> </style>
Alguns recursos no foram suportados pelo IE8. Exemplo o mouseover nos campos de entrada de dados.
<META content="text/html; charset=windows-1252" http-equiv=Content-Type> <LINK rel=stylesheet href="/cobol/myCss.css"> <title>Cobol Web - Net Express 5.1 ListView MySQL</title> <SCRIPT language=javaScript> function TABEnter(oEvent){ var oEvent = (oEvent)? oEvent : event; var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement; if(oEvent.keyCode==13) oEvent.keyCode = 9; if(oTarget.type=="text" && oEvent.keyCode==13) //return false; oEvent.keyCode = 9; if (oTarget.type=="radio" && oEvent.keyCode==13) oEvent.keyCode = 9; } function Tecla(e) { var tecla = event.keyCode; if(tecla > 47 && tecla < 58) // numeros de 0 a 9 return true; else { if (tecla != 8) // backspace return false; else return true; } } function setaPagina() { document.form1.scrPagina.value = document.form1.selectBox.options[document.getElementById("selectBox").selectedIndex] .text; document.form1.submit(); } function setaPaginaDigitada() { //document.form1.scrPagina.value = document.form1.selectBox.options[document.getElementById("selectBox").selectedIndex] .text; document.form1.submit(); } function anterior() { if (document.form1.scrPagina.value > 1) { document.form1.scrPagina.value = document.form1.scrPagina.value - 1; document.form1.submit(); } } function primeira() { document.form1.scrPagina.value = 1; document.form1.submit(); } function seguinte() { p = parseInt(document.form1.scrPagina.value); u = parseInt(document.form1.scrPaginaFinal.value); if (p < u)
{ p = p + 1; document.form1.scrPagina.value = p; document.form1.submit(); } } function ultima() { document.form1.scrPagina.value = document.form1.scrPaginaFinal.value; document.form1.submit(); } </SCRIPT> <META name=GENERATOR content="MSHTML 8.00.6001.18702"> <style type="text/css"> <!-.style1 { color: #0000FF; font-weight: bold; } --> </style> </HEAD> <FORM method=post name=form1 action=/cgi-bin/viewmysql.exe> <TABLE summary="Aplicao Cobol acessando MySql usando cursor para paginao"> <CAPTION style4> Aplicao <span class="style1">Cobol Web</span> com Net Express 5.1/ JavaScript / Css / MySQL <BR> Listview acessando MySQL e usando cursor para paginação </CAPTION> <TBODY> <TR bgColor=#cccccc> <TD> <DIV align=center>Id</DIV></TD> <TD> <DIV align=center>First_name</DIV></TD> <TD> <DIV align=center>Last_name</DIV></TD> <TD> <DIV align=center>E-mail</DIV></TD></TR> Observe que falta o fechamento das tags </tabela>, </form> e </html>. Isto ser realizado no arquivo rodape.html. O conceito de pgina dinmica o mesmo de um relatrio. Voc escreve o cabealho, l o arquivo para imprimir as linhas de detalhes e por ltimo imprime o rodap. detalhe.html O arquivo detalhe.html dever ficar dentro do loop do programa COBOL que gera a linha de detalhe.
rodape.html </TABLE> <style type="text/css"> <!-.style9 {font-family: "Courier New", Courier, monospace} .style14 { color: #CC3300; font-weight: bold; } .style18 {font-family: "Courier New", Courier, monospace; color: #CCCC00; } --> </style> <table> <tr bgcolor=#DDDDDD> <td width="50"><img src="/COBOL/imagens/first.png" width="48" height="48" border="0" title="Primeira página" onClick="primeira()" /></td> <td width="51"><img src="/COBOL/imagens/left.png" width="48" height="48" border="0" title="Página anterior" onClick="anterior()" /></td> <td width="239"> <div align="center" class="style9">Página: <input name="scrPagina" type="text" id="scrPagina" value=" 1" size="5" maxlength="5" onchange="setaPaginaDigitada()" title="Digite a pgina e tecle ENTER" onkeypress="return Tecla(event)" onkeydown="TABEnter()"/> de <input name="scrPaginaFinal" type="text" disabled class="centraliza" id="scrPaginaFinal" value=" 40" size="5" maxlength="5" /> </div></td> <td width="51"><img src="/COBOL/imagens/right.png" width="48" height="48" border="0" title="Pgina seguinte" onClick="seguinte()" /></td> <td width="52"><img src="/COBOL/imagens/last.png" width="48" height="48" border="0" title="ltima pgina" onClick="ultima()" /></td> <td width="72"><label> <select id="selectBox" name="selectBox" onchange="setaPagina()"> end-exec *> Cdigo cobol dentro da pginha html perform varying idx from 1 by 1 until idx > wTotalPaginas if idx = f-scrPagina *> posiciona select <listbox) na pgina atual String "<option value="'"' idx '"' "selected>" f-scrPagina "</option>" Delimited by size into strSelect else String "<option value="'"' idx '"' ">" idx "</option>" Delimited by size into strSelect end-if exec html :strSelect end-exec end-perform move wRegistros to maskPagina
String " N de Linhas: " maskPagina Delimited by size into strTexto exec html </select> </label></td> <td width="186"><div align="left"><span class="style9">Lanamentos:</span><span class="style14"> 599</span></div></td> </tr> <tr align="right"> <td colspan="7"> <span class="style18">By Altair Borges</span> </td> </tr> </table> </body> </html> No rodap foi inserido o fechamento das tags </tabela>, </form> e </html> alm de um perform para montagem da selectbox variando de acordo com a quantidade de pginas encontradas em wTotalPaginas Edite o arquivo myCss.css conforme cdigo CSS abaixo e salve-o na pasta de trabalho
C:\Net31\Exemplo03
table{width:80%; border-collapse:collapse; margin:1em 0px;} caption { font-family: "Calibri"; background: #FFCC33; font-size: 18px; } th, td { font-family:"Courier New"; font-size:14px; font-size-adjust:inherit padding:.2em; border:1px solid #fff;} .centraliza { text-align: center; } A estrutura da pgina dinmica est pronta e ser montada pela CGI COBOL.
5 Etapa - Crie o projeto viewmysql vazio com o Net e conecte ao database via OpenESQL
O objetivo do projeto usar a IDE do NE para editar e debugar.
Acessando o database SAKILA atravs do OpenESQL Assistent. Este aplicativo ir lhe auxiliar na gerao dos copybooks de cdigo COBOL para acessar o database. Estes fragmentos podem ser includos diretamento no programa cobol pelo Assistent.
O OpenESQL Assistent cria a estrutura de comunicao entre o programa COBOL e o banco de dados. Se j existir um programa.cbl no projeto e voc clicar cone inserido o cdigo fonte da query no fonte COBOL. ser
Clique em SQLCA e depois em Host Variable Declarations para gerar as reas de comunicao entre MySQL e Fonte COBOL.
program-id. viewmysql. Author. Altair Borges /2012 configuration section. special-names. decimal-point is comma. working-storage section. 01 campos-auxiliares. 03 w-Msg pic x(90) value spaces. 03 wPagina pic 9(04) value 1. 03 wTotalPaginas pic 9(04) value zeros. 03 wRegistros pic 9(06) value zeros. 03 wPosicao pic 9(06) value zeros. 03 wQuantidade pic 9(02) value 15. 03 wResto pic 9(02) value zeros. 03 res pic x(01) value spaces. 03 idx pic 9(05) value zeros. 03 strSelect pic x(50). 03 strTexto pic x(20). 03 wLnk pic x(90). 03 wStatus pic zzzzz. 03 wcodigo pic zz.zzz. 03 maskPagina pic zzzzz. 03 maskPaginaFinal pic zzzzz. 03 ws-cnOdbc pic x(09) value "viewmysql". *>---------------------------------------------------------------*> The following field receives ESQL error messages wider than the *> 70 bytes provided by the SQLCA field SQLERRMC 03 MFSQLMessageText pic x(256). *> The name of the file used to store server state 03 state-filename pic x(255) value "MF-STATE-SAVE.DAT". *> Status returned by state maintenance routines
pic x comp-x. pic x(07) value spaces. pic x(07) value "#e5f1f4". pic x(07) value "#F0FFF0".
01 HTMLFormLogin is external-form. 03 f-scrUsuario pic x(15) identified by "scrUsuario". 03 f-scrSenha pic x(15) identified by "scrSenha". 01 HTMLFormView is external-form. 03 f-scrPagina pic 9(5) identified by "scrPagina". 03 f-scrPaginaFinal pic 9(5) identified by "scrPaginaFinal". 03 f-scrLinhas pic 9(5) identified by "scrLinhas". EXEC SQL INCLUDE customer END-EXEC EXEC SQL INCLUDE SQLCA END-EXEC exec sql begin declare section end-exec 01 h-customer-id pic 9(04). 01 h-store-id pic 9(04). 01 h-first-name pic x(45). 01 h-last-name pic x(45). 01 h-email pic x(50). 01 h-address-id pic 9(04). 01 h-active pic 9(04). 01 h-create-date pic x(19). 01 h-last-update pic x(19). exec sql end declare section end-exec. Procedure division. perform 1000-inicializa perform 2000-validaAcesso perform 3000-processa perform 4000-finaliza stop run. *---------------1000-inicializa. call "sstate" call "MF_CLIENT_STATE_FILE" using state-filename server-status accept htmlFormView accept htmlFormLogin if f-scrPagina = zeros move 1 to f-scrPagina end-if move f-scrPagina to wPagina maskPagina move f-scrPaginaFinal to wTotalPaginas move f-scrLinhas to wRegistros Exit. *-----------------2000-ValidaAcesso. call "cbl_tolower" using f-scrUsuario by value 15 call "cbl_tolower" using f-scrSenha by value 15 String f-scrusuario "." f-scrsenha delimited by spaces
into w-msg End-String exec sql connect to :ws-cnOdbc user :w-msg connect to 'viewMySql' user 'root.12345' end-exec if sqlcode not = 0 perform 2100-acessoNegado perform 4000-finaliza end-if. * * * * * * * * * * * * * * if sqlcode not = 0 exec html <br><br><em> There was an error connecting to the database.>br><br> SQLSTATE = :sqlstate<br><br> SQL Error Message = :MFSQLMessageText<br><br> </em> </body> </html> end-exec exit program stop run end-if Exit.
*-----------------2100-AcessoNegado. exec html copy "msgAcesso.html". end-exec Exit. *-------------3000-processa. perform 3100-Cabecalho perform 3200-leitura Exit. *--------------3100-cabecalho. exec html copy "cabec.html". end-exec Exit. *------------3200-leitura. if f-scrPaginaFinal not equal zeros perform 3210-posiciona-ponteiro perform 3220-mostra-dados Exit Paragraph end-if *> Pega a quantidade de linhas da tabela if wRegistros = 0 exec sql select count(*) into :wRegistros from `customer` end-exec
move wRegistros to f-scrlinhas *> Calcula o nmero de pginas divide wRegistros by wQuantidade giving wTotalPaginas remainder wResto end-divide if wResto > 0 add 1 to wTotalPaginas end-if move wTotalPaginas to f-scrPaginaFinal maskPaginaFinal end-if perform 3210-posiciona-ponteiro perform 3220-mostra-dados Exit. *-----------------------3210-Posiciona-ponteiro. compute wPosicao = (wQuantidade * wPagina) - wQuantidade Exit. *-----------------3220-Mostra-dados. Exec sql Declare csr1 cursor for select `A`.`customer_id` ,`A`.`first_name` ,`A`.`last_name` ,`A`.`email` from `customer` A order by `A`.`customer_id` limit :wQuantidade offset :wPosicao; End-exec if sqlcode not = 0 perform 9000-msg-error end-if Exec sql open csr1 End-exec if sqlcode not = 0 perform 9000-msg-error end-if Perform until sqlcode not = zero Exec sql fetch csr1 into :h-customer-id ,:h-first-name ,:h-last-name ,:h-email End-exec if sqlcode = 0 perform 3230-Detalhe end-if End-Perform
Exec sql close csr1 End-exec perform 3240-Rodape Exit. *------------3230-detalhe. if corFundo = spaces or corFundo = cor1 move cor2 to corFundo else move cor1 to corFundo end-if initialize wlnk String *> link p/ o programa clientes.exe a ser implementado '<A href="/cgi-bin/clientes.exe?scrCodigo=' h-customer-id '&scrAcao='"Pesquisa"'">'h-customer-id'</A>' into wlnk end-string move h-customer-id to wcodigo exec html <Tr bgcolor=:corFundo> <td width="15%" align=center> :wlnk </td> <td width="40%"> :h-first-name </TD> <td width="15%"align=center> :h-last-name </td> <td width="30%"> :h-email </td> </Tr> end-exec Exit. *-----------3240-rodape. exec html copy "rodape.html". end-exec Exit. *-------------4000-finaliza. perform 4100-disconecta exit program stop run Exit. *---------------4100-disconecta. exec sql disconnect current end-exec Exit. *--------------9000-msg-Error. move sqlcode to wStatus exec html <html> Cdigo do Erro: :wStatus :SQLERRMC
EXE gerado hora de configurar o Animate, mas antes, preciso alterar a porta do
WebServer SOLO, pois ele por padro usa a porta 80 a mesma que, neste caso, est sendo usada pelo Apache. Altere para 8686, por exemplo. Menu / Options / Project
O cone aparecer na bandeja do Windows D um duplo Clique e verifique se a configurao est igual figura abaixo:
Na caixa de texto Start Animating at informe: http://127.0.0.1/COBOL/login.html Marque tambm a opo Wait for animatable attachment e clique em ok Pressione F11 para animar ou F5 para executar
Abra o browser e digite na URL o seguinte endereo: http://localhost/COBOL/login.html O resultado dever ser este:
At a prxima.
Livro
http://www.agbook.com.br/book/34170--Cobol_Web
Comentrios e sugestes borgesaltair@hotmail.com
2011