见Ibuyadventure;到wrox.com上去下载一个,
该程序使用得是即时注册,用户不需注册和登陆就可以把物品放进购物车,等到结帐得时候在进行登陆或注册,该程序采用得是数据库储存会话,不容易发生信息丢失现象,采用得是n层结构,表示层,业务逻辑层,数据层

解决方案 »

  1.   

    http://web.wrox.com/0764558900/ASP.NET_Code.rar
    最后一章
      

  2.   

    The IBuySpy Store Solution Kit is an e-commerce storefront selling fictional spy equipment. http://www.asp.net/Default.aspx?tabindex=5&tabid=42
      

  3.   

    我想用一个简单的session来实现,有代码的例子么?
      

  4.   

    session用来储存用户的帐号,不可能所有的都用产品实现,这样太消耗资源,产品号,帐号等都是依靠传递参数来实现存储,修改,删除的
      

  5.   

    不可能所有的都用产品实现===》不可能所有的都用session实现
      

  6.   

    购物车是电子商务网站中不可缺少的组成部分,但目前大多数购物车只能作为一个顾客选中商品的展示,客户端无法将购物车里的内容提取出来满足自己事务处理的需要,而这一点在有些电子商务活动中很有必要。XML的出现使得网络上传输的数据变得有意义起来,我们可以根据不同的要求以不同的样式将一个购物车的内容显示出来。 本文将详细分析一个由Java实现的基于XML的购物车。下面是一个包含了五件商品的购物车的XML内在结构:它的根元素为cart,total元素表示购物车内的总金额,每个item元素表示一件商品,item里的子元素分别标明了该商品的具体信息,可根据实际情况添加、修改或删除。 在这里,需要建立一个表示购物车的类:XMLCart.java,它是一个JavaBean,所以它包含了一个空的构造函数。这个类包含了购物车的一些基本功能: 生成一个空的购物车,往购物车里添加商品,删除购物车里的商品,改变购物车内商品的数量以及清空购物车等。它拥有一个全局私有变量“private XMLDocument myCart”,myCart用来存储购物车里的详细内容,购物车的基本功能就是对它的操作,它的类型是XMLDocument,即一个XML文档。这样,对购物车的操作就转换成对myCart中的子元素的添加、删除,及元素值的计算、修改等。 1. 清空购物车 清空购物车即生成一个空的购物车。这里空购物车是一个含有根元素cart及其元素total的XML文档,total元素是购物车的总金额,它的初始值为0,其XML具体形式如下: < ?xml version=‘1.0’ encoding=‘gb2312’?>
    < cart>
    < total>0< /total>
    < /cart>
    将这个XML字符串由parseString函数转换成XMLDocument存入myCart。
    其代码如下:
    public void emptyCart() throws IOException,SAXException{
        String stringCart=“< ?xml version=‘1.0’encoding=‘gb2312’?> ”+
           “< cart>< total>0< /total>< /cart>”;
          myCart=parseString(stringCart);
        }2. 添加商品
    添加商品,即将传入的item元素添加到根元素cart里,
    其中item里包括商品详细信息,
    同时计算total的值。其代码如下:
    public void addItemToCart(String stringItem)
    throws IOException,SAXException{
    //将item由String转换为XMLDocument
    XMLDocument itemAdded=parseString(stringItem);
    //取出item节点,并复制它
    NodeList itemList=itemAdded.getElementsByTagName(“item”);
    Node item=itemList.item(0);
    Node cloneItem=item.cloneNode(true);
    //如果购物车为空,则构造一个新的购物车
    if(isCartEmpty()){
         myCart.emptyCart();
    }
    //如果该商品不在购物车中,则插入该商品,并计算总金额
    if(!isItemExist(item,myCart)){
    //取myCart的根元素,并将复制的item节点添加到后面
    Element cartRoot=myCart.getDocumentElement();
    Node cartNode=cartRoot.appendChild(cloneItem);        
    computeTotal();    //计算总金额
            }
        }
    3. 删除商品
    删除商品,即根据商品代码将该商品的item元素
    从myCart的根元素cart中删除,
    并重新计算total的值:
    public void moveItemFromCart(String id){
    //取出以item为单位的节点集cartList以及根元素cartRoot
      NodeList cartList=myCart.getElementsByTagName(“item”);
         Element cartRoot=myCart.getDocumentElement();
          //在cartList中查找代码为选中id的商品
        for(int x=0;x< cartList.getLength();x++){
          Node itemNode=cartList.item(x);
          String  idValue=itemNode.getFirstChild().
          getFirstChild().getNodeValue();
          //如果找到,则从cartRoot中删除该节点,并跳出循环
    if(idValue.equals(id)){
          itemNode=cartRoot.removeChild(itemNode);
           break;
                }
            }
            computeTotal();    //计算总金额
        }
    4. 改变商品数量
    根据客户在页面上所填的数量,修改myCart中quantity,
    并重新计算total: 
    public void addQuantityToCart(String qnty) throws 
    IOException,SAXException{
        //将传过来的包含商品数量的一组XML字符串转换为XML文档
    XMLDocument quantityChanged=parseString(qnty);
    //取出包含新数量的quantity节点集和myCart中的quantity节点集
    NodeList quantityList=quantityChanged.getElementsByTagName(“quantity”);
    NodeList cartList=myCart.getElementsByTagName(“quantity”);
    //循环改变商品的数量
    for(int x=0;x< cartList.getLength();x++){
    //将新quantity的值赋给myCart中相应的quantity中去
    String quantity=quantityList.item(x).getFirstChild().getNodeValue();
    cartList.item(x).getFirstChild().setNodeValue(quantity);
    }
    computeTotal();    //计算总金额
        }
    5. 计算总金额
    即计算total的值,其中total=∑(price*quantity): 
    public void computeTotal(){
        NodeList quantityList=myCart.getElementsByTagName(“quantity”);
        NodeList priceList=myCart.getElementsByTagName(“price”);
        float total=0;
        //累加总金额
    for(int x=0;x< priceList.getLength();x++){
        float quantity=Float.parseFloat(quantityList.item(x)
        .getFirstChild().getNodeValue());
      float price=Float.parseFloat(priceList.item(x).getFirstChild().getNodeValue());
        total=total+quantity*price;
        }
        //将total附给myCart的total
    String totalString=String.valueOf(total);
        myCart.getElementsByTagName(“total”).
        item(0).getFirstChild().setNodeValue(totalString);
      }
    6. 判断购物车是否为空
    通常在添加新商品时,还需要知道购物车是否为空,
    如果为空的话,则要生成一个新的购物车。
    public boolean isCartEmpty(){
    //item的节点集,如果该节点集包含的节点数为0,则购物车内没有商品,返回true
    NodeList itemList=myCart.getElementsByTagName(“item”);
    if(itemList.getLength()==0) return true;
    else return false;
    }
    7. 判断所选商品是否已在购物车内
    即判断新传来商品的item是否已在myCart中存在,如果存在,返回true。
    public boolean isItemExist(Node item, XMLDocument cart){
      NodeList itemList=cart.getElementsByTagName(“item”);
          Node id=item.getFirstChild();
          String idValue=id.getFirstChild().getNodeValue();
          if(itemList.getLength()!=0){
              for(int x=0;x< itemList.getLength();x++){
               Node itemTemp = itemList.item(x);
              7Node idTemp=itemTemp.getFirstChild();
               String idTempValue=idTemp.getFirstChild().getNodeValue();
                if(idValue.equals(idTempValue)) return true;
                }
              return false;
            }
          return false;
        }除上述方法外,XMLCart还包括将XML字符串由输入时的String转换成XMLDocument的方法parseString,以及用于输出时将XSL赋给myCart并返回String型XML字串的 cartTurnToStringWithXSL方法来辅助购物车主要操作的实现 
      

  7.   

    http://www.fawcette.com/china/print.aspx?TotalPage=4&ID=94
      

  8.   

    用SESSION,用一个shopcart class
    {
    id,
    num
    }
    即可,自编例子
      

  9.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.Web.SessionState;
    namespace conan
    {
    public class order
    {
    private string m_id;
    private int m_amount;
    public order()
    {
    }
    public order(string str_id,int n_amount)
    {
    m_id=str_id;
    m_amount=n_amount;
    }
    public string id
    {
    get
    {
    return m_id;
    }
    }

    public int amount
    {
    get
    {
    return m_amount;
    }
    }
    }
    public class shopcart : System.Web.Services.WebService
    {
    public shopcart(string strUser)
    {
    InitializeComponent();
    m_user=strUser;
    Session["shoppingcart"]=m_user;
    }
    public shopcart()
    {
    InitializeComponent();
    if(Session["shoppingcart"]!=null)
    m_user=Session["shoppingcart"].ToString();
    if(Session["content"]!=null)
    m_list=(ArrayList)Session["content"];
    }
            private string m_user;
    public string user
    {
    get
    {
    if(Session["shoppingcart"]!=null)
                        return Session["shoppingcart"].ToString();
    else
    return null;
    }
    }
    private ArrayList m_list;
    public ArrayList list
    {
    get
    {
    if(Session["content"]!=null)
    {
    m_list=(ArrayList)Session["content"];
    return m_list;
    }
    else
    return null;
    }
    }
    public decimal cost
    {
    get
    {
    return (decimal)Session["cost"];
    }
    set
    {
    Session["cost"]=value;
    }
    }
    public int pay
    {
    get
    {
    return (int)Session["pay"];
    }
    set
    {
    Session["pay"]=value;
    }
    }
    public string memo
    {
    get
    {
    return Session["memo"].ToString();
    }
    set
    {
    Session["memo"]=value;
    }
    } public int choice
    {
    get
    {
    return (int)Session["choice"];
    }
    set
    {
    Session["choice"]=value;
    }
    }
    public bool invoice
    {
    get
    {
    return (bool)Session["invoice"];
    }
    set
    {
    Session["invoice"]=value;
    }
    }
    public int send
    {
    get
    {
    return (int)Session["send"];
    }
    set
    {
    Session["send"]=value;
    }
    }
    public void reset()
    {
    Session["shoppingcart"]=null;
    Session["content"]=null;
    }
    public void AddShoppingCart(string strID, int nAmount)
    {
    order neworder=new order(strID,nAmount);
    order oldorder;
    if(nAmount==0)
    {
    DeleteShoppingCart(strID);
    return;
    }
    if(Session["content"]!=null)
    {
    m_list=(ArrayList)Session["content"];
    }
    for(int i=0;i<m_list.Count;i++)
    {
    oldorder=(order)m_list[i];
    if(strID==oldorder.id)
    {
    UpdateShoppingCart(strID,nAmount+oldorder.amount);
    return;
    } }
    m_list.Add(neworder);
    Session["content"]=m_list;
    }
    public void DeleteShoppingCart(string strID)
    {
    order tmporder=new order();
    int index=0;
    if(Session["content"]!=null)
    {
    m_list=(ArrayList)Session["content"];
    for(index=0;index<m_list.Count;index++)
    {
    tmporder=(order)m_list[index];
    if(tmporder.id==strID)
    break;
    }
    if(index==m_list.Count)
    return;
    m_list.RemoveAt(index);
    Session["content"]=m_list;
    }

    }
    public void UpdateShoppingCart(string strID,int mAmount)
    {
    DeleteShoppingCart(strID);
    AddShoppingCart(strID,mAmount);
    Session["content"]=m_list;
    }
    public void DeleteAll()
    {
    Session["content"]=null;
    m_list.RemoveRange(0,m_list.Count);
    reset();
    }


    #region Component Designer generated code

    //Web 服务设计器所必需的
    private IContainer components = null;

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    m_list=new ArrayList();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if(disposing && components != null)
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    #endregion
    }}
      

  10.   

    To bitsbird
    请问在 
    http://web.wrox.com/0764558900/ASP.NET_Code.rar 最后一章
    那个范例, 我执行setup时会出现错误而无法将里面的档案做complier, 所以在最后一章的范例没有办法执行, 我想在最后一章中在components中的cs檔应该是要编译成dll檔后放在bin之下, 请问要怎么手动编译呢 ?