【发布时间】:2016-06-01 03:05:34
【问题描述】:
我想在单击按钮时插入或调用布尔函数。
据说,这是布尔:
private bool IsCritical(int ProductID, int Quantity, int Available, int Criticallevel){
bool existing = true;
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT Products.CriticalLevel, Products.Available, OrderDetails.Quantity FROM Products, OrderDetails WHERE ProductID=@ProductID";
cmd.Parameters.AddWithValue("@productid", ProductID);
cmd.Parameters.AddWithValue("@productid",ProductID);
SqlDataReader dr = cmd.ExecuteReader();
if(Available < Quantity)
{
return false;
}
else
{
int currentQty = Available - Quantity;
if(currentQty >= Criticallevel)
{
return false;
}
else return true;
}
cn.Close();
return existing;
}
但我找不到调用它的方法。
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("~/Account/AddToCart.aspx?ID=" +
Request.QueryString["ID"].ToString() +
"&qty=" + txtQty.Text);
}
数量对应于客户购买的一种产品的数量。 数量应低于或等于临界水平。
我想要发生的是,当我单击“添加”按钮时,布尔值将运行。如果 Quantity 低于或等于临界水平,则程序应继续 Add_Click 事件中的“Response.Redirect”。如果不是,则应显示一条错误消息,表明已达到临界级别。
【问题讨论】: