المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Method not calculating properly‏



C# Programming
10-02-2009, 05:12 AM
Hi, I'm creating an asp.net Pizza order form using c# for a night school course and I have a RadioButtonList for the Size of the pizza and a checkbox list for the Pizza Toppings. Both controls have autopostback enabled so that as a size is selected and a topping is added the Total Price label will automatically calculate the total price and size is selected and toppings added. I have a simple method that adds the ingredients price to the size price as selctions are made. The problem is that the value of the Total Price changes as selections are made to the size (2,4,6,8,10) but if a topping is selected then the value of the total price doesn't add the size price to the toppings price they are still calculated individually, can someone tell from my code how i can write and use my method to total the size price with the topping price? thanks in advance.

public partial class _Default : System.Web.UI.Page
{
decimal TotalPrice = 0;
decimal IngredientsPrice = 0;
decimal SizePrice = 0;

private decimal MethodTotalPrice(decimal MethodIngredientsPrice,
decimal MethodSizePrice)
{
decimal MethodTotalPrice;
MethodTotalPrice = MethodIngredientsPrice + MethodSizePrice;
return MethodTotalPrice;
}

protected void Page_Load(object sender, EventArgs e)
{

}
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
lblSize.Text = rblSize.SelectedItem.Text;

if (rblSize.SelectedValue == "Slice")
{
lblSize.Font.Size = 8;
SizePrice = 2;
}
if (rblSize.SelectedValue == "Small")
{
lblSize.Font.Size = 10;
SizePrice = 4;
}
if (rblSize.SelectedValue == "Medium")
{
lblSize.Font.Size = 12;
SizePrice = SizePrice + 6;
}
if (rblSize.SelectedValue == "Large")
{
lblSize.Font.Size = 14;
SizePrice = 8;
}
if (rblSize.SelectedValue == "Xtra Large")
{
lblSize.Font.Size = 16;
SizePrice = 10;
}
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);
lblPriceTotal.Text = TotalPrice.ToString();
}
protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)
{
string Message;
Message = "";
for (int i = 0; i < cblIngredients.Items.Count; i++)
{
if (cblIngredients.Items[i].Selected)
{
Message = Message + cblIngredients.Items[i].Text + "
";
IngredientsPrice = IngredientsPrice + 1;
}
}
lblIngredients.Text = Convert.ToString(Message);
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);
lblPriceTotal.Text = TotalPrice.ToString();
}
}