簡體   English   中英

沒有語法錯誤,但程序不產生任何結果

[英]No syntax errors, but program does not produce any results

我必須為 class 創建一個程序。 我的應用程序需要具有OilLubeCharges()FlushCharges()MiscCharges()OtherCharges()TaxCharges()TotalCharges()的值返回方法。

它需要有用於ClearOilLube()ClearFlushes()ClearMisc()ClearOther()ClearFees()的 void 方法。

目前我的代碼沒有語法錯誤,但是當我編譯它時它不會計算任何東西。 計算、清除和退出按鈕也不起作用。 任何有關為什么會出現這些問題的幫助將不勝感激。 下面是我的代碼。

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

如上面評論中所述,您的事件很可能沒有連接到您的按鈕。 您可以通過多種方式做到這一點; 通常它是在設計器中完成的。

要確定這是否是原因,請嘗試以下操作:

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

請注意,這假定您的按鈕名為“CalcButton”。 您也可以在設計器中看到這是否正確。

如果可行,您需要以相同的方式或通過在設計器中為按鈕選擇方法來對按鈕的 rest 執行相同的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM