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;
}
}
}
}
}
|