0

我正在尝试创建站点的克隆:http: //aspnet.cob.ohio.edu/mis3200/asppub/MIS3200/Unit4/bobcat4POS.aspx

在单选按钮列表上选择“是”后,难以在标签中显示项目以及显示复选框列表。

protected void Page_Load(object sender, EventArgs e)
{
   // 
   // when the page loads,
   // (1) do not allow the chekout button to be visible
   // (2) Set Focus to Number of Movies Textbox
   //

   SetFocus(txtMovies);
   btnCheckOut.Enabled = false;

}
   protected void btnSubmit_Click(object sender, EventArgs e)
    {


    decimal decNum1 = 0m;
    decimal decNum2 = 0M;
    decimal decNum3 = 0M;
    decimal decSum = 0M;
    decimal decProduct = 0M;

    decNum1 = Convert.ToInt32(txtMovies.Text);
    decNum2 = Convert.ToDecimal(txtPrice.Text);
    decNum3 = Convert.ToInt32(lblNumMovies.Text);
    decSum = decNum1 + decNum3;
    decProduct = decNum1 * decNum2;

    lblNumMovies.Text = decSum.ToString();

    lblPrice.Text = (decProduct + Convert.ToDecimal(lblPrice.Text)).ToString();

    txtMovies.Text = "";
    txtPrice.Text = "";

    btnCheckOut.Visible = true;
    btnCheckOut.Enabled = true;


    }
   protected void rblSnacks_SelectedIndexChanged(object sender, EventArgs e)
   {
       string strSnacks = Convert.ToString(rblSnacks.SelectedItem); // stores if customer selects "yes" or "no"

       if (rblSnacks.SelectedIndex == 0)
       {
           cblSnacks.Visible = true;
       }
       else
       {
           cblSnacks.Visible = false;
       }

   }
