2016-06-01 3 views
0

단추를 클릭 할 때 부울 함수를 삽입하거나 호출하고 싶습니다.버튼을 클릭 할 때 부울을 호출하는 방법

아마, 이것은 BOOL 인 :

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); 
} 

수량은 고객이 구입 한 제품의 수량에 해당합니다. 수량은 위험 수준보다 낮거나 같아야합니다.

내가 원하는 것은 추가 버튼을 클릭하면 부울이 실행된다는 것입니다. 수량이 위험 수준보다 낮거나 같으면 프로그램은 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 메서드에 전달할 값이 무엇인지 알지 못합니다. 따라서 실제로 전달되는 값을 변경해야합니다. –

관련 문제