For Each p In ShopArray If p = ID.ToString Then ItemExists = True End If Next
If ItemExists = True Then For Each pp In ShopArray QtyString = QtyString & "," & pp Next Else ShopString = ShopString & "," & ID QtyString = QtyString & "," & Qty End If
MsgBox(ShopString) MsgBox(QtyString)
System.Web.HttpContext.Current.Session("Cart") = ShopString System.Web.HttpContext.Current.Session("Qty") = QtyString End Sub
For Each p In ShopArray i = i + 1 If p = ID.ToString Then ItemExists = True End If Next
If ItemExists = True Then QtyArray(i) = QtyArray(i) + Qty
QtyString = ""
For Each p In QtyArray If QtyString = "" Then QtyString = p Else QtyString = QtyString & "|" & p End If Next Else If QtyString = "" Then QtyString = Qty ShopString = ID Else QtyString = QtyString & "|" & Qty ShopString = ShopString & "|" & ID End If End If
Imports System Imports System.Collections.Generic Imports System.Web.UI Imports System.Web.UI.WebControls
Namespace E Public Class Item Private _name As String Private _qty As Integer Public Property Name() As String Get return _name End Get Set _name = Value End Set End Property Public Property Qty() As Integer Get return _qty End Get Set _qty = Value End Set End Property End Class Public Partial Class CartPage Inherits Page Public Sub Page_Load(src As Object, e As EventArgs) Dim lst As List(Of Item) = DirectCast(Session("Cart"), List(Of Item)) If lst Is Nothing Then lst = New List(Of Item)() Session("Cart") = lst End If Cart.DataSource = lst Cart.DataBind() End Sub Protected Overloads Overrides Sub OnInit(e As EventArgs) MyBase.OnInit(e) AddHandler AddA.Click, AddressOf AddA_Click AddHandler AddB.Click, AddressOf AddB_Click AddHandler AddC.Click, AddressOf AddC_Click End Sub Public Sub AddA_Click(sender As Object, e As EventArgs) Add("A") End Sub Public Sub AddB_Click(sender As Object, e As EventArgs) Add("B") End Sub Public Sub AddC_Click(sender As Object, e As EventArgs) Add("C") End Sub Private Sub Add(_name As String) Dim lst As List(Of Item) = DirectCast(Session("Cart"), List(Of Item)) Dim itm As Item = lst.Find(AddressOf (New Finder(_name)).Find) If itm IsNot Nothing Then itm.Qty += 1 Else itm = New Item itm.Name = _name itm.Qty = 1 lst.Add(itm) End If Cart.DataBind() End Sub End Class Public Class Finder Private name As String Public Sub New(ByVal _name As String) name = _name End Sub Public Function Find(ByVal i As Item) As Boolean Return i.Name = name End Function End Class End Namespace
Public Class Item Private _name As String Private _qty As Integer Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = Value End Set End Property Public Property Qty() As Integer Get Return _qty End Get Set(ByVal value As Integer) _qty = Value End Set End Property End Class
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.