• 大小: 33.99MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-30
  • 语言: C#
  • 标签: web  asp.net  C#  

资源简介

通过本MyPetShop源代码掌握ListControl类控件与数据源的绑定方法;熟练掌握GridView控件的应用;掌握DetailsView控件的应用。设计并实现一个网上购物网站

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MyPetShop.DAL;

namespace MyPetShop.BLL
{
  public class CartItemService
  {
    MyPetShopDataContext db = new MyPetShopDataContext();

    public CartItem Add(int customerId int productId int qty)
    {
      CartItem cartItem = null;

      Product product = (from p in db.Product
                         where p.ProductId == productId
                         select p).First();
      //当前需要添加的CartItem对象
      cartItem = new CartItem();
      cartItem.CustomerId = customerId;
      cartItem.ProId = product.ProductId;
      cartItem.ProName = product.Name;
      cartItem.ListPrice = product.ListPrice.Value;
      cartItem.Qty = qty;

      //如果客户当前宠物商品已在购物车内,则只要修改数量即可
      int ExistCartItemCount = (from c in db.CartItem
                                where c.CustomerId == customerId && c.ProId == productId
                                select c).Count();
      if (ExistCartItemCount > 0) //修改
      {
        CartItem existCartItem = (from c in db.CartItem
                                  where c.CustomerId == customerId && c.ProId == productId
                                  select c).First();
        existCartItem.Qty += qty;//添加
      }
      else
      {
        db.CartItem.Insertonsubmit(cartItem);
      }

      db.SubmitChanges();
      return cartItem;
    }

    /// 
    /// 更新购物车中购物项的数量
    /// 

    public CartItem Update(int customerId int productId int qty)
    {
      CartItem cartItem = null;

      //如果客户当前宠物商品已在购物车内,则只要修改数量即可;数量为0时删除该购物项
      cartItem = (from c in db.CartItem
                  where c.CustomerId == customerId && c.ProId == productId
                  select c).First();
      if (cartItem != null)
      {
        cartItem.Qty = qty;
        //数量为0时删除
        if (cartItem.Qty <= 0)
        {
          db.CartItem.Deleteonsubmit(cartItem);
        }
        db.SubmitChanges();
      }

      return cartItem;
    }

    /// 
    /// 删除购物车中购物项
    /// 

    public void Delete(int customerId int productId)
    {
      CartItem cartItem = (from c in db.CartItem
                           where c.CustomerId == customerId && c.ProId == productId
                           select c).First();
      if (cartItem != null)
      {
        db.CartItem.Deleteonsubmit(cartItem);
        db.SubmitChanges();
      }
    }

    /// 
    /// 清除购物车中所有购物项
    /// 

    public void Clear(int customerId)
    {
      List cartItemList = (from c in db.CartItem
                                     where c.CustomerId == customerId
                                     select c).ToList();
      foreach (CartItem cartItem in cartItemList)
      {
        db.CartItem.Deleteonsubmit(cartItem);
      }
      db.SubmitChanges();
    }

    public List

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-02-23 17:09  MyPetShop\
     目录           0  2018-02-23 17:09  MyPetShop\.vs\
     目录           0  2018-02-23 17:09  MyPetShop\.vs\config\
     文件       79218  2018-02-22 14:51  MyPetShop\.vs\config\applicationhost.config
     目录           0  2018-02-23 17:09  MyPetShop\.vs\MyPetShop\
     目录           0  2018-02-23 17:09  MyPetShop\.vs\MyPetShop\v15\
     文件      131584  2018-08-02 17:19  MyPetShop\.vs\MyPetShop\v15\.suo
     目录           0  2018-02-23 17:09  MyPetShop\.vs\MyPetShop\v15\Server\
     目录           0  2018-08-02 17:19  MyPetShop\.vs\MyPetShop\v15\Server\sqlite3\
     文件           0  2018-02-08 10:39  MyPetShop\.vs\MyPetShop\v15\Server\sqlite3\db.lock
     文件     2326528  2018-08-02 17:19  MyPetShop\.vs\MyPetShop\v15\Server\sqlite3\storage.ide
     目录           0  2018-02-23 17:09  MyPetShop\.vs\tong\
     目录           0  2018-02-23 17:09  MyPetShop\.vs\tong\v15\
     文件       58880  2018-02-22 14:48  MyPetShop\.vs\tong\v15\.suo
     目录           0  2018-02-23 17:09  MyPetShop\.vs\tong\v15\Server\
     目录           0  2018-02-23 17:09  MyPetShop\.vs\tong\v15\Server\sqlite3\
     文件           0  2018-02-22 11:30  MyPetShop\.vs\tong\v15\Server\sqlite3\db.lock
     文件     1118208  2018-02-22 14:48  MyPetShop\.vs\tong\v15\Server\sqlite3\storage.ide
     目录           0  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\
     目录           0  2018-02-23 17:09  MyPetShop\MyPetShop.BLL\bin\
     目录           0  2018-02-23 17:09  MyPetShop\MyPetShop.BLL\bin\Debug\
     文件       21504  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\bin\Debug\MyPetShop.BLL.dll
     文件       38400  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\bin\Debug\MyPetShop.BLL.pdb
     文件       29184  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\bin\Debug\MyPetShop.DAL.dll
     文件         473  2018-02-23 16:59  MyPetShop\MyPetShop.BLL\bin\Debug\MyPetShop.DAL.dll.config
     文件       73216  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\bin\Debug\MyPetShop.DAL.pdb
     目录           0  2018-02-08 10:58  MyPetShop\MyPetShop.BLL\bin\Release\
     文件        3722  2018-02-21 14:41  MyPetShop\MyPetShop.BLL\CartItemService.cs
     文件        1961  2018-02-21 14:41  MyPetShop\MyPetShop.BLL\CategoryService.cs
     文件        4108  2018-08-02 17:15  MyPetShop\MyPetShop.BLL\CustomerService.cs
     文件        2723  2018-02-22 09:40  MyPetShop\MyPetShop.BLL\MyPetShop.BLL.csproj
............此处省略724个文件信息

评论

共有 条评论