/// <summary> /// 保存子商品,js形式 /// </summary> /// <param name="pid"></param> protected void SaveChildProduct2(TB_Product_Products entity) { string[] ids = Request["pid"].ToStr().Split(','); string[] names = Request["name"].ToStr().Split(','); string[] proNumbers = Request["proNumber"].ToStr().Split(','); string[] colors = Request["color"].ToStr().Split(','); string[] purchasPrices = Request["purchasPrice"].ToStr().Split(','); string[] marketPrices = Request["marketPrice"].ToStr().Split(','); string[] salesPrices = Request["salesPrice"].ToStr().Split(','); for (int i = 0; i < names.Length; i++) { entity.ProName = names[i]; entity.ProNumber = proNumbers[i]; entity.Color = colors[i]; entity.PurchasPrice = purchasPrices[i].ToDecimal(); entity.MarketPrice = marketPrices[i].ToDecimal(); entity.SalesPrice = salesPrices[i].ToDecimal(); entity.ParentId = entity.ID; entity.AddDate = DateTime.Now; if (ids[0].ToInt() == 0) { ProductService.ProductsService.Insert(entity); } else { entity.ID = ids[0].ToInt(); ProductService.ProductsService.Update(entity); } } }
protected void RepChildList_ItemCommand(object sender, RepeaterCommandEventArgs e) { string commandName = e.CommandName; string value = e.CommandArgument.ToStr(); if (commandName == "delete") { List <TB_Product_Products> list = new List <TB_Product_Products>(); foreach (RepeaterItem item in RepChildList.Items) { string thisIndex = ((HiddenField)item.FindControl("Index")).Value; if (value != thisIndex) { TB_Product_Products entity = new TB_Product_Products(); entity.ProName = ((TextBox)item.FindControl("ProName")).Text; entity.ProNumber = ((TextBox)item.FindControl("ProNumber")).Text; entity.Color = ((TextBox)item.FindControl("Color")).Text; entity.PurchasPrice = ((TextBox)item.FindControl("PurchasPrice")).Text.ToDecimal(); entity.MarketPrice = ((TextBox)item.FindControl("MarketPrice")).Text.ToDecimal(); entity.SalesPrice = ((TextBox)item.FindControl("SalesPrice")).Text.ToDecimal(); list.Add(entity); } } RepChildList.DataSource = list; RepChildList.DataBind(); } }
//添加子商品 protected void BtnAddChild_Click(object sender, EventArgs e) { List <TB_Product_Products> list = new List <TB_Product_Products>(); TB_Product_Products entity2 = new TB_Product_Products(); list.Add(entity2); foreach (RepeaterItem item in RepChildList.Items) { TB_Product_Products entity = new TB_Product_Products(); entity.ID = ((HiddenField)item.FindControl("ID")).Value.ToInt(); entity.ProName = ((TextBox)item.FindControl("ProName")).Text; entity.ProNumber = ((TextBox)item.FindControl("ProNumber")).Text; entity.Color = ((TextBox)item.FindControl("Color")).Text; entity.PurchasPrice = ((TextBox)item.FindControl("PurchasPrice")).Text.ToDecimal(); entity.MarketPrice = ((TextBox)item.FindControl("MarketPrice")).Text.ToDecimal(); entity.SalesPrice = ((TextBox)item.FindControl("SalesPrice")).Text.ToDecimal(); list.Add(entity); } RepChildList.DataSource = list; RepChildList.DataBind(); }
//加载 public void LoadDataBind() { int ID = CommonClass.ReturnRequestInt("id", 0); if (ID > 0) { TB_Product_Products model = ProductService.ProductsService.Get(ID); if (model.ID.ToInt() > 0) { ViewState["id"] = model.ID; TB_Product_Categorys category = ProductService.CategoryService.Get(model.CategoryID); DDLOneLevel.SelectedValue = ProductService.CategoryService.Get(category.ParentID).ParentID.ToStr(); GetTwoCategory(); DDLTwoLevel.SelectedValue = category.ParentID.ToStr(); GetThreeCategory(); DDLThreeLevel.SelectedValue = model.CategoryID.ToStr(); BindProperties(); BindBrand(model.CategoryID); TbProductName.Text = model.ProName; TbProNumber.Text = model.ProNumber; TbIntroduction.Text = model.Introduction; DDLBrand.SelectedValue = model.BrandID.ToStr(); ProPic.Url = model.PicUrl; ProImg.Url = model.ImgUrl; TbPurchasPrice.Text = model.PurchasPrice.ToStr(); TbMarketPrice.Text = model.MarketPrice.ToStr(); TbSalesPrice.Text = model.SalesPrice.ToStr(); TbColor.Text = model.Color; FckDesc.Value = model.ProDesc; FckPakingList.Value = model.PakingList; FckSalesService.Value = model.CustomerService; TbOrderBy.Text = model.OrderBy.ToStr(); TbKeyWord.Text = model.KeyWord; TbClickCount.Text = model.ClickCount.ToStr(); CheckBoxIsHidden.Checked = model.IsHidden; DDLVouchType.SelectedValue = model.VouchType.ToStr(); TbDate.Text = model.AddDate.ToString(); foreach (ListItem li in CheckBoxListMark.Items) { if (model.Mark.Contains(li.Value)) { li.Selected = true; } } //绑定子商品 RepChildList.DataSource = GetChildProducts(model.ID); RepChildList.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { ButtonDelete.Attributes.Add("onclick", "return confirm('确认删除这条信息吗?')"); if (!IsPostBack) { ViewState["PageIndex"] = 1; ViewState["search"] = ""; LoadDataBind(); } product = ProductService.ProductsService.Get(Request["pid"]); }
//加载所有信息 public void LoadDataBind() { int pageSize = AspNetPager1.PageSize; int recordCount = 0; int pageIndex = ViewState["PageIndex"].ToInt(); List <Expression> expression = new List <Expression>(); expression.Add(new Expression("ProID", "=", Request["pid"])); RepList.DataSource = ProductService.PictureService.Search(pageSize, pageIndex, expression, "AddDate desc", ref recordCount); RepList.DataBind(); AspNetPager1.RecordCount = recordCount; product = ProductService.ProductsService.Get(Request["pid"]); }
/// <summary> /// 保存子商品 /// </summary> /// <param name="pid"></param> protected void SaveChildProduct(TB_Product_Products entity) { //旧数据 List <int> ids = GetChildProducts(entity.ID).Select(p => p.ID).ToList(); //新数据 List <int> thisIds = new List <int>(); foreach (RepeaterItem item in RepChildList.Items) { int id = ((HiddenField)item.FindControl("ID")).Value.ToInt(); entity.ProName = ((TextBox)item.FindControl("ProName")).Text; entity.ProNumber = ((TextBox)item.FindControl("ProNumber")).Text; entity.Color = ((TextBox)item.FindControl("Color")).Text; entity.PurchasPrice = ((TextBox)item.FindControl("PurchasPrice")).Text.ToDecimal(); entity.MarketPrice = ((TextBox)item.FindControl("MarketPrice")).Text.ToDecimal(); entity.SalesPrice = ((TextBox)item.FindControl("SalesPrice")).Text.ToDecimal(); entity.ParentId = entity.ID; entity.AddDate = DateTime.Now; if (id == 0) { ProductService.ProductsService.Insert(entity); } else { entity.ID = id; ProductService.ProductsService.Update(entity); thisIds.Add(id); } } foreach (int id in ids) { //如果当前id存在说明为删除,不存在说明删除 if (!thisIds.Contains(id)) { //删除 ProductService.ProductsService.Delete(id); } } }
//推荐设置 protected void ButtonVouchSet_Click(object sender, EventArgs e) { foreach (RepeaterItem ri in RepList.Items) { CheckBox cb = ((CheckBox)ri.FindControl("CheckBoxChoose")); int ID = Convert.ToInt32(((HiddenField)ri.FindControl("HiddenFieldID")).Value); if (cb.Checked == true) { TB_Product_Products model = ProductService.ProductsService.Get(ID); model.Mark = ""; foreach (ListItem li in CheckBoxListMark.Items) { if (li.Selected == true) { model.Mark += li.Value + ","; } } ProductService.ProductsService.Update(model); } } //重新加载 LoadDataBind(); }
/// <summary> /// 添加购物车 /// </summary> /// <param name="type">商品类型,0为普通商品,1为团购商品</param> /// <param name="proId">商品编号</param> /// <param name="count">商品数量</param> /// <returns></returns> public static bool AddCart(int type, int proId, int count) { if (!File.Exists(path)) { CreateXMLFile(path); } decimal marketPrice = 0; //获取购物车里面的数据 TB_Order_OrderDetails model = new TB_Order_OrderDetails(); switch (type) { case 0: TB_Product_Products entity = ProductService.ProductsService.Get(proId); model.ProductID = entity.ID; model.ProNumber = entity.ProNumber; model.ProName = entity.ProName; model.Price = entity.SalesPrice; model.Picture = entity.ImgUrl; marketPrice = entity.MarketPrice; break; case 1: TB_Product_Group entity2 = ProductService.GroupService.Get(proId); model.ProductID = entity2.ID; model.ProName = entity2.GroupName; model.Price = entity2.Price; model.Picture = entity2.ImgUrl; break; } DataSet ds = new DataSet(); ds.ReadXml(path); if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; //当前商品是否存在 bool isExist = false; foreach (DataRow dr in dt.Rows) { if (dr["id"].ToInt() == proId && dr["type"].ToInt() == type) { isExist = true; dr["count"] = dr["count"].ToInt() + count; dr["amount"] = model.Price * dr["count"].ToInt(); } } //当不存在 if (isExist == false) { DataRow dr = dt.NewRow(); dr["type"] = type.ToStr(); dr["id"] = model.ProductID; dr["proNumber"] = model.ProNumber; dr["name"] = model.ProName; dr["img"] = model.Picture; dr["marketPrice"] = marketPrice; dr["count"] = count; dr["price"] = model.Price; dr["amount"] = model.Price * count; dt.Rows.Add(dr); } //保存到购物车 ds.WriteXml(path); } else { AddProductInfo(type, model, count); } return(true); }
//保存 protected void BtnSave_Click(object sender, EventArgs e) { lock (obj) { TB_Product_Products model = new TB_Product_Products(); if (ViewState["id"] != null) { model = ProductService.ProductsService.Get(ViewState["id"]); } model.CategoryID = DDLThreeLevel.SelectedValue.ToInt(); model.CategoryName = DDLThreeLevel.SelectedItem.Text; model.ProName = TbProductName.Text; model.ProNumber = TbProNumber.Text; model.Introduction = TbIntroduction.Text; model.BrandID = DDLBrand.SelectedValue.ToInt(); model.PicUrl = ProPic.Url; model.ImgUrl = ProImg.Url; model.PurchasPrice = TbPurchasPrice.Text.ToDecimal(); model.MarketPrice = TbMarketPrice.Text.ToDecimal(); model.SalesPrice = TbSalesPrice.Text.ToDecimal(); model.Color = TbColor.Text; model.ProDesc = FckDesc.Value; model.PakingList = FckPakingList.Value; model.CustomerService = FckSalesService.Value; model.OrderBy = TbOrderBy.Text.ToInt(); model.KeyWord = TbKeyWord.Text; model.ClickCount = TbClickCount.Text.ToInt(); model.IsHidden = CheckBoxIsHidden.Checked; model.VouchType = DDLVouchType.SelectedValue.ToInt(); model.Creater = AdminUserName; model.AddDate = Convert.ToDateTime(TbDate.Text); foreach (ListItem li in CheckBoxListMark.Items) { if (li.Selected == true) { model.Mark += li.Value + ","; } } if (ViewState["id"] == null) { if (ProductService.ProductsService.Insert(model) == 1) { model = ProductService.ProductsService.Search(1, new List <Expression>(), "id desc").First(); //保存商品属性 SaveProperties(model.ID); //保存子商品 SaveChildProduct(model); MessageDiv.InnerHtml = CommonClass.Reload("数据添加成功"); } else { MessageDiv.InnerHtml = CommonClass.Alert("数据添加失败"); } } else { if (ProductService.ProductsService.Update(model) == 1) { //保存商品属性 SaveProperties(model.ID); //保存子商品 SaveChildProduct(model); MessageDiv.InnerHtml = CommonClass.Reload("数据修改成功"); } else { MessageDiv.InnerHtml = CommonClass.Alert("数据修改失败"); } } } }
protected void Page_Load(object sender, EventArgs e) { id = CommonClass.ReturnRequestInt("id", 0); if (id > 0) { //Response.Redirect("product_"+ id.ToStr() + ".html"); Product = ProductService.ProductsService.Get(id); List <Expression> picExpression = new List <Expression>(); picExpression.Add(new Expression("ProID", "=", id)); //获取图片列表 picList = ProductService.PictureService.Search(picExpression, " OrderBy asc"); if (Product.ID == 0) { Response.Redirect(CommonClass.AppPath); } } else { Response.Redirect("Products.aspx"); } //获取会员信息 if (Request.Cookies["MemberInfo"] != null) { memberName = Request.Cookies["MemberInfo"].Values["MemberName"].ToStr(); memberID = Request.Cookies["MemberInfo"].Values["ID"].ToInt(); //添加浏览记录 List <Expression> expression = new List <Expression>(); expression.Add(new Expression("MemberId", "=", memberID.ToStr())); expression.Add(new Expression("ProId", "=", id.ToStr())); TB_Product_BrowerRecord entity = ProductService.BrowerRecordService.Get(expression); //判断是否已经浏览过此商品 if (entity.MemberId > 0) { entity.BrowerDate = DateTime.Now; ProductService.BrowerRecordService.Update(entity, expression); } else { entity.MemberId = memberID; entity.ProId = id; entity.BrowerDate = DateTime.Now; ProductService.BrowerRecordService.Insert(entity); } } if (!IsPostBack) { //相关产品 List <Expression> expression = new List <Expression>(); expression.Add(new Expression("CategoryId", "=", Product.CategoryID.ToStr())); RepList.DataSource = ProductService.ProductsService.Search(20, expression); RepList.DataBind(); //绑定评论 BindComments(1); //绑定提问 BindQuestions(1); } }