protected void Btn_Add_Click(object sender, EventArgs e) { HuaJiaCartModel huaJiaCartModel = new HuaJiaCartModel(); huaJiaCartModel.setUsername(Session["username"].ToString()); int medicineId = Int32.Parse(this.MedicineId.SelectedValue); huaJiaCartModel.setMedicineId(medicineId); float price = MedicineLogic.getPriceById(medicineId); huaJiaCartModel.setPrice(price); int count = Int32.Parse(this.Count.Text); huaJiaCartModel.setCount(count); float totalPrice = price * count; huaJiaCartModel.setTotalPrice(totalPrice); HuaJiaCartLogic huaJiaCartLogic = new HuaJiaCartLogic(); if (huaJiaCartLogic.AddHuaJiaCartInfo(huaJiaCartModel)) { Response.Write("<script>alert('药品划价销售信息添加成功!');location.href='HuaJiaAdd.aspx';</script>"); } else { Response.Write("<script>alert('" + huaJiaCartLogic.getErrMessage() + "');location.href='HuaJiaAdd.aspx';</script>"); } }
public bool AddHuaJiaCartInfo(HuaJiaCartModel huaJiaCartModel) { string sqlString = "select stockCount from [t_medicine] where medicineId=" + huaJiaCartModel.getMedicineId(); int leftStockCount = 0; DataBase db = new DataBase(); DataSet ds = db.GetDataSet(sqlString); if (ds.Tables[0].Rows.Count > 0) { leftStockCount = Convert.ToInt32(ds.Tables[0].Rows[0]["stockCount"]); } if (huaJiaCartModel.getCount() > leftStockCount) { this.errMessage = "你输入的药品销售数目超出了系统库存!"; return(false); } string insert_cart_string = "insert into [t_huajia_cart] (username,medicineId,price,count,totalPrice) values ("; insert_cart_string += SqlString.GetQuotedString(huaJiaCartModel.getUsername()) + ","; insert_cart_string += huaJiaCartModel.getMedicineId() + ","; insert_cart_string += huaJiaCartModel.getPrice() + ","; insert_cart_string += huaJiaCartModel.getCount() + ","; insert_cart_string += huaJiaCartModel.getTotalPrice() + ")"; string update_medicine_string = "update [t_medicine] set stockCount = stockCount -" + huaJiaCartModel.getCount() + " where medicineId=" + huaJiaCartModel.getMedicineId(); string[] sqlStrings = new string[2] { insert_cart_string, update_medicine_string }; if (!db.ExecuteSQL(sqlStrings)) { this.errMessage = "添加药品销售信息时发生了错误!"; return(false); } return(true); }