asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET入门教程 13.3.1 购物对象[4]


发布日期:2023年03月19日
 
ASP.NET入门教程 13.3.1 购物对象[4]

)在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

)保存这个页面遗憾的是不可以对这个类进行任何操作直到开始实例化对象的实例因此这儿还不会看到任何内容

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

               

上一篇:ASP.NET入门教程 13.3.1 购物对象[3]

下一篇:ASP.NET入门教程 13.3.1 购物对象[9]