Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2008, 06:48 PM
Registered User
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13: shopping cart problem

For chapter 13 shopping cart...after i key in all the code follow as the book i get such error:


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'Commerce' does not exist in the namespace 'M2L' (are you missing an assembly reference?)

Source Error:

Line 80: }
Line 81:
Line 82: public virtual M2L.Commerce.CartItem Cart {
Line 83: get {
Line 84: return ((M2L.Commerce.CartItem)(this.GetPropertyValue("Ca rt")));


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\root\6f98d0e5\9285cdca\App_Code.otcjhtkr.0.c s Line: 82


*i already define => namespace M2L.Commerce under Shopping.cs


and i also tried to download original source code from this web side i also get the same problem.

following will be my shopping.cs file:



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data .SqlClient ;
using System.Collections .Generic ;

namespace M2L.Commerce
{
[Serializable ]
    public class CartItem
    {
        private string _productModel;
        private string _productName;
        private string _productImageUrl;
        private int _quantity;
        private double _price;
        private double _lineTotal;

        public void New()
        {
        }

        public void New(string Product_Model, string Product_Name, string Product_ImageUrl, int Quantity, double Price)
        {
            _productModel = Product_Model;
            _productName = Product_Name;
            _productImageUrl = Product_ImageUrl;
            _quantity = Quantity;
            _price = Price;
            _lineTotal = Quantity * Price;
        }

        public string ProductModel
        {
            get
            {
                return _productModel;
            }
            set
            {
                _productModel = value;
            }
        }

        public string ProductName
        {
            get
            {
                return _productName;
            }
            set
            {
                _productName = value;
            }
        }

        public string ProductImageUrl
        {
            get
            {
                return _productImageUrl;
            }
            set
            {
                _productImageUrl = value;
            }
        }

        public int Quantity
        {
            get
            {
                return _quantity;
            }
            set
            {
                _quantity = value;
            }
        }

        public double Price
        {
            get
            {
                return _price;
            }
            set
            {
                _price = value;
            }

        }

        public double LineTotal
        {
            get
            {
                return _quantity * _price;
            }
        }


        [Serializable ]
        public class ShoppingCart
        {
            private DateTime _dateCreated;
            private DateTime _lastUpdate;
            private ListBox<CartItem> _items;

            public ShoppingCart()
            {
                if (this._items == null)
                {
                    this._items = new ListBox<CartItem >();
                    this._dateCreated = DateTime .Now ;
                }
        }

            public List<CartItem> Items
            {
                get
                {
                    return _items ;
                }
                set
                {
                    _items =value;
                }
            }

            public void Insert(string Product_Model, double Price, int Quantity, string Product_Name, string Product_ImageUrl)
            {
                int ItemIndex = ItemIndexOfID(Product_Model );
                if(ItemIndex == -1)
                {
                    CartItem NewItem = new CartItem ();
                    NewItem .ProductModel = Product_Model ;
                    NewItem .Price = Price;
                    NewItem .ProductName = Product_Name ;
                    NewItem .ProductImageUrl = Product_ImageUrl ;
                 _items .Add(NewItem );
                }
                else
                {
                    _items[ItemIndex ].Quantity +=1;
                }
                _lastUpdate = DateTime .Now;
            }

            public void Update(int Row_ID, string Product_Model, double Price)
            {
                CartItem Item = _items [RowID ];
                Item .ProductModel = Product_Model ;
                Item .Quantity = Quantity;
                Item .Price = Price ;
                _lastUpdate = DateTime .Now ;
            }

            public void DeleteItem(int Row_ID)
            {
                _items .RemoveAt(Row_ID );
                _lastUpdate = DateTime .Now ;
            }

            private int ItemIndexOfID(string Product_Model)
            {
                int index = 0;
                foreach (CartItem item in _items)
                {
                    if (item.ProductModel == Product_Model)
                    {
                        return index;
                    }
                    index += 1;
                }
                return -1;
            }

            public double Total
            {
                get
                {
                    double t=0;

                    if (_items == null)
                    {
                        return 0;
                    }

                    foreach (CartItem Item in _items )

                    {
                        t += Item.LineTotal;
                    }

                    return t;
                }
            }

            }

    }
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 Shopping Cart michaelcode BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 9 January 25th, 2010 03:50 AM
Chapter 13 Shopping Cart disappears after login bwinklesky BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 June 14th, 2007 12:34 PM
Chapter 13 - Problem compiling Cart Dsypher BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 March 12th, 2007 01:34 AM
Ch.13 Builing a Shopping Cart seannie BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 7th, 2007 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.