简体   繁体   中英

No syntax errors, but program does not produce any results

I have to create a program for class. My applications needs to have value returning methods for OilLubeCharges() , FlushCharges() , MiscCharges() , OtherCharges() , TaxCharges() , TotalCharges() .

It needs to have void methods for ClearOilLube() , ClearFlushes() , ClearMisc() , ClearOther() , ClearFees() .

Currently my code has no syntax errors, however when I compile it it does not calculate anything. The calculate, clear, and exit buttons also do not work. Any assistance as to why these issues are occurring would be appreciated. Below is my code.

public partial class Form1 : Form
{
    public Form1() 
    {
        InitializeComponent();
    }

    private void CalcButton_Click(object sender, EventArgs e)
    {
        OilLubeCharges();
        FlushCharges();
        MiscCharges();
        OtherCharges();
        TaxCharges();
        TotalCharges();
    }

    private void ClearButton_Click(object sender, EventArgs e)
    {
        oilCheckBox.Checked = false;
        lubeCheckBox.Checked = false;
        radFlushBox.Checked = false;
        tranFlushBox.Checked = false;
        insCheckBox.Checked = false;
        mufCheckBox.Checked = false;
        tireCheckBox.Checked = false;
        partsTextBox.Text = "";
        laborTextBox.Text = "";
        serLabTotalTextBox.Text = "";
        partsTotalTextBox.Text = "";
        taxPartsTextBox.Text = "";
        totalFeesTextBox.Text = "";
    }

    private void ExitButton_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private int OilLubeCharges()
    {
        int total = 0;

        if (oilCheckBox.Checked)
        {
            total += 26;
            serLabTotalTextBox.Text = total.ToString("c");
        }

        if (lubeCheckBox.Checked)
        {
            total += 18;
            serLabTotalTextBox.Text = total.ToString("c");
            return total;
        }
        else
        {
            return total;
        }
    }

    private int FlushCharges()
    {
        int total = 0;

        if (radFlushBox.Checked)
        {
            total += 30;
            serLabTotalTextBox.Text = total.ToString("c");
        }

        if (tranFlushBox.Checked)
        {
            total += 80;
            serLabTotalTextBox.Text = total.ToString("c");
            return total;
        }
        else
        {
            return total;
        }
    }

    private int MiscCharges()
    {
        int total = 0;

        if (insCheckBox.Checked)
        {
            total += 15;
            serLabTotalTextBox.Text = total.ToString("c");
        }

        if (mufCheckBox.Checked)
        {
            total += 100;
            serLabTotalTextBox.Text = total.ToString("c");
        }

        if (tireCheckBox.Checked)
        {
            total += 20;
            serLabTotalTextBox.Text = total.ToString("c");
            return total;
        }
        else
        {
            return total;
        }
    }

    private int OtherCharges()
    {
        int total = 0;
        int parts = 0;
        int labor = 0;

        if (int.TryParse(partsTextBox.Text, out parts))
        {
            partsTextBox.Text = parts.ToString("c");
            total = parts;
        }

        if (int.TryParse(laborTextBox.Text, out labor))
        {
            laborTextBox.Text = labor.ToString("c");
            return total;
        }
        else
        {
            return total;
        }
    }

    private decimal TaxCharges()
    {
        decimal parts = 0;
        decimal partsTax;

        partsTax = parts * .06m;
        taxPartsTextBox.Text = partsTax.ToString("c");
        return partsTax;
    }

    private decimal TotalCharges()
    {
        decimal total = 0;

        total = OilLubeCharges() + FlushCharges() + MiscCharges() + TaxCharges() + OtherCharges();
        totalFeesTextBox.Text = total.ToString("c");
        return total;
    }
}

As stated in the comments above, most likely your events are not hooked up to your buttons. You can do this several ways; typically it's done in the designer.

To know for sure if this is the cause, try this:

public Form1() 
{
    InitializeComponent();
    CalcButton.Click += CalcButton_Click;
}

Note that this assumes your button is named "CalcButton". You can see whether that's true in the designer as well.

If that works, you need to do the same with the rest of your buttons either the same way or by selecting the method in the designer for the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM