Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2003, 10:50 PM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP Navigation not working?????

I have 2 form buttons PREVIOUS and NEXT that don´t work when clicked on. Any clues would be greatly appreciated. Here is the code (reduced)::












      <FORM action="<% = Request.ServerVariables("SCRIPT_NAME") %>" method=post id=form1 name=form1>

        <INPUT type="submit" value="New Orders" name=submit>
        <INPUT type="submit" value="All Orders" name=submit>
        <INPUT type="submit" value="Orders Completed" name=submit>

      </FORM>
      <%
If IsEmpty(Request.QueryString("Codigo")) Then

  Dim PagAtual, objCon, objRS, strQ, TotPag, Cont, NumPagMax, VarPagMax 'Declara as variáveis
  Const RegPorPag = 500 'Informa o numero total de registros a serem exibidos por página
  If Request.ServerVariables("CONTENT_LENGTH") = 0 Then 'Se for a primeira vez que a página é carregada:
    PagAtual = 1 'Define o valor da página atual em 1
  Else 'E se não for a primeira vez que a página é carregada:
    PagAtual = CInt(Request.Form("txtPagina")) 'Define o valor da página atual a ser exibida igual a (txtPagina)
   Select Case Request.Form("submit")
      Case "Previous" 'Se o botão (Previous) for acionado:
         PagAtual = PagAtual - 1 'Diminui o valor da página atual em 1
      Case "Next" 'Se o botão (Next) for acionado:
         PagAtual = PagAtual + 1 'Aumenta o valor da página atual em 1
      Case "Menos" 'Se o link com o (Submit=Menos) for clicado:
         NumPagMax = NumPagMax - VarPagMax 'Diminui (VarPagMax) ao valor de (NumPagMax)
      Case "Mais" 'Se o link com o (Submit=Mais) for clicado:
         NumPagMax = NumPagMax + VarPagMax 'aumenta (VarPagMax) ao valor de (NumPagMax)
      Case Else'Se um link com o número da página for clicado:
         PagAtual = 1 'Define o valor da página atual em 1
     End Select
     If NumPagMax < PagAtual then 'Se o número máximo do índice retornar maior que a última página do índice:
        NumPagMax = NumPagMax + VarPagMax 'Aumenta o valor máximo do indice
     End If
     If NumPagMax - (VarPagMax - 1) > PagAtual then'Se o número máximo do índice retornar menor que a página atual:
        NumPagMax = NumPagMax - VarPagMax 'Aumenta o valor máximo do indice
     End If
  End If

  Set objCon = Server.CreateObject("ADODB.Connection") 'Cria um objeto de conexão com o banco de dados
  objCon.Open "dbq=D:\www\##\db\Cadastro.mdb;Driver={Microso ft Access Driver (*.mdb)};" 'abre a conexão com o banco de dados

  Set objRS = Server.CreateObject("ADODB.Recordset") 'Cria um objeto Recordset para o recurso de paginação
  objRS.CursorLocation = 3 '(3 = adUseClient); define o cursor do Recordset como residente no cliente
  objRS.CursorType = 3 '(3 = adOpenStatic); define o tipo de cursor do Recordset como estático
  objRS.LockType = 1 '(1 = adLockReadOnly); define o tipo de cursor de Recordset como somente leitura
  objRS.CacheSize = RegPorPag 'define o tamanho do cache da página do Recordset igual a (RegPorPag)

  If Request.Form("Submit") = "New Orders" Then
    strQ = "Select * From Pedidos Where Baixa = 'N' Order By Data DESC, Codigo"
  Else If Request.Form("Submit") = "All Orders" Then
    strQ = "Select * From Pedidos Order By Data DESC, Codigo"
  Else If Request.Form("Submit") = "Orders Completed" Then
    strQ = "Select * From Pedidos Where Baixa = 'S' Order By Data DESC, Codigo"
  Else If IsEmpty(Request.Form("Submit")) then
    strQ = "Select * From Pedidos Where Baixa = 'N' Order By Data DESC, Codigo"
  Else
    strQ = Request.Form("Form_strQ")
  End If : End If : End If: End If

  objRS.Open strQ, objCon, , , &H0001 ' abre o Recordset para o recurso de paginação
  objRS.PageSize = RegPorPag ' Define o tamanho da página de registros do Recordset igual a (RegPorPag)
  Set objRS.ActiveConnection = Nothing 'Desconecta o Recordset do objeto de conexão
  objCon.Close 'Fecha o objeto de conexão com o banco de dados
  Set objCon = Nothing 'Libera a variável (objCon) da memória

  If Not(objRS.EOF) Then 'Se a consulta SQL retornar com dados:
    objRS.AbsolutePage = PagAtual 'Define que a pagina a ser retornada será a (PagAtual)
    TotPag = objRS.PageCount 'Especifica o total de registros retornados na consulta
    MostraDados 'Executa a rotina (MostraDados) para exibir os dados no browser
  Else 'E se a consulta SQL não retornar com dados:
    MostraNada 'Executa a rotina (MostraNada) para exibir uma mensagem no browser
  End If
  objRS.Close 'Fecha o Recordset de paginação
  Set objRS = Nothing 'Livera a variável (objRS) da memória

Else

  If IsEmpty(Request.QueryString("Efetuar")) Then
    Visualizar_Pedido
  Else
    'Dá baixa ao pedido
    Efetua_Pedido
  End If

  'Libera variaveis da memória
  Set PagAtual = Nothing
  Set objCon = Nothing
  Set objRS = Nothing
  Set strQ = Nothing
  Set TotPag = Nothing
  Set Cont = Nothing
  Set NumPagMax = Nothing
  Set VarPagMax = Nothing

End If
%><CENTER>
    </TD>
  </TR>
</TABLE>

<BR>
<CENTER>
    <CENTER>
</CENTER></CENTER>
</BODY>
</HTML>

<% Sub MostraDados() %>
<CENTER>
<STRONG>&nbsp;&nbsp;Product List</STRONG>
 :: There are <b><%= objRS.RecordCount %></b> orders<BR><BR>
<TABLE border=1 width=80% align=center cellpadding=1 cellspacing=1 bordercolor=#CCCCCC height=100>
  <TR bgcolor=#CCCCCC height=1>
    <TD align=center><B>No.</B></TD>
    <TD><B>Date of order</B></TD>
    <TD nowrap align=center><B>Client Code</B></TD>
    <TD nowrap align=center><B>Complete</B></TD>
  </TR>
<%
Dim Cor, x : x = 1
For Cont = 1 to objRS.PageSize 'Faz um loop para mostrar todos os dados da página
  If x = 1 Then
    Cor = "#f4f4f4"
    x = 2
  Else
    Cor = "white"
    x = 1
  End If
  %>
  <TR bgcolor=<% = cor %>>
    <TD bgcolor=white align=center valign=top>

      <%=(PagAtual * RegPorPag + Cont) - RegPorPag %></TD>
    <TD valign=top>
      <A href="<% = Request.ServerVariables("SCRIPT_NAME") & "?Codigo=" & objRS("Codigo") & "&Data=" & objRS("Data")%>">

      <%=objRS("Data")%></A></TD>
    <TD width=1% align=center valign=top>

      <%= objRS("Codigo")%></TD>
    <TD width=1% align=center valign=top>

    <IMG src="check_<%=objRS("Baixa")%>.gif"></TD>
  </TR>
<%objRS.MoveNext 'Avança para o próximo registro
  If objRS.Eof then Exit For 'Se for fim de registros sai do loop
Next 'Finaliza o loop
Set Cor = Nothing
Set x = Nothing
Set Cont = Nothing
%>
</TABLE>
<B>Page <%= PagAtual & " of " & TotPag %> </B><BR>
&nbsp;<BR>
   <INPUT type="Hidden" name="Form_strQ" VALUE="<% = strQ%>">
   <INPUT TYPE="Hidden" NAME="txtPagina" VALUE="<%= PagAtual %>">
   <% If PagAtual > 1 Then %>
         <INPUT TYPE="Submit" NAME="Submit" VALUE="Previous">
   <% End If %>
   <% If PagAtual <> TotPag Then %>
         <INPUT TYPE="Submit" NAME="Submit" VALUE="Next">
   <% End If %>
<CENTER>

<% End Sub %>


<% Sub MostraNada()%>
<CENTER><STRONG>List of Orders</STRONG>
<BR><BR><BR><BR><BR><BR><B>None Found</B><BR><BR><BR><BR>
<% Response.End %>


<% End Sub %>

<% SUB Visualizar_Pedido

'# Cria um objeto de conexão com o banco de dados
Set Conexao = Server.CreateObject("ADODB.Connection")

'# abre a conexão com o banco de dados
Conexao.Open "DBQ=D:\www\##\db\Cadastro.mdb;Driver={Microso ft Access Driver (*.mdb)};"

'# Comando SQL que captura os dados do cliente da tabela
ComandoSQL = "Select * From Clientes Where Codigo = " & Request.QueryString("Codigo")

'# abre a tabela Produtos e recupera o email do banco de dados
Set Cliente = Conexao.Execute(ComandoSQL)

%>

<TABLE border=1 width=78% align=center cellpadding=1 cellspacing=1 bordercolor=#CCCCCC>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Name:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Nome")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Email:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><A href="mailto:<%=Cliente("Email")%>">
        <%=Cliente("Email")%></A></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Address:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Endereco")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Suburb/Town:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Bairro")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>City:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Cidade")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>State:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Estado")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Postal Code:</b></P>
    </TD>
    <TD width="72%">
      <P align=left><%=Cliente("Cep")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Telephone:</b></P>
    </TD>
    <TD width="72%" >
      <P align=left><%=Cliente("Telefone")%></P>
    </TD>
  </TR>
  <TR>
    <TD bgcolor=#CCCCCC width="28%">
      <P align=right><b>Fax:</b></P>
    </TD>
    <TD width="72%" >
      <P align=left><%=Cliente("fax")%></P>
    </TD>
  </TR>
