protected void Btn_Add_Click(object sender, EventArgs e) { /*建立商品销售购物车模型取得商品销售信息*/ GoodCartInfoModel goodCartInfoModel = new GoodCartInfoModel(); goodCartInfoModel.GoodNo = this.GoodNo.Text; try { goodCartInfoModel.GoodCount = Int32.Parse(this.GoodCount.Text); } catch (Exception exception) { Response.Write("<script>alert('请输入正确的数字!');</script>"); return; } goodCartInfoModel.EmployeeNo = Session["employeeNo"].ToString(); /*调用业务层执行商品销售信息的加入操作*/ GoodCartLogic goodCartLogic = new GoodCartLogic(); if (goodCartLogic.AddGoodCartInfo(goodCartInfoModel)) { Response.Write("<script>alert('商品销售信息添加成功!');location.href='SellGoods.aspx';</script>"); } else { Response.Write("<script>alert('" + goodCartLogic.ErrMessage + "');location.href='SellGoods.aspx';</script>"); } }
/*传入商品销售购物车信息模型对象,将商品销售信息加入到系统中*/ public bool AddGoodCartInfo(GoodCartInfoModel goodCartInfoModel) { /*进行相关的验证*/ if (goodCartInfoModel.GoodNo == "") { this.errMessage = "请输入商品编号信息!"; return(false); } string sqlString = "select * from [goodInfo] where goodNo='" + goodCartInfoModel.GoodNo + "'"; if (!DBOperation.ExecuteReader(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null).Read()) { this.errMessage = "你输入的商品编号信息不存在!"; return(false); } /*验证商品的库存是否够卖*/ sqlString = "select goodCount from [goodStockInfo] where goodNo='" + goodCartInfoModel.GoodNo + "'"; int goodCount = Convert.ToInt32(DBOperation.ExecuteScalar(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null)); if (goodCartInfoModel.GoodCount > goodCount) { this.errMessage = "你输入的商品销售数目超出了系统库存"; return(false); } /*将商品销售信息加入到购物车信息表中*/ sqlString = "insert into [goodCartInfo] (employeeNo,goodNo,goodCount) values ('"; sqlString += goodCartInfoModel.EmployeeNo + "','"; sqlString += goodCartInfoModel.GoodNo + "',"; sqlString += goodCartInfoModel.GoodCount + ")"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "将商品销售信息加入到购物车信息表时发生了错误!"; return(false); } sqlString = "update [goodStockInfo] set goodCount = goodCount -" + goodCartInfoModel.GoodCount + " where goodNo='" + goodCartInfoModel.GoodNo + "'"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "添加商品销售信息修改商品库存失败!"; return(false); } return(true); }