/*传入商品进货信息模型对象,实现商品进货信息的加入操作*/ public bool AddBuyInfo(BuyInfoModel buyInfoModel) { /*首先验证管理员输入的商品编号在系统中是否存在*/ string sqlString = "select * from [goodInfo] where goodNo='" + buyInfoModel.GoodNo + "'"; if (!DBOperation.ExecuteReader(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null).Read()) { this.errMessage = "你输入的商品不存在!"; return(false); } /*构造sql语句实现进货信息的加入操作*/ sqlString = "insert into [buyInfo] (goodNo,supplierName,price,number,totalPrice,buyDate,addTime) values ('"; sqlString += buyInfoModel.GoodNo + "','"; sqlString += buyInfoModel.SupplierName + "',"; sqlString += buyInfoModel.Price + ","; sqlString += buyInfoModel.Number + ","; sqlString += buyInfoModel.TotalPrice + ",'"; sqlString += buyInfoModel.BuyDate + "','"; sqlString += buyInfoModel.AddTime + "')"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "添加商品进货信息时发生了错误!"; return(false); } /*增加对应商品的库存*/ sqlString = "update [goodStockInfo] set goodCount = goodCount + " + buyInfoModel.Number + " where goodNo='" + buyInfoModel.GoodNo + "'"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "登记进货时修改商品库存失败!"; return(false); } return(true); }
protected void Btn_Add_Click(object sender, EventArgs e) { if (this.BuyDate.Text == "") { Response.Write("<script>alert('请选择进货日期!');</script>"); return; } /*建立进货信息模型并取得各个信息*/ BuyInfoModel buyInfoModel = new BuyInfoModel(); buyInfoModel.SupplierName = this.SupplierName.Text; buyInfoModel.GoodNo = this.GoodNo.Text; buyInfoModel.Price = Convert.ToSingle(this.Price.Text); buyInfoModel.Number = Int32.Parse(this.Number.Text); buyInfoModel.TotalPrice = buyInfoModel.Price * buyInfoModel.Number; buyInfoModel.BuyDate = Convert.ToDateTime(this.BuyDate.Text).Date; buyInfoModel.AddTime = DateTime.Now; /*调用业务层实现进货信息的登记*/ BuyInfoLogic buyInfoLogic = new BuyInfoLogic(); if (buyInfoLogic.AddBuyInfo(buyInfoModel)) { Response.Write("<script>alert('商品进货信息登记成功!');location.href='BuyInfoAdd.aspx'</script>"); } else { Response.Write("<script>alert('" + buyInfoLogic.ErrMessage + "');</script>"); } }