sessionshoppingcartcontroller.vb

来自「C#语言制作asp.net网上商店的」· VB 代码 · 共 46 行

VB
46
字号
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Web


Namespace NetShopForge.Library.Cart

    Public Class SessionShoppingCartController
        Implements IShoppingCart

        'ToDo: Add Implements Clauses for implementation methods of these interface(s)
        Public Function Add(ByVal cartid As String, ByVal item As IShoppingCartInfo) As Integer Implements IShoppingCart.Add
            Dim items As List(Of ShoppingCartInfo)
            If Not (HttpContext.Current.Session("mycart") Is Nothing) Then
                items = CType(HttpContext.Current.Session("mycart"), List(Of ShoppingCartInfo))
                If items.Contains(item) Then items.Remove(item)
            Else
                items = New List(Of ShoppingCartInfo)
                ' HttpContext.Current.Session("mycart") = items
            End If
            items.Add(item)
            HttpContext.Current.Session("mycart") = items
            Return 0
        End Function 'Add

        Public Function Remove(ByVal cartid As String, ByVal item As IShoppingCartInfo) As Integer Implements IShoppingCart.Remove
            Dim items As List(Of ShoppingCartInfo) = CType(HttpContext.Current.Session("mycart"), List(Of ShoppingCartInfo))
            Dim i As Integer
            For i = 0 To items.Count - 1
                If CType(items(i), IShoppingCartInfo).ProductID = item.ProductID Then
                    items.RemoveAt(i)
                    Exit For
                End If
            Next i
            Return 0
        End Function 'Remove




        Public Function GetItems(ByVal cartid As String) As System.Collections.Generic.IList(Of IShoppingCartInfo) Implements IShoppingCart.GetItems
            Return CType(HttpContext.Current.Session("mycart"), IList(Of IShoppingCartInfo))
        End Function
    End Class
End Namespace

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?