protected void btnCheckOut_Click(object sender, EventArgs e)
{
    string strMovies; // add local variable for type string
    int intNumMovies = Convert.ToInt32(txtMovies.Text); // adding ability for characters text box to be seen as a number
    decimal decDiscountRate = 0.1M; // establish discount rate (10%)
    decimal decDiscount; // local variable to calculate discount
    decimal decTaxRate = 0.0725M;
    decimal decSalesTax;
    decimal decAmountDue;
    decimal decSubtotal = 0M;
    decimal decSnackFees = 0M; // decimal variable for storing the snack fees selected in cbl
    string strSnacks = Convert.ToString(rblSnacks.SelectedItem); // stores if customer selects "yes" or "no"
    decimal decAccumTotalPrice = 0M; // decimal variable for the accumulated total price for snacks and movies

    if (cblSnacks.Items[0].Selected) // if popcorn is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[0].Value);
    }
    if (cblSnacks.Items[1].Selected) // if skittles is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[1].Value);
    }
    if (cblSnacks.Items[2].Selected) // if nestle crunch is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[2].Value);
    }
    if (cblSnacks.Items[3].Selected) // if twix is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[3].Value);
    }
    if (cblSnacks.Items[4].Selected) // if snickers is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[4].Value);
    }
    if (cblSnacks.Items[5].Selected) // if twizzlers is selected
    {
        decSnackFees = decSnackFees + Convert.ToDecimal(cblSnacks.Items[5].Value);
    }

    decAccumTotalPrice = decSubtotal + decSnackFees;

    decSubtotal = Convert.ToDecimal(lblPrice.Text);
    decSalesTax = decAccumTotalPrice * decTaxRate;
    decDiscount = decAccumTotalPrice * decDiscountRate;  
    decAmountDue = decAccumTotalPrice + decSalesTax; 

    lblInvoice.Visible = true;

    if (intNumMovies == 1) // if statement for if accumulated quantity in txtMovies text box is greater than 1
    {
        strMovies = "Movie"; // using the pluaral form of "movie"
    }
    else
    {
        strMovies = "Movies";
    }

    if (intNumMovies > 5 && rblSnacks.SelectedValue == "no") // applying the discount in the invoice label but "no" is selected in the rbl -> no snacks are selected
    {
        decAmountDue = decAccumTotalPrice - decDiscount + decSalesTax;

        lblNumMovies.Text = txtMovies.Text; // label will display number in the txtMovies text box

        lblInvoice.Text = "Your order total is: " + "<br/>"; // Modifying output of invoice label for correct grammar ( >1, <5)
        lblInvoice.Text += lblNumMovies.Text + " " + strMovies + " for " + decSubtotal.ToString("C2") + "<br/>";
        lblInvoice.Text += "sales tax = " + decSalesTax.ToString("C2") + "<br/>";
        lblInvoice.Text += "discount = " + "(" + decDiscount.ToString("C2") + ")" + "<br/>"; // displaying discounted fee for more than 5 movies ordered
        lblInvoice.Text += "total due = " + decAmountDue.ToString("C2");

    }

    else if (intNumMovies > 5 && rblSnacks.SelectedValue == "yes") // applying the discount in the invoice label but "yes" is selected in the rbl -> snacks are selected and added onto the total
    {
        decAmountDue = decAccumTotalPrice - decDiscount + decSalesTax;

        lblNumMovies.Text = txtMovies.Text; // label will display number in the txtMovies text box

        lblInvoice.Text = "Your order total is: " + "<br/>"; // Modifying output of invoice label for correct grammar ( >1, <5)
        lblInvoice.Text += lblNumMovies.Text + " " + strMovies + " for " + decSubtotal.ToString("C2") + "<br/>";
        lblInvoice.Text += "snacks = " + cblSnacks.SelectedItem;
        lblInvoice.Text += "sales tax = " + decSalesTax.ToString("C2") + "<br/>";
        lblInvoice.Text += "discount = " + "(" + decDiscount.ToString("C2") + ")" + "<br/>"; // displaying discounted fee for more than 5 movies ordered
        lblInvoice.Text += "total due = " + decAmountDue.ToString("C2");
    }

    else if (intNumMovies > 0 && intNumMovies < 5 && rblSnacks.SelectedValue == "yes") // not applying the discount in the invoice label but "yes" is selected in the rbl -> snacks are selected and added onto the non-discounted total
    {
        decAmountDue = decAccumTotalPrice + decSalesTax;

        lblNumMovies.Text = txtMovies.Text; // label will display number in the txtMovies text box

        lblInvoice.Text = "Your order total is: " + "<br/>"; // Modifying output of invoice label for correct grammar
        lblInvoice.Text += lblNumMovies.Text + " " + strMovies + " for " + decSubtotal.ToString("C2") + "<br/>";
        lblInvoice.Text += "snacks = " + cblSnacks.SelectedItem;
        lblInvoice.Text += "sales tax = " + decSalesTax.ToString("C2") + "<br/>";
        lblInvoice.Text += "total due = " + decAmountDue.ToString("C2");
    }
    else if (intNumMovies > 0 && intNumMovies < 5 && rblSnacks.SelectedValue == "no") // not applying the discount in the invoice label but "no" is selected in the rbl -> no discount is applied and no snacks are added onto the total
    {
        decAmountDue = decAccumTotalPrice + decSalesTax;

        lblNumMovies.Text = txtMovies.Text; // label will display number in the txtMovies text box

        lblInvoice.Text = "Your order total is: " + "<br/>"; // Modifying output of invoice label for correct grammar
        lblInvoice.Text += lblNumMovies.Text + " " + strMovies + " for " + decSubtotal.ToString("C2") + "<br/>";
        lblInvoice.Text += "sales tax = " + decSalesTax.ToString("C2") + "<br/>";
        lblInvoice.Text += "total due = " + decAmountDue.ToString("C2");
    }
4

1 回答 1

0

您是否绝对确定 rblSnacks.SelectedValue 确实是文本而不是值(即“是”而不是“0”)?

我会冒险猜测 rblSnacks.SelectedItem.Text 是您应该评估的对象。解决这个问题的另一种方法是rblSnacks.Items.FindByText("yes").selected == true.

于 2013-10-01T02:31:35.927 回答