Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 28th, 2007, 12:30 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Modifying Shopping Cart Class

Below is the current database structure.


The OptionGroup holds the product attribute, e.g. Colour related to the product
Every product has it's own OptionGroup, as every product is unique.

The GroupOptions holds the attributes, e.g. Red, Blue, Green


Products
--------
ProductID (PK)
ProductCode
Name
Description
Price
PictureURL
ThumbURL
CatID
Featured
Active


OptionGroup
-----------------
OptionGroupID (PK)
OptionGroupName
ProductID (FK)


GroupOptions
------------
GroupOptionID (PK)
OptionGroupValues
OptionGroupID (FK)



How can I edit the sample class code below to reflect my database structure above?

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic

Namespace Wrox.Commerce

    <Serializable()> _
    Public Class CartItem
        Private _productID As Integer
        Private _productName As String
        Private _productImageUrl As String
        Private _quantity As Integer
        Private _price As Double
        Private _lineTotal As Double

        Public Sub New()
        End Sub

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

            _productID = ProductID
            _productName = ProductName
            _productImageUrl = ProductImageUrl
            _quantity = Quantity
            _price = Price
            _lineTotal = Quantity * Price

        End Sub

        Public Property ProductID() As Integer
            Get
                Return _productID
            End Get
            Set(ByVal value As Integer)
                _productID = value
            End Set
        End Property

        Public Property ProductName() As String
            Get
                Return _productName
            End Get
            Set(ByVal value As String)
                _productName = value
            End Set
        End Property

        Public Property ProductImageUrl() As String
            Get
                Return _productImageUrl
            End Get
            Set(ByVal value As String)
                _productImageUrl = value
            End Set
        End Property

        Public Property Quantity() As Integer
            Get
                Return _quantity
            End Get
            Set(ByVal value As Integer)
                _quantity = value
            End Set
        End Property

        Public Property Price() As Double
            Get
                Return _price
            End Get
            Set(ByVal value As Double)
                _price = value
            End Set
        End Property

        Public ReadOnly Property LineTotal() As Double
            Get
                Return _quantity * _price
            End Get
        End Property

    End Class


    <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 = DateTime.Now
        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 = -1 Then
                Dim NewItem As New CartItem()

                NewItem.ProductID = ProductID
                NewItem.Quantity = Quantity
                NewItem.Price = Price
                NewItem.ProductName = ProductName
                NewItem.ProductImageUrl = ProductImageUrl

                _items.Add(NewItem)
            Else
                _items(ItemIndex).Quantity += 1
            End If

            _lastUpdate = DateTime.Now()

        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)

            Item.ProductID = ProductID
            Item.Quantity = Quantity
            Item.Price = Price
            _lastUpdate = DateTime.Now()

        End Sub

        Private Function ItemIndexOfID(ByVal ProductID As Integer) As Integer

            Dim index As Integer

            For Each item As CartItem In _items
                If item.ProductID = ProductID Then
                    Return index
                End If
                index += 1
            Next

            Return -1

        End Function

        Public Sub DeleteItem(ByVal rowID As Integer)

            _items.RemoveAt(rowID)
            _lastUpdate = DateTime.Now()

        End Sub

        Public ReadOnly Property Total() As Double
            Get
                Dim t As Double

                If _items Is Nothing Then
                    Return 0
                End If

                For Each Item As CartItem In _items
                    t += Item.LineTotal
                Next

                Return t
            End Get
        End Property

    End Class

End Namespace


Thanks.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shopping cart keyvanjan Classic ASP Basics 1 January 9th, 2007 10:16 PM
Shopping cart help rsm42 ASP.NET 1.0 and 1.1 Basics 3 December 9th, 2006 06:09 AM
shopping cart xipnl BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 10th, 2005 07:00 PM
shopping cart isheikh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 8th, 2004 04:20 PM



All times are GMT -4. The time now is 10:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.