ASP.NET - ayuda en carrito de compras

 
Vista:
sin imagen de perfil

ayuda en carrito de compras

Publicado por vazagho (79 intervenciones) el 02/11/2010 22:17:57
que tal en mi proyecto asp tengo la seccion de categoria de productos donde me da a eligir que categoria quiero ver por ejemplo hombre, mujer, menores....... cuando entro a la pagina mujer en esta caso tengo un datalist listado con los datos del producto codificado en codigo html incluyendole un boton image algo asi

<asp:DataList ID="dlhombre" runat="server" CellPadding="4" ForeColor="Black"
RepeatColumns="1" BackColor="#CCCCCC" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" GridLines="Both" CellSpacing="2">
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="White" />
<ItemTemplate>
<TABLE id="Table5" height="90" cellSpacing="1" cellPadding="1" width="300" border="0">
<TR>
<TD>
<a href='fcodigo/<%#DataBinder.Eval(Container.DataItem,"cod_producto")%>.jpg' rel="lightbox"><img src='fcodigo/<%#DataBinder.Eval(Container.DataItem,"cod_producto")%>.jpg' width="100" height="120" alt="" /></a></TD>
<TD>
<B>Detalle:</B>  <%# DataBinder.Eval(Container.DataItem, "detalle")%><BR>
<B>Stock:</B>  <%# DataBinder.Eval(Container.DataItem, "stock_actual")%><BR>
<B>Medida:</B>  <%# DataBinder.Eval(Container.DataItem, "unidadEntity.detalle")%><BR>
<B>Peso:</B>  <%# DataBinder.Eval(Container.DataItem, "peso_kg")%><BR>
<B>Precio:</B>   <%# DataBinder.Eval(Container.DataItem, "precio")%> <BR>
<B>Moneda:</B>  <%# DataBinder.Eval(Container.DataItem, "monedaEntity.detalle")%><BR>
<BR>
<A href='carrito.aspx?ID=<%# DataBinder.Eval(Container.DataItem,"cod_producto")%>'><asp:ImageButton ID="ImageButton1" runat="server" Height="40px"
ImageUrl="images/boton-comprar.jpg" Width="150px" /></A>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:DataList>


se supone que al darle click en el boton voy a recuperar el codigo del producto por medio del ID= CUANDO hago el hiperenlace y lo recuero en mi pagina carrito asi, este codigo lo hice pero incluyendo todo en esa pagina , codigo bruto


Imports System.Data.SqlClient
Imports System.Data
Partial Class carrito
Inherits System.Web.UI.Page
Private Sub LlenarDatos()
Dim DT As DataTable
DT = Session("carrito")
Me.DataGrid1.DataSource = DT
Me.DataGrid1.DataBind()
Session("carrito") = DT
End Sub
Private Sub ActualizarTotalPagar()
Dim Fila As DataRow
Dim DT As DataTable
Dim TOTAL As Single
DT = Session("carrito")
For Each Fila In DT.Rows
TOTAL = TOTAL + Fila("Total")
Next
Me.lblTotal.Text = TOTAL
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Introducir aquí el código de usuario para inicializar la página
Dim DT As DataTable
Dim DR As DataRow
Dim idarticulo As String
idarticulo = Request.QueryString("id")
If Session("carrito") Is Nothing Then
DT = New DataTable
DT.Columns.Add("Codigo", System.Type.GetType("System.String")).MaxLength = 5
DT.Columns.Add("Nombre", System.Type.GetType("System.String")).MaxLength = 50
DT.Columns.Add("Precio", System.Type.GetType("System.Decimal"))
DT.Columns.Add("Cantidad", System.Type.GetType("System.Int32"))
DT.Columns.Add("Total", System.Type.GetType("System.Decimal"))
Dim PK(1) As DataColumn
PK(0) = DT.Columns("Codigo")
DT.PrimaryKey = PK
Me.DataGrid1.DataSource = DT
Me.DataGrid1.DataBind()
Else
DT = Session("carrito")
End If
If idarticulo <> "" And Me.IsPostBack = False Then
Dim FilaExiste As DataRow = DT.Rows.Find(idarticulo)
If Not (FilaExiste Is Nothing) Then
FilaExiste.BeginEdit()
FilaExiste("Cantidad") = FilaExiste("Cantidad") + 0
FilaExiste("Total") = FilaExiste("Precio") * FilaExiste("Cantidad")
FilaExiste.EndEdit()
Else
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
cn.ConnectionString = "Database=artesania;Server=SERVERXP-A42027;integrated security=true"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "usp_Articulo_Traer_X_ID"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@idarticulo", idarticulo)
cmd.Parameters.Add("@nomarticulo", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output
cmd.Parameters.Add("@precio", SqlDbType.Decimal, 5).Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
DR = DT.NewRow()
DR.BeginEdit()
DR.Item("Codigo") = idarticulo
DR.Item("Nombre") = cmd.Parameters("@nomarticulo").Value
DR.Item("Precio") = cmd.Parameters("@precio").Value
If IsDBNull(DR.Item("Cantidad")) Then
DR.Item("Cantidad") = 0
Else
DR.Item("Cantidad") = DR.Item("Cantidad") + 0
End If
DR.Item("Total") = DR.Item("Precio") * DR.Item("Cantidad")
DR.EndEdit()
DT.Rows.Add(DR)
End If
End If
If Me.IsPostBack = False Then
Me.DataGrid1.DataSource = DT
Me.DataGrid1.DataBind()
End If
Session("carrito") = DT
Call ActualizarTotalPagar()
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim DT As DataTable
DT = Session("carrito")
DT.Rows.RemoveAt(e.Item.ItemIndex)
DT.AcceptChanges()
Me.DataGrid1.DataSource = DT
Me.DataGrid1.DataBind()
Session("carrito") = DT
ActualizarTotalPagar()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
Call LlenarDatos()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
Call LlenarDatos()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim DT As DataTable
Dim txtCantidad As TextBox
' txtCantidad = CType(e.Item.Cells(3).Controls(1), TextBox)
txtCantidad = CType(e.Item.FindControl("txtCantidad"), TextBox)
DT = Session("carrito")
DT.Rows(e.Item.ItemIndex)("Cantidad") = txtCantidad.Text
DT.Rows(e.Item.ItemIndex)("Total") = DT.Rows(e.Item.ItemIndex)("Precio") * txtCantidad.Text
DataGrid1.EditItemIndex = -1
Me.DataGrid1.DataSource = DT
Me.DataGrid1.DataBind()
Session("carrito") = DT
ActualizarTotalPagar()
End Sub

Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
Response.Redirect("products.aspx")
End Sub

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Response.Redirect("Confirmandopago.aspx")
End Sub
End Class

como hago para reemplazar todo eso programando orientado a objectos, pues ahi dentro esta la conexion usan parametros y algunas cosas mas
gracias, espero sus comentarios
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder