protected void addcart_Click(object sender, ImageClickEventArgs e) { Userinfo user = new Userinfo(); if (this.countliteral.Text.Trim() != "缺货") { cart ocart = new cart(); if (ocart.isexitproduct(int.Parse(this.Request.QueryString["pid"].ToString())) == false) { if (ocart.addtocart(int.Parse(this.Request.QueryString["pid"].ToString()), user.getUserID(), 1, false) == 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物成功')</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物失败')</script>", false); } } else { if (ocart.updatecartbyid(int.Parse(this.Request.QueryString["pid"].ToString())) == 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物成功')</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物失败')</script>", false); } } } else { this.addcart.Enabled = false; } }
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "buy") { Label productidlabel = e.Item.FindControl("productid") as Label; Userinfo user = new Userinfo(); { product pro = new product(); DataRow dr = pro.getoneproduct(int.Parse(productidlabel.Text)); if ((int.Parse(dr["count"].ToString()) > int.Parse(dr["sellcount"].ToString()))) { cart ocart = new cart(); if (ocart.isexitproduct(int.Parse(productidlabel.Text)) == false) { if (ocart.addtocart(int.Parse(productidlabel.Text), user.getUserID(), 1, false) == 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物成功')</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物失败')</script>", false); } } else { if (ocart.updatecartbyid(int.Parse(productidlabel.Text)) == 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物成功')</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('购物失败')</script>", false); } } } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('该商品缺货中')</script>", false); } } } }