-4

採用担当者から、ジュニア開発者としてのコーディングの仕事を与えられました。3つの選択肢があり、購入を計算する必要がある問題に行きました. 本、食品、医薬品を除き、すべての商品に 10% の税金が課せられることになっています。非課税であっても、輸入品には 5% の追加税がかかります。そこで、ユーザーがアイテムの名前を入力できるフォーム、輸入品か免税品かを示す 2 つのチェック ボックス、価格を入力するテキスト ボックス、および各入力用のテキスト ボックスを作成しました。その下には総売上税を計算するテキスト ボックスがあり、その下には合計のテキスト ボックスがあります。最初のチェックボックスの名前は「Item1Import」、次のチェックボックスの名前は「Item1Exempt」です。価格テキスト ボックスの名前は「Item1Price」、もう一方の名前は「Item1Output」です。

ここに私がこれまでに持っているコードがあります。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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


        private void Item1Price_TextChanged(object sender, EventArgs e)
            {
                if(Item1Exempt.Checked && Item1Import.Checked)
                {
                    Item1Output.Text = ((Convert.ToInt32(Item1Price.Text)) + (Convert.ToInt32(Item1Price.Text) * 0.05).ToString("C2"));
                }
                else if(Item1Exempt.Checked && !Item1Import.Checked)
                {
                    Item1Output.Text = (Convert.ToInt32(Item1Price.Text)).ToString("C2");
                }
                else if(!Item1Exempt.Checked && Item1Import.Checked)
                {
                    Item1Output.Text = ((Convert.ToInt32(Item1Price.Text) + (Convert.ToInt32(Item1Price.Text) * 0.1) + (Convert.ToInt32(Item1Price.Text) * 0.05)).ToString("C2"));
                }
                else
                {
                    Item1Output.Text = ((Convert.ToInt32(Item1Price.Text)) + (Convert.ToInt32(Item1Price.Text) * 0.1)).ToString("C2");
                }

            }

        private void Item2Price_TextChanged(object sender, EventArgs e)
            {
                if (Item2Exempt.Checked && Item2Import.Checked)
                {
                    Item2Output.Text = ((Convert.ToInt32(Item2Price.Text)) + (Convert.ToInt32(Item2Price.Text) * 0.05).ToString("C2"));
                }
                else if (Item2Exempt.Checked && !Item2Import.Checked)
                {
                    Item2Output.Text = (Convert.ToInt32(Item2Price.Text)).ToString("C2");
                }
                else if (!Item2Exempt.Checked && Item2Import.Checked)
                {
                    Item2Output.Text = ((Convert.ToInt32(Item2Price.Text) + (Convert.ToInt32(Item2Price.Text) * 0.1) + (Convert.ToInt32(Item2Price.Text) * 0.05)).ToString("C2"));
                }
                else
                {
                    Item2Output.Text = ((Convert.ToInt32(Item2Price.Text)) + (Convert.ToInt32(Item2Price.Text) * 0.1)).ToString("C2");
                }
            }

        private void Item3Price_TextChanged(object sender, EventArgs e)
            {
                if (Item3Exempt.Checked && Item3Import.Checked)
                {
                    Item3Output.Text = ((Convert.ToInt32(Item3Price.Text)) + (Convert.ToInt32(Item3Price.Text) * 0.05).ToString("C2"));
                }
                else if (Item3Exempt.Checked && !Item3Import.Checked)
                {
                    Item3Output.Text = (Convert.ToInt32(Item3Price.Text)).ToString("C2");
                }
                else if (!Item3Exempt.Checked && Item3Import.Checked)
                {
                    Item3Output.Text = ((Convert.ToInt32(Item3Price.Text) + (Convert.ToInt32(Item3Price.Text) * 0.1) + (Convert.ToInt32(Item3Price.Text) * 0.05)).ToString("C2"));
                }
                else
                {
                    Item3Output.Text = ((Convert.ToInt32(Item3Price.Text)) + (Convert.ToInt32(Item3Price.Text) * 0.1)).ToString("C2");
                }
            }

        private void Item4Price_TextChanged(object sender, EventArgs e)
            {
                if (Item4Exempt.Checked && Item4Import.Checked)
                {
                    Item4Output.Text = ((Convert.ToInt32(Item4Price.Text)) + (Convert.ToInt32(Item4Price.Text) * 0.05).ToString("C2"));
                }
                else if (Item4Exempt.Checked && !Item4Import.Checked)
                {
                    Item4Output.Text = (Convert.ToInt32(Item4Price.Text)).ToString("C2");
                }
                else if (!Item4Exempt.Checked && Item4Import.Checked)
                {
                    Item4Output.Text = ((Convert.ToInt32(Item4Price.Text) + (Convert.ToInt32(Item4Price.Text) * 0.1) + (Convert.ToInt32(Item4Price.Text) * 0.05)).ToString("C2"));
                }
                else
                {
                    Item4Output.Text = ((Convert.ToInt32(Item4Price.Text)) + (Convert.ToInt32(Item4Price.Text) * 0.1)).ToString("C2");
                }
            }

        private void SalesTax_TextChanged(object sender, EventArgs e)
            {
                SalesTax.Text = (((Convert.ToInt32(Item1Output.Text) - Convert.ToInt32(Item1Price.Text)) + ((Convert.ToInt32(Item2Output.Text) - Convert.ToInt32(Item2Price.Text)) + ((Convert.ToInt32(Item3Output.Text) - Convert.ToInt32(Item3Price.Text)) + ((Convert.ToInt32(Item4Output.Text) - Convert.ToInt32(Item4Price.Text)).ToString("C2"));
            }

        private void Total_TextChanged(object sender, EventArgs e)
            {
                Total.Text = ((Convert.ToInt32(Item1Output)) + (Convert.ToInt32(Item1Output)) + (Convert.ToInt32(Item1Output)) + (Convert.ToInt32(Item1Output)).ToString("C2"));
            }

    }
}

私が抱えている最初の問題は、Item1Price に入力するたびに Item1Output に出力されますが、他のものでは機能せず、「salestax」と「total」のテキスト ボックスにも何も表示されないことです。

2 番目の問題は、「O.OO」のような数字を入力できないことですが、「00」は入力でき、数字を削除するとクラッシュします。

どんな助けでも本当にありがたいです。前もって感謝します。

4

1 に答える 1