</TABLE>



<%
'# Comando SQL que captura os dados do cliente da tabela
ComandoSQL = "Select * From Pedidos Where Codigo = " & Request.QueryString("Codigo") &" and Data = '" & Request.QueryString("Data") & "'"

'# abre a tabela Produtos e recupera o email do banco de dados
Set Pedido = Conexao.Execute(ComandoSQL)

Dim XMLDoc, XMLItems

Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM") 'Cria o objeto XML

XMLDoc.loadXML Pedido("Pedido")
Set XMLItems = XMLDoc.documentElement

%>

  <TABLE border=0 cellPadding=10 cellSpacing=0 width="100%">
    <TR>
      <TD valign=top width="30%">
        <BR>

    <TABLE border=1 width=80% align=center cellpadding=2 cellspacing=1 bordercolor=White>
      <TR bgcolor=#CCCCCC>
        <TH align=left>Product</TH>
        <TH width=1% nowrap>Image</TH>
        <TH width=1% nowrap>Price
          Unit.</TH>
        <TH width=1% nowrap>Qty.</TH>
        <TH width=1% nowrap>
          Total Cost</TH>
      </TR>
      <%
          For Each item in XMLItems.childNodes

            '# Captura o valor unitário do produto
            ValorUnit = item.attributes.getNamedItem("Valor").text

            '# Calcula o valor total do produto, multiplicando a quantidade pelo valor unitário
            ValorSubTot = item.text * ValorUnit

            '# Calcula a quantidade e o valor total dos produtos
            produtos = produtos + 1
            total = total + ValorSubTot
            %>
      <TR >
        <TD>
          <%=item.attributes.getNamedItem("Nome").text%> </A> </TD>
        <TD align=center nowrap> <A href="upload/<%=item.attributes.getNamedItem("Codigo").text%>.j pg" target="_blank"> <%=item.attributes.getNamedItem("Codigo").text%> </A> </TD>
        <TD align=center nowrap> <%=FormatCurrency(ValorUnit)%> </TD>
        <TD width="1%" align=center><%=item.text%> </TD>
        <TD align=center nowrap> <B><%=FormatCurrency(ValorSubTot)%></B> </TD>
      </TR>
      <%
          Next %>
      <TR bgcolor=#CCCCCC>
        <TD colspan=2 align=center>
          The cart contains <b><%=produtos%></b> different products </TD>
        <TD colspan=3 align=right>
          TOTAL <b><%=FormatCurrency(total)%></b> </TD>
      </TR>
    </TABLE>

<BR><CENTER>Order made on: <%=Pedido("Data")%></CENTER>

<%
If Pedido("Baixa") = "N" Then
  Response.Write "<BR><CENTER>[ <A href="""
  Response.Write Request.ServerVariables("SCRIPT_NAME")
  Response.Write "?Efetuar=Sim&Codigo=" & Request.QueryString("Codigo") & "&Data=" & Request.QueryString("Data")
  Response.Write """><B>Finalize Order</B></A> ]<BR><BR></CENTER>"
End If


Conexao.Close

'# Libera variaveis da memória
Set Conexao = Nothing
Set Pedido = Nothing
Set Cliente = Nothing
Set ComandoSQL = Nothing
%>

<% END SUB%>


<% SUB Efetua_Pedido

Dim Pedido, ConnString, Conexao, SQLString, DBDados
ConnString = "DBQ=D:\www\##\db\Cadastro.mdb"
ConnString = ConnString & ";Driver={Microsoft Access Driver (*.mdb)}"
Set Conexao = Server.CreateObject("ADODB.Connection")
Conexao.Open ConnString
SQLString = "UPDATE DISTINCTROW Pedidos "
SQLString = SQLString & "SET Baixa='S' "
SQLString = SQLString & " WHERE Codigo = " & Request.QueryString("Codigo") & " and Data = '" & Request.QueryString("Data") & "'"
Set DBDados = Conexao.Execute(SQLString)

Set ConnString = Nothing
Set DBDados = Nothing
Set Conexao = Nothing
Set ConnString = Nothing

Response.Write Pedido & "<BR><BR><B>Order Completed</B>"

Set Pedido = Nothing

END SUB
%>





 
Old August 20th, 2003, 01:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you expect us to read through all that code trying to work out your problem?

Start by doing some troubleshooting yourself to narrow down the problem:
a) is the page valid HTML? (http://validator.w3.org will tell you)
b) are the prev and next submit buttons encased in a HTML <form></form>?

www.adOpenStatic.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp/Access recordset navigation query murshed Classic ASP Databases 1 April 10th, 2008 01:43 PM
navigation (ch7 of Beg.ASP.NET3.5) wingri ASP.NET 3.5 Basics 3 April 7th, 2008 12:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.