熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 13.3.1 購物對象[4]

2022-06-13   來源: .NET編程 

    ()在Cartltem類下面添加如下代碼創建WroxShoppingCart對象

 

<Serializable()> _

    Public Class WroxShoppingCart

 

        Private _dateCreated As DateTime

        Private _lastUpdate As DateTime

        Private _items As List(Of CartItem)

 

        Public Sub New()

            _items = New List(Of CartItem)

            _dateCreated = DateTimeNow

        End Sub

 

 

        Public Property Items() As List(Of CartItem)

            Get

                Return _items

            End Get

            Set(ByVal value As List(Of CartItem))

                _items = value

            End Set

        End Property

 

        Public Sub Insert(ByVal ProductID As Integer ByVal Price As Double ByVal Quantity As Integer ByVal ProductName As String ByVal ProductImageUrl As String)

 

            Dim ItemIndex As Integer = ItemIndexOfID(ProductID)

 

            If ItemIndex = Then

                Dim NewItem As New CartItem()

 

                NewItemProductID = ProductID

                NewItemQuantity = Quantity

                NewItemPrice = Price

                NewItemProductName = ProductName

                NewItemProductImageUrl = ProductImageUrl

 

                _itemsAdd(NewItem)

            Else

                _items(ItemIndex)Quantity +=

            End If

 

            _lastUpdate = DateTimeNow()

 

        End Sub

 

        Public Sub Update(ByVal RowID As Integer ByVal ProductID As Integer ByVal Quantity As Integer ByVal Price As Double)

 

            Dim Item As CartItem = _items(RowID)

 

            ItemProductID = ProductID

            ItemQuantity = Quantity

            ItemPrice = Price

            _lastUpdate = DateTimeNow()

 

        End Sub

 

        Private Function ItemIndexOfID(ByVal ProductID As Integer) As Integer

 

            Dim index As Integer

 

            For Each item As CartItem In _items

                If itemProductID = ProductID Then

                    Return index

                End If

                index +=

            Next

 

            Return

 

        End Function

 

        Public Sub DeleteItem(ByVal rowID As Integer)

 

            _itemsRemoveAt(rowID)

            _lastUpdate = DateTimeNow()

 

        End Sub

 

        Public ReadOnly Property Total() As Double

            Get

                Dim t As Double

 

                If _items Is Nothing Then

                    Return

                End If

 

                For Each Item As CartItem In _items

                    t += ItemLineTotal

                Next

 

                Return t

            End Get

        End Property

 

    End Class

 

End Namespace

    ()保存這個頁面遺憾的是不可以對這個類進行任何操作直到開始實例化對象的實例因此這兒還不會看到任何內容

[]  []  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15596.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.