public partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
string customerType = txtCustomerType.Text;
decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);
decimal discountPercent = .0m;
switch (customerType)
{
case "R":
if (subtotal < 100)
discountPercent = .0m;
else if (subtotal >= 100 && subtotal < 250)
discountPercent = .1m;
else if (subtotal >= 250 && subtotal < 500)
discountPercent = .25m;
else if (subtotal >= 500)
discountPercent = .30m;
break;
case "C":
discountPercent = .2m;
break;
case "T":
if (subtotal < 500)
discountPercent = .4m;
else if (subtotal >= 500)
discountPercent = .5m;
break;
default:
discountPercent = .1m;
break;
}
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");
txtCustomerType.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
int i = 0;
string summaryString = txtTotal.Text;
for (i = 0; i < 5; i++)
summaryString += Environment.NewLine;
MessageBox.Show(summaryString, "Order Totals");
this.Close();
}
}
ユーザーが計算ボタンを押すと、請求書の合計が計算されます。私がする必要があるのは、前の 5 つの合計値を保存し、それらを新しい行のメッセージ ボックスに次々と表示することだけです。ユーザーが終了ボタンをクリックすると、このメッセージ ボックスが表示されます。