Answered Radio buttons and check boxes with math

jag250

Active member
Joined
Sep 16, 2020
Messages
28
Programming Experience
1-3
http://miscapstone.uncw.edu/316f20matthewsk/MIS316/MP1Bmatthewsk.aspx
This is the project I have to build
I have created the online of the page and 3/4 panels are functioning and my textboxes are good to go.
I need help trying to get the math portion done and the radio and checkbox buttons. if you check the sample site you can see what parts I am missing. I am going to continue doing what I can, but help or a general outline of what I am missing would be greatly appreciated.
Screenshot 2020-09-16 14.01.55.png

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    //input variable
    string name = "";
    int numbagels = 0;

    //variables to labels
    name = txtName.Text;
    numbagels = Convert.ToInt32(txtNumofBagels.Text);

    lblOrderFor.Text = name;
    lblNumberofBagels.Text = numbagels.ToString();

    if (rbCarryOut.Checked == true)
    {
        lblOrderType.Text = "Carry Out";
        lblChargeTax.Text = "No";
    }
    else
    {
        lblOrderType.Text = "Dine In";
        lblChargeTax.Text = "Yes";
    }
    pnlCustomer.Visible = false;
    pnlDineorCarry.Visible = true;
}


protected void btnFinishOrder_Click(object sender, EventArgs e)
{
    pnlDineorCarry.Visible = false;
    pnlFinishOrder.Visible = true;

    //input variable
    string name = "";
    int numbagels = 0;

    name = txtName.Text;
    numbagels = Convert.ToInt32(txtNumofBagels.Text);
 
Last edited by a moderator:
I know the OP's original question is regarding WebForms, but I figured this was a great opportunity to give Blazor a test drive:


C#:
@page "/"

<h1>Bagel Store</h1>
<div>
    <label for="txtBagelCount">Number of Bagels: </label>
    <input id="txtBagelCount" @bind="BagelCount" @bind:event="oninput" />
</div>
<div id="divBagelKind">
    <label for="divBagelKind">Kind of Bagel: </label>
    <input type="radio" name="rbgBagelKind" value="Plain" id="rdbPlain" @onchange="OnChangeKind" checked />
    <label for="rdbPlain">Plain</label>
    <input type="radio" name="rbgBagelKind" value="Wheat" id="rdbWheat" @onchange="OnChangeKind" />
    <label for="rdbWheat">Wheat</label>
    <input type="radio" name="rbgBagelKind" value="Everything" id="rdbEverything" @onchange="OnChangeKind" />
    <label for="rdbEverything">Everything</label>
</div>
<div id="divOptions">
    <label for="divOptions">Options: </label>
    <input type="checkbox" id="chkToasted" @bind="IsToasted" />
    <label for="chkToasted">Toasted</label>
    <input type="checkbox" id="chkCreamCheese" @bind="IsCreamCheese" />
    <label for="chkCreamCheese">Cream Cheese</label>
</div>
<div id="divDineIn">
    <input type="checkbox" id="chkDineIn" @bind="IsDineIn" />
    <label for="chkDineIn">Dine In</label>
</div>
<div>
    <label>Tax: @subTotal.ToString("C")</label>
</div>
<div>
    <label>Tax: @tax.ToString("C")</label>
</div>
<div>
    <label>Total Cost: @totalCost.ToString("C")</label>
</div>

@code
{
    int _bagelCount = 0;
    int BagelCount { get => _bagelCount; set { _bagelCount = value; Recompute(); } }
    string _bagelKind;
    string BagelKind { get => _bagelKind; set { _bagelKind = value; Recompute(); } }
    bool _isToasted;
    bool IsToasted { get => _isToasted; set { _isToasted = value; Recompute(); } }
    bool _isCreamCheese;
    bool IsCreamCheese { get => _isCreamCheese; set { _isCreamCheese = value; Recompute(); } }
    bool _isDineIn;
    bool IsDineIn { get => _isDineIn; set { _isDineIn = value; Recompute(); } }

    decimal subTotal;
    decimal tax;
    decimal totalCost;

    void OnChangeKind(ChangeEventArgs e)
        => BagelKind = e.Value.ToString();

    void Recompute()
    {
        subTotal = 2.0m;
        switch (BagelKind)
        {
        case "Wheat":
            subTotal += 0.50m;
            break;
        case "Everything":
            subTotal += 1.50m;
            break;
        }

        if (IsToasted)
            subTotal += 0.50m;

        if (IsCreamCheese)
            subTotal += 1.0m;

        subTotal *= BagelCount;

        tax = 0;
        if (IsDineIn)
            tax = subTotal * 0.07m;

        totalCost = subTotal + tax;
    }
}

Pardon the lack of entry validation for the number of bagels -- it'll accept negative numbers. I just started going up the Blazor learning curve about 2 hours ago.
 
Yes, I blame you my evil twin. :cool:

Edit-Debug cycle is still too slow, and some more debugging tooling needed, but I'm willing to put up with it because I don't have to write any JavaScript.
 
And if you do write any sensitive data ie js, it's viewable in the inspector as you know, it's all downloaded if using wasm. be wary using bootstrap with it, as their are some kinks needing be ironed out.

The serverside is a bit different but has different set of limitations. No doubt you're having fun with it. ?
 
Just another tool to put into the toolbox. Probably not going to be my primary means of web development until it matures some more.
 
Yea same here for sure.

But it is a lot of fun to work with Blazor. I just don't think I want to use it on production sites personally.
 
Back
Top Bottom