基本信息
源码名称:asp.net 购物车实例代码【附完整源码】
源码大小:0.03M
文件格式:.rar
开发语言:C#
更新时间:2013-02-22
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
此购物车实例主要有三大功能:1.折扣方案调整 2.商品列表 3.购物车
商品列表:
购物车:
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page {
public ShopCartSet ShopCart {
get {
return (ShopCartSet)Session["ShopCartSet"];
}
set {
Session["ShopCartSet"] = value;
}
}
public List<IDiscountable> DiscountsUsing {
get {
return (List<IDiscountable>)Application["DiscountsUsing"];
}
}
protected void Page_Load(object sender, EventArgs e) {
if (!this.IsPostBack) {
this.SetDataBind();
this.SetShopCartDataBind();
this.SetDiscountDataBind();
}
}
private void SetDataBind() {
ProductBLL bllProduct = new ProductBLL();
this.gvProducts.DataSource = bllProduct.GetAllProducts();
this.gvProducts.DataBind();
}
private void SetShopCartDataBind() {
this.gvShopCart.DataSource = this.ShopCart;
this.gvShopCart.DataBind();
}
private void SetDiscountDataBind() {
if (this.DiscountsUsing.Count > 0)
this.lblDiscountsDescriptions.Text = "现在,您可以享受以下折扣方案:";
this.lstDiscountsUsing.DataSource = this.DiscountsUsing;
this.lstDiscountsUsing.DataTextField = "Description";
this.lstDiscountsUsing.DataBind();
}
protected void gvProducts_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) {
int id = int.Parse((string)e.CommandArgument);
ProductBLL bllProduct = new ProductBLL();
Product product = bllProduct.GetProductById(id);
ShopCartItem item = new ShopCartItem(product, 1);
this.ShopCart.Add(item);
this.SetShopCartDataBind();
}
protected void gvShopCart_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Footer) {
e.Row.Cells[0].ColumnSpan = 3;
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
Label lblTotalPrice = e.Row.Cells[3].FindControl("lblTotalPrice") as Label;
lblTotalPrice.Text = string.Format("{0:F2} 元", this.ShopCart.TotalPrice);
Label lblPrice = e.Row.Cells[4].FindControl("lblPrice") as Label;
lblPrice.Text = string.Format("{0:F2} 元", this.ShopCart.Price);
}
}
protected void gvShopCart_RowCommand(object sender, GridViewCommandEventArgs e) {
int id = int.Parse((string)e.CommandArgument);
ShopCartItem item = this.ShopCart[id];
if (e.CommandName == "AddOne")
item.Count ;
if (e.CommandName == "RemoveOne") {
if (item.Count > 1)
item.Count--;
else
this.ShopCart.Remove(item);
}
if (e.CommandName == "SetCount") {
LinkButton btnSetCount = (LinkButton)e.CommandSource;
int newCount = int.Parse(((TextBox)btnSetCount.Parent.FindControl("txtCount")).Text);
item.Count = newCount;
}
if (e.CommandName == "DeleteItem")
this.ShopCart.Remove(item);
this.SetShopCartDataBind();
}
}