protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e) { int productId = int.Parse(e.CommandArgument.ToString()); IProductBLL productBLL = (IProductBLL)SpringContext.Context.CreateSecurityProxyInstance("ProductBLL"); switch (e.CommandName.ToLower()) { case "delete": productBLL.Delete(productId); Response.Redirect("ProductList.aspx", true); break; case "putcar":; Product product = productBLL.Select(productId); OrderProduct orderProduct = new OrderProduct(); orderProduct.Num = 1; orderProduct.ProductID = productId; orderProduct.ProductName = product.ProductName; IUserBLL userBLL = (IUserBLL)SpringContext.Context.CreateSecurityProxyInstance("UserBLL"); ICustomBLL customBLL = (ICustomBLL)SpringContext.Context.CreateSecurityProxyInstance("CustomBLL"); if (customBLL.Select(userBLL.UserID).IsMember) { orderProduct.Price = product.MemberPrice; } else { orderProduct.Price = product.NormalPrice; } IShopCarBLL shopCarBLL = (IShopCarBLL)SpringContext.Context.CreateSecurityProxyInstance("ShopCarBLL"); shopCarBLL.Add(orderProduct); Response.Redirect("ShopCar.aspx", true); break; default: break; } }
/// <summary> /// 向购物车添加产品 /// </summary> private void Add() { string id = Request.QueryString["productId"]; if (!string.IsNullOrEmpty(id)) { int productId = 0; int.TryParse(id, out productId); IProductBLL productBLL = (IProductBLL)SpringContext.Context.CreateInstance("ProductBLL"); Model.Product product = productBLL.Select(productId); OrderProduct orderProduct = new OrderProduct(); orderProduct.Num = 1; orderProduct.ProductID = productId; orderProduct.ProductName = product.ProductName; IUserBLL userBLL = (IUserBLL)SpringContext.Context.CreateInstance("UserBLL"); ICustomBLL customBLL = (ICustomBLL)SpringContext.Context.CreateInstance("CustomBLL"); if (customBLL.Select(userBLL.UserID).IsMember) { orderProduct.Price = product.MemberPrice; } else { orderProduct.Price = product.NormalPrice; } shopCarBLL.Add(orderProduct); Response.Write("{success:true}"); } else { Response.Write("{success:false}"); } Response.End(); }