日期:2014-05-17 浏览次数:20373 次
string goumailiang = TextBox3.Text; //goumailiang是用户输入的购买数量
int goumailiang1 = Convert.ToInt32(goumailiang);
if (kc <= 0)
{
Response.Write("<script>alert('谢谢您的关注,本产品已售罄');document.location=document.location;</script>");
}
else
{
if (kc >= goumailiang1)
{
Session["text"] = goumailiang1;
// response.redirect("BuyCar.cs?shuliang={0}", goumailiang1 );
float price = BuyCar.GetPriceByGoodsID(id);
String shuliang = (DataTable)Session["text"];
//检查表中是否存在同名的订购物品
if (GoodsIsExist(GoodsID, MemberID))
{
//执行update语句,让同名的商品数量+1
sql = string.Format("update tb_BuyInfo set Number="+shuliang +",SumPrice=("+shuliang +")*{0} where GoodsID={1} and MemberID={2}", Price, GoodsID, MemberID);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
else
{
sql = string.Format("insert into tb_BuyInfo(GoodsID,MemberID,Number,SumPrice) values({0},{1},{2},{3})", GoodsID, MemberID, Num, Price);//默认订购1件商品,总价格就是商品单价
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
conn.Close();