C# 怎么做购物车

liyi002 2010-12-02 02:50:41
现在不知道如何下手。。请高手给个思路
最好 给个参与资料 是基于access数据 库的
...全文
300 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxlxmd 2010-12-02
  • 打赏
  • 举报
回复
cookies吧
Session 感觉不是很好用
老鼠找猫 2010-12-02
  • 打赏
  • 举报
回复
用DataTable实现临时购物车,
最好采用数据库来存放,当你下次登录进来的时候,能看到原来选购的东西。
tlzjff 2010-12-02
  • 打赏
  • 举报
回复
用 cookies 也不错,关机开机后,购物车东西还在,不过换了电脑后就没了,新蛋和京东好像都是cookies
Return门徒 2010-12-02
  • 打赏
  • 举报
回复
购物车实体类

public class Cart
{
private product _Products;//产品

public product Products
{
get { return _Products; }
set { _Products = value; }
}
private int _Count;//购买数量

public int Count
{
get { return _Count; }
set { _Count = value; }
}
private double _Price;//单品总价
public double Price
{
get { return _Price; }
set { _Price = value; }
}
}
Return门徒 2010-12-02
  • 打赏
  • 举报
回复
购物车操作类

public class ShoppingCart : System.Web.UI.Page
{
B_product Bproduct = new B_product();
//所有
public List<Cart> getAll()
{
List<Cart> list = new List<Cart>();
if (Session["Cart"] == null)
{
list = null;

}
else
{
list = Session["Cart"] as List<Cart>;
}
return list;
}
//增加
public List<Cart> getCart(Cart c)
{
List<Cart> list = new List<Cart>();
if (Session["Cart"] == null)
{
list.Add(c);
Session["Cart"] = list;
Session.Timeout = 60;

}
else
{
list = (List<Cart>)Session["Cart"];
bool yn = false;
for (int i = 0; i < list.Count; i++)
{
if (list[i].Products.Id == c.Products.Id)
{
list[i].Count += c.Count;
list[i].Price = list[i].Count * list[i].Products.ProductPrice;
Session["Cart"] = list;
yn = true;
}
}
if (yn == false)
{
list.Add(c);
Session["Cart"] = list;
}
}
return list;
}
//删除
public List<Cart> getDeleCart(Cart c)
{
List<Cart> list = new List<Cart>();
list = (List<Cart>)Session["Cart"];
for (int i = 0; i < list.Count; i++)
{
if (list[i].Products.Id == c.Products.Id)
{
list.Remove(c);
Session["Cart"] = list;
}
}
return list;
}
//更新
public List<Cart> getUpdaCart(Cart c)
{
List<Cart> list = new List<Cart>();
list = (List<Cart>)Session["Cart"];
for (int i = 0; i < list.Count; i++)
{
if (list[i].Products.Id == c.Products.Id)
{
list[i].Count = c.Count;
list[i].Price = c.Price;
Session["Cart"] = list;
}
}
return list;
}
}
Return门徒 2010-12-02
  • 打赏
  • 举报
回复
用session,把所选物品放入其中
每次填加都要判断session中物品是否已存在
如果没有,新加一个,如果有在数量上加一个

也就是说,在没有付款前所有操作都是基于session中的

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