⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shopcartbussiness.cs

📁 ASP.NET 2.0动态网站设计实例源代码,本书介绍了ASP.NET2.0的基础知识
💻 CS
字号:
///////////////////////////////////////////////////////////
//  ShopcartBussiness.cs
//  Implementation of the Class ShopcartBussiness
//  Generated by Enterprise Architect
//  Created on:      13-五月-2006 19:53:13
///////////////////////////////////////////////////////////




using BookShop.Entity;
using BookShop.DataAccess;
using System.Data;
using System.Collections;

namespace BookShop.Bussiness
{
  /// <summary>
  /// 购物车业务
  /// </summary>
  public class ShopcartBussiness
  {

    public ShopcartBussiness()
    {

    }

    ~ShopcartBussiness()
    {

    }

    public virtual void Dispose()
    {

    }

    /// <summary>
    /// 将指定货物添加到购物车中
    /// </summary>
    /// <param name="cart"></param>
    /// <param name="goodsid"></param>
    /// <param name="count"></param>
    public void AddToCart(ref ShopcartEntity cart, GoodsEntity goods, int count)
    {
      bool contains = false;
      GoodsEntity tempGoods=new GoodsEntity();
      foreach (DictionaryEntry deGoods in cart.Goods)
      {
        tempGoods = (GoodsEntity)deGoods.Key;
        if (tempGoods.GoodsID == goods.GoodsID)
        {
          int scount = (int)deGoods.Value + count;
          cart.Goods.Remove(deGoods.Key);
          cart.Goods.Add(deGoods.Key, scount);
          contains = true;
          return;
        }
      }
      if (!contains)
      {
        cart.Goods.Add(goods, count);
      }
    }

    /// <summary>
    /// 清空购物车
    /// </summary>
    /// <param name="cart"></param>
    public void ClearCart(ref ShopcartEntity cart)
    {
      cart.Goods.Clear();
    }

    /// <summary>
    /// 根据会员ID从数据库中获取上次存储的购物车信息
    /// </summary>
    /// <param name="memberID"></param>
    public ShopcartEntity GetCartByMemberID(int memberID)
    {
      string cartString = new ShopCartAccess().GetCartByMemberID(memberID);
      if (cartString != null)
        return (ShopcartEntity)Common.DeserializeIt(cartString, typeof(ShopcartEntity));
      else
        return null;
    }

    /// <summary>
    /// 将购物车信息保存如数据库
    /// </summary>
    /// <param name="car"></param>
    public bool SaveCart(ShopcartEntity cart)
    {
      return new ShopCartAccess().SaveCart(cart);
    }
    /// <summary>
    /// 将指定货物从购物车中移除
    /// </summary>
    public void RemoveFromCart(ref ShopcartEntity cart, GoodsEntity goods)
    {
      GoodsEntity tempGoods = new GoodsEntity();
      foreach (DictionaryEntry deGoods in cart.Goods)
      {
        tempGoods = (GoodsEntity)deGoods.Key;
        if (tempGoods.GoodsID == goods.GoodsID)
        {
          cart.Goods.Remove(deGoods.Key);
          return;
        }
      }
    }
  }//end ShopcartBussiness

}//end namespace Bussiness

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -