/*传入商品退货信息模型对象,实现顾客退货的业务操作*/ public bool SellBackInfoAdd(SellBackInfoModel sellBackInfoModel, bool isGood) { /*查询销售信息表中是否存在该销售单据号*/ string sqlString = "select COUNT(*) from [sellInfo] where sellNo='" + sellBackInfoModel.SellNo + "'"; int count = Convert.ToInt32(DBOperation.ExecuteScalar(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null)); if (count == 0) { this.errMessage = "你输入的销售单据号不存在!"; return(false); } /*判断该次销售中是否存在该商品的信息*/ sqlString = "select COUNT(*) from [sellInfo] where sellNo='" + sellBackInfoModel.SellNo + "' and goodNo='" + sellBackInfoModel.GoodNo + "'"; count = Convert.ToInt32(DBOperation.ExecuteScalar(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null)); if (0 == count) { this.errMessage = "该次销售没有该商品的信息!"; return(false); } /*判断退货的商品数量是否正确*/ sqlString = "select number from [sellInfo] where sellNo='" + sellBackInfoModel.SellNo + "' and goodNo='" + sellBackInfoModel.GoodNo + "'"; int number = Convert.ToInt32(DBOperation.ExecuteScalar(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null)); if (sellBackInfoModel.Number > number) { this.errMessage = "你的退货数量不能大于销售时的数量!"; return(false); } /*通过验证后执行商品退货信息的加入*/ sqlString = "insert into [sellBackInfo] (sellNo,goodNo,price,number,totalPrice,sellBackReason,sellBackTime) values ('"; sqlString += sellBackInfoModel.SellNo + "','"; sqlString += sellBackInfoModel.GoodNo + "',"; sqlString += sellBackInfoModel.Price + ","; sqlString += sellBackInfoModel.Number + ","; sqlString += sellBackInfoModel.TotalPrice + ",'"; sqlString += sellBackInfoModel.SellBackReason + "','"; sqlString += sellBackInfoModel.SellBackTime + "')"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "添加商品退货信息时发生了错误!"; return(false); } /*如果退回的商品是完好的,需要将商品入库*/ if (isGood) { sqlString = "update [goodStockInfo] set goodCount = goodCount + " + sellBackInfoModel.Number;; 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) { SellBackInfoModel sellBackInfoModel = new SellBackInfoModel(); sellBackInfoModel.SellNo = this.SellNo.Text; sellBackInfoModel.GoodNo = this.GoodNo.Text; if (this.Price.Text == "" || this.Number.Text == "") { Response.Write("<script>商品价格或数量信息输入不能为空!</script>"); } try { sellBackInfoModel.Price = Convert.ToSingle(this.Price.Text); } catch { Response.Write("<script>alert('请输入正确的价格信息!');</script>"); return; } try { sellBackInfoModel.Number = Int32.Parse(this.Number.Text); } catch { Response.Write("alert('请输入正确的商品数量!');"); } sellBackInfoModel.TotalPrice = sellBackInfoModel.Price * sellBackInfoModel.Number; sellBackInfoModel.SellBackReason = this.SellBackReason.Text; sellBackInfoModel.SellBackTime = DateTime.Now; bool isGood = (Int32.Parse(this.IsGood.SelectedValue) == 1)?true:false; SellBackLogic sellBackLogic = new SellBackLogic(); if (sellBackLogic.SellBackInfoAdd(sellBackInfoModel, isGood)) { Response.Write("<script>alert('商品退货成功!');location.href='SellBackInfoAdd.aspx';</script>"); } else { Response.Write("<script>alert('" + sellBackLogic.ErrMessage + "');</script>"); } }