2009-11-12 172 views
0

重复:missing assembly reference缺少的程序集引用

大家好 请帮我

我Shopping.cs文件如下

using System; 
using System.Data; 
using MyWebsite.Commerce; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Linq; 
using System.Web; 
using System.Data.SqlClient; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Xml.Serialization; 


namespace MyWebsite.Commerce 
{ 
    [Serializable] 
    public class CartItem 
    { 
     private int _productID; 
     private string _productName; 
     private string _productURL; 
     private int _quantity; 
     private double _price; 
     private double _lineTotal; 
     public void New() 
     { 
     } 
     public void New(int ProductID, string ProductName, string ProductURL, int Quantity, double Price) 
     { 
      _productID = ProductID; 
      _productName = ProductName; 
      _productURL = ProductURL; 
      _quantity = Quantity; 
      _price = Price; 
      _lineTotal = Quantity * Price; 
     } 
     public int ProductID { get; set; } 
     public string ProductName { get; set; } 
     public string ProductURL { get; set; } 
     public int Quantity { get; set; } 
     public double Price { get; set; } 
     public double LineTotal { get; set; } 


     [Serializable] 

     public class ShoppingCart 
     { 
      private DateTime _dateCreated; 
      private DateTime _lastUpdate; 
      private List<CartItem> _items; 
      public ShoppingCart() 
      { 
       if (this._items = null) 
       { 
        this._items = new List<CartItem>(); 
        this._dateCreated = DateTime.Now; 
       } 
      } 
      public List<CartItem> Items 
      { get; set; } 
      public void Insert(int ProductID, string ProductName, string ProductURL, int Quantity, double Price) 
      { 
       int ItemIndex = ItemIndexOfID(ProductID); 
       if (ItemIndex == -1) 
       { 
        CartItem NewItem = new CartItem(); 
        NewItem.ProductID = ProductID; 
        NewItem.ProductName = ProductName; 
        NewItem.ProductURL = ProductURL; 
        NewItem.Price = Price; 
        NewItem.Quantity = Quantity; 
        _items.Add(NewItem); 
       } 
       else 
       { 
        _items[ItemIndex].Quantity += 1; 
       } 
       _lastUpdate = DateTime.Now; 
      } 

      public void Update(int RowID, int ProductID, int Quantity, double Price) 
      { 
       CartItem Item = _items[RowID]; 
       Item.ProductID = ProductID; 
       Item.Quantity = Quantity; 
       Item.Price = Price; 
       _lastUpdate = DateTime.Now; 
      } 
      public void DeleteItem(int rowID) 
      { 
       _items.RemoveAt(rowID); 
       _lastUpdate = DateTime.Now; 
      } 
      private int ItemIndexOfID(int ProductID) 
      { 
       int index = 0; 
       foreach (CartItem item in _items) 
       { 
        if (item.ProductID == ProductID) 
        { 
         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; 
       } 
      } 
     } 

    } 
} 

and then i create a web user control file ShoppingCart.ascx and ShoppingCart.ascx.cs file code are given below of ShoppingCart.ascx.cs 

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using MyWebsite.Commerce; 


public partial class ShoppingCart : System.Web.UI.UserControl 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (Profile.Cart == null) 
     { 
      Profile.Cart = new MyWebsite.Commerce.ShoppingCart(); 
     } 
     if (!Page.IsPostBack) 
     { 
      BindGrid(); 
     } 
     if (Profile.Cart.Items == null) 
     { 
      TotalLabel.Visible = false; 
     } 
    } 
    protected void CartGrid_RowEditing(object sender, GridViewEditEventArgs e) 
    { 
     CartGrid.EditIndex = e.NewEditIndex; 
     BindGrid(); 
    } 
    protected void CartGrid_RowUpdating(object sender, GridViewUpdatedEventArgs e) 
    { 
     TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; 
     int Quantity = Convert.ToString(QuantityTextBox.Text); 
     if (Quantity == 0) 
     { 
      Profile.Cart.Items.RemoveAt(e.RowIndaex); 
     } 
     else 
     { 
      Profile.Cart.Items[e.RowIndex].Quantity = Quantity; 
     } 
     CartGrid.EditIndex = -1; 
     BindGrid(); 
    } 
    protected void CartGrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 
    { 
     CartGrid.EditIndex = -1; 
     BindGrid(); 
    } 
    protected void CartGrid_RowDeleting(object sender, GridViewDeleteEventArgs e) 
    { 
     Profile.Cart.Items.RemoveAt(e.RowIndex); 
     BindGrid(); 
    } 

    private void BindGrid() 
    { 
     CartGrid.DataSource = Profile.Cart.Items; 
     DataBind(); 
     TotalLabel.Text = string.Format("Total : {0,19:c}", Profile.Cart.Total); 
    } 
} 

给我拖放在ShoppingCart.ascx文件来ShoppingCartPage .aspx文件并运行应用程序时出现错误,当我点击错误时,我继续阅读以下代码

说明:编译服务此请求所需的资源时发生错误。请查看以下具体的错误细节并适当修改您的源代码。

编译器错误消息:CS0234:该 类型或命名空间名称的购物' 在命名空间 “MyWebsite.Commerce”(?是否缺少 的组件参考)

线17不存在:公共类的ProfileCommon: System.Web.Profile.ProfileBase { 第18行:第19行:公共虚拟 MyWebsite.Commerce.ShoppingCart车{ 第20行:获得{行21:
回报 ((我Website.Commerce.ShoppingCart)(this.GetPropertyValue( “购物车”)));

请帮我..................

+0

昨天你发布了同样的问题。 – Shoban 2009-11-12 06:43:27

回答

0

不在于它是去了解解决此最佳或唯一途径,但我会尝试删除所有引用,并逐一添加它们,直到你再次获得工作。

0

这对我来说很难理解,所以我只是想在这里为你测试一个想法。因为我看到你的类

你有

namespace MyWebsite.Commerce 

,然后在你有一个类CartItem。然后,而不是有另一个完全独立的类ShoppingCart,你有CartItem中的那个类。

我可能是错误的(因为我没试过这个测试),但我觉得行的ASCX

Profile.Cart = new MyWebsite.Commerce.ShoppingCart(); 

应该

Profile.Cart = new MyWebsite.Commerce.CartItem.ShoppingCart(); 

注意额外CartItem。

或者将ShoppingCart类作为MyWebsite.Commerce命名空间中的单独类来编写。

相关问题