-2
當我點擊'計算'按鈕時,'其他程序'和'安裝'文本框恢復爲0,'賬單'出現給定客戶類型的基本價格。我的代碼如下:C#計算程序 - 輸入文本框
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Bus432_Assignment2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
const double RES_HOME = 99;
const double RES_HOME_ADD = 49;
const double ENT_ADD_PRO = 10;
const double ENT_BASIC = 249;
const double ENT_PER_PRO = 99;
const double ENT_ADD_INSTALL_CHARGE = .10;
const double UNLIM_BASIC = 999;
char customerType;
double addpro = 0;
double install = 0;
double bill = 0;
// Check to make sure type has been entered.
if (txtCustomerType.Text == "")
{
MessageBox.Show("Customer type is required.",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCustomerType.Focus();
return;
}
// Get customer type
customerType = char.Parse(txtCustomerType.Text);
customerType = char.ToUpper(customerType);
txtCustomerType.Text = customerType.ToString();
// Check customer type, programs, installations
txtInstall.Text = install.ToString();
txtAddPro.Text = addpro.ToString();
if (customerType == 'H' || customerType == 'E')
{
if (txtInstall.Text == "")
{
MessageBox.Show("For home use customer plan, enter installations",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
if (txtInstall.Text == "")
{
txtInstall.Focus();
}
return;
}
}
else if (customerType == 'E' || customerType == 'H')
{
if (txtAddPro.Text == "")
{
MessageBox.Show("For enterprise or home use customer, enter additional programs",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
if (txtAddPro.Text == "")
{
txtAddPro.Focus();
}
return;
}
else if (customerType != 'E' || customerType != 'H' || customerType != 'U')
{
MessageBox.Show("Customer type must be E, H, or U.",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
//txtInstall.Focus();
return;
}
// Get Additional Programs and installations
addpro = double.Parse(txtAddPro.Text);
install = double.Parse(txtInstall.Text);
if (addpro < 0)
{
MessageBox.Show("Number of additional programs must not be negative.",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAddPro.Focus();
return;
}
else if (install < 0)
{
MessageBox.Show("Number of installations must not be negative.",
Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtInstall.Focus();
return;
}
}
// Calculate Bill
switch(customerType)
{
case 'H':
bill = RES_HOME + addpro * RES_HOME_ADD;
break;
case 'E':
bill = ENT_BASIC + addpro * ENT_PER_PRO *(1+ENT_ADD_INSTALL_CHARGE*(install-ENT_ADD_PRO));
break;
case 'U':
bill = UNLIM_BASIC;
break;
}
// Display the result.
txtBill.Text = bill.ToString("C");
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
幫助* what *? –
當我點擊計算「附加程序」和「安裝」時,如果輸入不同的數字,則轉到0 – MSmits23