2016-06-01 4 views
0

ボタンをクリックするとブール関数を挿入したり呼び出したりしたいと思います。ボタンのクリックでブールを呼び出す方法

たぶん、これはブール値です:

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 [email protected]"; 
    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); 
} 

数量は、お客様が購入した1製品の量に相当します。 数量はクリティカルレベル以下である必要があります。

私がしたいことは、[追加]ボタンをクリックするとブールが実行されることです。数量がクリティカルレベル以下の場合、プログラムはAdd_Clickイベントの "Response.Redirect"を続行する必要があります。そうでない場合は、クリティカルレベルに達したことを示すエラーメッセージが表示されます。

答えて

0

はこの試してみてください。助けを

protected void btnAdd_Click(object sender, EventArgs e) 
{ 
    //Change ProductID, Quantity, Available, Criticallevel to actual values 
    if (!IsCritical(ProductID, Quantity, Available, Criticallevel)) 
    { 
     Response.Redirect("~/Account/AddToCart.aspx?ID=" + 
     Request.QueryString["ID"].ToString() + 
     "&qty=" + txtQty.Text); 
    } 
    else 
    { 
     //Write error message here 
    } 
} 
+0

感謝:) をしかし、私はあなたが「実際の値」によって何を意味するか知っているかもしれませんか? – Izelblade

+0

私はIsCriticalメソッドのために渡している値が何であるか分かりません。そのため、実際に渡している値に変更する必要があります。 –

関連する問題