Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Carrito de Compras
Carrito de Compras
Pagina Catalogo.aspx
Pagina listacomprados.aspx
End Sub
Public Shared ReadOnly Property Instancia() As Conexion
Get
Return _instancia
End Get
End Property
End Class
CLASE ProductosDA
Imports System.Data
Imports System.Data.SqlClient
Imports ComponenteEntidad
Public Class ProductosDA
Private Shared ReadOnly _instancia As New ProductosDA
While PaTable.Read
Coleccion.Add(New Productos(PaTable.Item(0), PaTable.Item(1),
PaTable.Item(2), PaTable.Item(3), PaTable.Item(4)))
End While
cnn.Close()
cnn.Dispose()
Return Coleccion
End Function
Public Function ListarporCodigo(ByVal cod As String) As List(Of
Productos)
Dim dsDatos As New DataSet
Dim cnn As New SqlConnection(Conexion.Instancia.cadenaconexion)
cnn.Open()
Dim sqlcmd As New SqlCommand("pa_productos_buscarcodigo", cnn)
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.Add("@codproducto", SqlDbType.Char, 4).Value =
cod
Dim PaTable As SqlDataReader = sqlcmd.ExecuteReader
Dim Coleccion As New List(Of Productos)
While PaTable.Read
Coleccion.Add(New Productos(PaTable.Item(0), PaTable.Item(1),
PaTable.Item(2), PaTable.Item(3), PaTable.Item(4)))
End While
cnn.Close()
cnn.Dispose()
Return Coleccion
End Function
Sqlcmd.ExecuteNonQuery()
cnn.Close()
cnn.Dispose()
Return True
End Function
Public Function Editar(ByVal Productos As Productos) As Boolean
Sqlcmd.ExecuteNonQuery()
cnn.Close()
cnn.Dispose()
Return True
End Function
Public Function Eliminar(ByVal codproducto As String) As Boolean
End Class
COMPONENTEENTIDAD
Public Class Productos
Private _codproducto As String
Private _descripcion As String
Private _precio As Double
Private _cantidad As Integer
Private _foto As String
Public Property codproducto() As String
Get
Return _codproducto
End Get
Set(ByVal value As String)
_codproducto = value
End Set
End Property
Public Property descripcion() As String
Get
Return _descripcion
End Get
Set(ByVal value As String)
_descripcion = value
End Set
End Property
Public Property precio() As Double
Get
Return _precio
End Get
Set(ByVal value As Double)
_precio = value
End Set
End Property
Public Property cantidad() As Integer
Get
Return _cantidad
End Get
Set(ByVal value As Integer)
_cantidad = value
End Set
End Property
Public Property foto() As String
Get
Return _foto
End Get
Set(ByVal value As String)
_foto = value
End Set
End Property
Public Sub New(ByVal ccodproducto As String, ByVal cdesproducto As
String, ByVal cprecio As Double, ByVal ccantidad As Integer, ByVal cfoto
As String)
_codproducto = ccodproducto
_descripcion = cdesproducto
_precio = cprecio
_cantidad = ccantidad
_foto = cfoto
End Sub
End Class
COMPONENTENEGOCIO
Imports ComponenteEntidad
Imports ComponenteDatos
Public Class ProductosCN
Public Sub New()
End Sub
Private Shared ReadOnly _instancia As New ProductosCN
Return ProductosDA.Instancia.ListarporCodigo(cod)
End Function
Public Function Insertar(ByVal Productos As Productos) As Boolean
ProductosDA.Instancia.Insertar(Productos)
End Function
Public Function Editar(ByVal Productos As Productos) As Boolean
ProductosDA.Instancia.Editar(Productos)
End Function
Public Function Eliminar(ByVal codproducto As String) As Boolean
ProductosDA.Instancia.Eliminar(codproducto)
End Function
End Class
CREAR CANASTADS
EN LA PAGINA CATALOGOS
EDIT TEMPLATES
PROPIEDADES DE PRECIOLABEL
Imports ComponenteEntidad
Imports ComponenteDatos
Imports ComponenteNegocio
Partial Public Class Catalogo
Inherits System.Web.UI.Page
End Sub
End Sub
End Sub
EN LA PAGINA LISTACOMPRADOS
<table class="style1">
<tr>
<td bgcolor="#006699">
<asp:Label ID="Label2" runat="server" Font-Bold="True"
ForeColor="White"
Text="Mi Carrito de Compras"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
ImageUrl="~/Imagenes/Eliminar.png" HeaderText="Quitar"
onclick="ImageButton1_Click"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="codproducto"
HeaderText="Codigo" />
<asp:BoundField DataField="desproducto"
HeaderText="Producto" />
<asp:BoundField DataField="preproducto"
HeaderText="Precio" />
<asp:TemplateField HeaderText="Cantidad" >
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("canproducto") %>'
ontextchanged="TextBox1_TextChanged"
Width="80px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="subtotal"
HeaderText="Subtotal" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066"
HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
</td>
</tr>
<tr>
<td align="right" class="style2">
<asp:Label ID="Label1" runat="server" Text="Subtotal S/." Font-
Bold="True"></asp:Label>
&
nbsp;
<asp:Label ID="Lblsubtotal" runat="server"
Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td align="center" class="style2">
<asp:Button ID="Button1" runat="server" Text="Actualizar Datos"
style="height: 26px" />
<asp:Button ID="Button2" runat="server" Text="Continuar Comprando" />
</td>
</tr>
</table>
CODIGO EN LA PAGINA LISTACOMPRADOS.ASPX
Imports ComponenteEntidad
Imports ComponenteDatos
Imports ComponenteNegocio
End Sub
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles Button1.Click
Dim i As Integer
Dim total, prec, subtotal As Double
Dim cod, des As String
Dim cant As Integer
Dim obj As CanastaDS = CType(Session("Canasta"), CanastaDS)
For i = 0 To GvwCarrito.Rows.Count - 1
cod = (GvwCarrito.Rows(i).Cells(1).Text)
des = (GvwCarrito.Rows(i).Cells(2).Text)
prec = Double.Parse(GvwCarrito.Rows(i).Cells(3).Text)
cant =
CType(GvwCarrito.Rows(i).Cells(0).FindControl("TextBox1"), TextBox).Text
prec = Double.Parse(GvwCarrito.Rows(i).Cells(3).Text)
subtotal = cant * prec
'Actualiza la canasta
GvwCarrito.Rows(i).Cells(5).Text = subtotal
For Each objDR In obj.Canasta.Rows
If objDR("codproducto") = cod Then
objDR("canproducto") = cant
objDR("subtotal") = subtotal
Exit For
End If
Next
total = total + subtotal
Next
Lblsubtotal.Text = total.ToString("0.00")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles Button2.Click
Response.Redirect("Catalogo.aspx")
End Sub
End Sub
End Class