
12/03/2006, 22:53
|
 | | | Fecha de Ingreso: noviembre-2002 Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 4 meses Puntos: 16 | |
Un catalogo on-line en ASP.NET Hola maestros... la verdad de las cosas es que me he aventurado de a poco en la migracion de ASP a ASP.NET y hoy despues de mucho estudio he logrado hacer mi primer script en ASP.NET... no es la gran cosa pero algo es algo... bueno se trata de uncatalogo online que anteriormente lo tenia hecho con ASP... y que me decidi migrarlo a ASP.NET y aqui esta... catalogo.aspx
Código:
<% @Page Language = VB %>
<% @Import Namespace = "System.Data" %>
<% @Import Namespace = "System.Data.OleDb" %>
<html>
<head>
<title>Catálogo on-line</title>
<link rel="stylesheet" type="text/css" href="estilo.css">
<%
'Declarar Variables
Dim Conn As OleDbConnection
Dim cmd As OleDbDataAdapter
Dim dt, dtp As DataTable
Dim i, n, p, s As Integer
Dim sql_categorias As String
Dim sql_productos As String
Dim categoria, contador As Integer
Dim findefila As String
'Rescate de valores por URL
categoria = Request.Querystring("cat")
sql_categorias = "Select * From Categorias;"
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("catalogo.mdb") & ";")
' Crear el comando
cmd = New OleDbDataAdapter(sql_categorias, Conn)
' Llenar el DataTable
dt = New DataTable
cmd.Fill(dt)
n = dt.Rows.Count
%>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="25%" valign="top">
<table border="1" width="60%" bordercolor="#DFE8FF" cellspacing="0" cellpadding="0" align="center">
<tr>
<td wisth="100%" bgcolor="#DFE8FF" align="center" class="text"><b>Categorías</b></td>
</tr>
<tr>
<td width="100%">
<table border="0" width="100%" bgcolor="#EFEFEF" cellspacing="0" cellpadding="0">
<%
If n = 0 then
%>
<tr>
<td width="100%" class="text" align="center">No hay categorías</td>
</tr>
<%
Else
For i = 0 To n - 1
Dim id_categoria
Dim nombre_categoria
Dim total_productos
id_categoria = dt.Rows(i).Item("id_categoria")
nombre_categoria = dt.Rows(i).Item("nombre_categoria")
total_productos = dt.Rows(i).Item("total_productos")
'Condición
If clng(categoria) = id_categoria Then
%>
<tr>
<td width="100%"><b><a href="catalogo.aspx?cat=<% = id_categoria %>"><% = nombre_categoria %></a></b> (<% = total_productos %>)</td>
</tr>
<% Else %>
<tr>
<td width="100%"><a href="catalogo.aspx?cat=<% = id_categoria %>"><% = nombre_categoria %></a> (<% = total_productos %>)</td>
</tr>
<%
End If
Next
End If
%>
</table>
</td>
</tr>
</table>
</td>
<td width="75%" valign="top">
<%
If categoria = Nothing Then
'Creación de la sentecia SQL correspondiente
sql_productos = "Select Top 10 * From productos Order By id_producto Desc"
' Crear el comando
cmd = New OleDbDataAdapter(sql_productos, Conn)
' Llenar el DataTable
dtp = New DataTable
cmd.Fill(dtp)
s = dt.Rows.Count
%>
<table border="1" bordercolor="#DFE8FF" width="90%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="100%" colspan="5" bgcolor="#DFE8FF" class="text">Los últimos 10 productos</td>
</tr>
<tr>
<%
If Not s = 0 Then
findefila = "</tr><tr>"
contador = 1
For p = 0 To s - 1
Dim id_producto
Dim categoriap
Dim imagen
Dim producto
Dim precio
id_producto = dtp.Rows(p).Item("id_producto")
categoriap = dtp.Rows(p).Item("categoria")
imagen = dtp.Rows(p).Item("imagen")
producto = dtp.Rows(p).Item("producto")
precio = dtp.Rows(p).Item("precio")
%>
<td width="20%" bgcolor="#EFEFEF" align="center" class="text"><a href="verdetalle.aspx?cat=<% = categoriap %>&pro=<% = id_producto %>"><img src="imagenes/<% = imagen %>" width="50" height="50" border="0"><br><a href="verdetalle.aspx?cat=<% = categoriap %>&pro=<% = id_producto %>"><% = producto %></a><br>$<% = precio %></td>
<%
If contador = 5 Then
Response.Write(findefila)
contador = 1
Else
contador = contador + 1
End If
Next
Else
%>
<td width="100%" bgcolor="#EFEFEF" align="center" class="text">No hay productos nuevos</td>
<% End If %>
</tr>
</table>
<% Else %>
<table border="1" bordercolor="#DFE8FF" width="80%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="10%" bgcolor="#DFE8FF" class="text"> </td>
<td width="80%" bgcolor="#DFE8FF" class="text"> Productos</td>
<td width="10%" bgcolor="#DFE8FF" class="text" align="right">Precio</td>
</tr>
<%
'Creación de la sentencia SQL correspondiente
sql_productos = "Select * From productos Where categoria = " & categoria & ""
' Crear el comando
cmd = New OleDbDataAdapter(sql_productos, Conn)
' Llenar el DataTable
dtp = New DataTable
cmd.Fill(dtp)
s = dt.Rows.Count
If Not s = 0 Then
For p = 0 To s - 1
Dim id_producto
Dim imagen
Dim producto
Dim precio
id_producto = dtp.Rows(p).Item("id_producto")
imagen = dtp.Rows(p).Item("imagen")
producto = dtp.Rows(p).Item("producto")
precio = dtp.Rows(p).Item("precio")
%>
<tr>
<td width="10%" bgcolor="#EFEFEF" align="center"><a href="verdetalle.aspx?cat=<% = categoria %>&pro=<% = id_producto %>"><img src="imagenes/<% = imagen %>" width="50" height="50" border="0"></a></td>
<td width="80%" bgcolor="#EFEFEF"> <a href="verdetalle.aspx?cat=<% = categoria %>&pro=<% = id_producto %>"><% = producto %></a></td>
<td width="10%" bgcolor="#EFEFEF" align="right">$<% = precio %></td>
</tr>
<%
Next
Else
%>
<tr>
<td width="100%" bgcolor="#EFEFEF" colspan="3" align="center" class="text">No hay productos en esta categoría</td>
</tr>
<%
End if
End if
%>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Continua....
__________________ Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!! |