資源簡介
通過本MyPetShop源代碼掌握ListControl類控件與數(shù)據(jù)源的綁定方法;熟練掌握GridView控件的應用;掌握DetailsView控件的應用。設計并實現(xiàn)一個網(wǎng)上購物網(wǎng)站
代碼片段和文件信息
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;
??????//如果客戶當前寵物商品已在購物車內(nèi),則只要修改數(shù)量即可
??????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;
????}
????///?
????///?更新購物車中購物項的數(shù)量
????///?
????public?CartItem?Update(int?customerId?int?productId?int?qty)
????{
??????CartItem?cartItem?=?null;
??????//如果客戶當前寵物商品已在購物車內(nèi),則只要修改數(shù)量即可;數(shù)量為0時刪除該購物項
??????cartItem?=?(from?c?in?db.CartItem
??????????????????where?c.CustomerId?==?customerId?&&?c.ProId?==?productId
??????????????????select?c).First();
??????if?(cartItem?!=?null)
??????{
????????cartItem.Qty?=?qty;
????????//數(shù)量為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個文件信息
評論
共有 條評論