日期:2014-05-18  浏览次数:20605 次

请问各位高手,购物车应该怎么实现啊???(解决立即给分!!!)
我在自己做一个购物的网站,现在正在设计购物车和订单的功能.购物车的功能要有修改商品数量、删除购物车里的信息、显示购物车里的总金额、提交订单.
请问这个购物车应该如何实现??有没有相关的例子可以看??

大家都来帮忙!!

------解决方案--------------------
兄弟 这种例子网上一大把……
------解决方案--------------------
和一般的数据库一样啊,不过很多网站购物车的信息都是保存在session,开始并不保存到数据库,比如alibaba,ebay等就是这样保存在session!!!
------解决方案--------------------
这种例子很多的.
可以保存到数据库,也可以保存在Session中
你也可以看一下PetShop的购物车
------解决方案--------------------
网上下格Petshop或者是Duwanish看看,又可以得到你想要的,又可以学会规范的编程模式
------解决方案--------------------
baidu大把的例子
------解决方案--------------------
petshop~~~~
session保存一个购物车的实体类
------解决方案--------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace BookStore
{
/// <summary>
/// AddToCart 的摘要说明。
/// </summary>
public class AddToCart : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbInfo;
protected System.Web.UI.HtmlControls.HtmlForm QuickSearchFrom;
protected System.Web.UI.WebControls.Label lbAllPrice;
protected System.Web.UI.WebControls.Label lbAllDiscountPrice;
protected System.Web.UI.WebControls.Label lbDiscount;
protected System.Web.UI.WebControls.Button btToOrder;
protected System.Web.UI.WebControls.Button btClearAll;
protected System.Web.UI.WebControls.DataList dlCart;
static int nBookID, nUserID;
protected System.Web.UI.WebControls.Button btGoOn;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
if(Object.Equals(Session[ "UserName "],null))
{
Session[ "ReqestedURL "] = Request.RawUrl;
Response.Redirect( "../Error.aspx ");
}
else
{
nUserID = int.Parse(Session[ "UserID "].ToString());
if(Object.Equals(Request[ "BookID "],null))
{
BindData();
}
else
{
nBookID = int.Parse(Request[ "BookID "].ToString());
AddDataToCart();
BindData();
}
}
}
}

private void AddDataToCart()
{
string strSql;

strSql = "select Quantity from ShoppingCart where BookID= " + nBookID + " and UserID= " + nUserID;
if(IsExist(strSql))
{
this.lbInfo.Text = "这本书已经在购物车中了,请直接更改这本书的购买数目。 ";
}
else
{
strSql = "Insert into [ShoppingCart] (UserID,BookID,Quantity) Values( "
+ nUserID + ", "
+ nBookID + ", "
+ 1 + ") ";
try
{
RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);
}
catch
{
this.lbInfo.Text = "加入购物车失败! ";
return;
}
}
}


private void BindData()
{
float fAllPrice, fAllDiscountPrice;
fAllPrice = 0;
fAllDiscountPrice = 0;
DataTable currentDT;