关于购物车实现原理,大家说说!!!! 放到session数组里??其他的朋友呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 两种方法都可以,微软的IBuySpy示例是放在数据库中,不过也要用到session,你可以下个IBuySpy看看! using System;using System.Collections;namespace Unique.Test.DbObject{ public class BookOrder { string itemID; string title; decimal price; string quantity; public string ItemID { get { return itemID; } set { itemID=value; } } public string Title { get { return title; } set { title=value; } } public decimal Price { get { return price; } set { price=value; } } public string Quantity { get { return quantity; } set { quantity=value; } } public BookOrder(string ItemID,string Title,decimal Price,string Quantity) { this.itemID=ItemID; this.title=Title; this.price=Price; this.quantity=Quantity; } } public class BookCart { Hashtable ht; public BookCart() { ht=new Hashtable(); } public ICollection htValue { get { return ht.Values; } } public BookOrder this[int index] { get { return (BookOrder)ht[index]; } } public decimal TotalCost() { decimal total=0; foreach(DictionaryEntry Entry in ht) { BookOrder Order=(BookOrder)Entry.Value; total+=(Convert.ToInt32(Order.Quantity) * Order.Price); } return total; } public void AddOrder(BookOrder Book) { BookOrder Order=(BookOrder)ht[Book.ItemID]; if(Order!=null) { Order.Quantity+=Book.Quantity; } else { ht.Add(Book.ItemID,Book); } } public void Remove(string ItemID) { if(ht[ItemID]!=null) { ht.Remove(ItemID); } } }} 还是数据库方便点阿,根据IBuySpy里说的,即使客户没有CheckOut,到下次登录的时候也可以恢复上次的购物记录 PetShop和duwamish是放数组里的。一般都的ShoppingCart都是这样做的。不过不能查看上次的记录. 先放在session中如果要购买了就提交到订单表中 如果全部放到Session里的话恐怕不太好,如果session过期他所选的商器就会丢掉,并且增加许多系统开销。建议放到数据库里面,放到数据库里的话还有一个问题就是如何来标识用户。你如果在用户选购商品之前要求用户登录那是很烦的。所以最好用cookie值来标识用户,并且他下次登录时还可以显示他之前选过的商品。他不支持cookie保存也没关系,不影响他当次的在线购物,只是下次他来时不能看到之前选过的商品。 session没问题的,过期时间放长一点,cookie也不好啊,客户有的不喜欢那玩意 订单提示 ASP +Mysql proc GridView编辑 将TextBox改变成其它控件问题 如何把asp.net页面生成HTML页面啊 gridview中使用js 来者有分,大家是如何实现"[1][2][3][4][5][6]"这种分页方法的??在线急等!! 如何通过一个函数输出两个数组? sql语句问题,请高手帮忙 asp.net 求大神。。。网页图片的放大问题 请问各位大虾,C#中如何列出局域网内其他机器的名称? 关于页面布局
using System.Collections;namespace Unique.Test.DbObject
{
public class BookOrder
{
string itemID;
string title;
decimal price;
string quantity; public string ItemID
{
get
{
return itemID;
}
set
{
itemID=value;
}
} public string Title
{
get
{
return title;
}
set
{
title=value;
}
} public decimal Price
{
get
{
return price;
}
set
{
price=value;
}
} public string Quantity
{
get
{
return quantity;
}
set
{
quantity=value;
}
} public BookOrder(string ItemID,string Title,decimal Price,string Quantity)
{
this.itemID=ItemID;
this.title=Title;
this.price=Price;
this.quantity=Quantity;
}
} public class BookCart
{
Hashtable ht;
public BookCart()
{
ht=new Hashtable();
} public ICollection htValue
{
get
{
return ht.Values;
}
} public BookOrder this[int index]
{
get
{
return (BookOrder)ht[index];
}
} public decimal TotalCost()
{
decimal total=0;
foreach(DictionaryEntry Entry in ht)
{
BookOrder Order=(BookOrder)Entry.Value;
total+=(Convert.ToInt32(Order.Quantity) * Order.Price);
} return total;
} public void AddOrder(BookOrder Book)
{
BookOrder Order=(BookOrder)ht[Book.ItemID];
if(Order!=null)
{
Order.Quantity+=Book.Quantity;
}
else
{
ht.Add(Book.ItemID,Book); }
} public void Remove(string ItemID)
{
if(ht[ItemID]!=null)
{
ht.Remove(ItemID);
}
}
}}