Visual C# 注册系统错误输入无效
本文关键字:输入 无效 系统错误 注册 Visual | 更新日期: 2023-09-27 18:34:08
我们被要求使用 Visual C# 制作一个注册程序,我想出了代码,但我认为每当我输入单位数时它总是提示"无效输入",即使我输入超过 9 个单位,因为我们的教授说单位不得小于 9。 这是我制作的代码
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 MachineProblem2
{
public partial class frmEnrollment : Form
{
public frmEnrollment()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
rdbInstallment.Checked = true;
rdbRegular.Checked = true;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnCompute_Click(object sender, EventArgs e)
{
int units = Convert.ToInt32(txtUnits.Text);
int tuitionfee = 1250;
double miscfee = .15;
int labfee = 750;
//double scholar = 0;
//double fullpayment = 0;
//double installment = .005;
int totalTuition = 0;
double totalMiscFee = 0;
int totalLabFee = 0;
int totalDiscount = 0;
int computeModePayment = 0;
int computeScholarDiscount = 0;
int scholarDiscount = 80;
int fullpaymentDiscount = 5;
double modeOfPayment = 0;
double status = 0;
double convertedDiscount = 0;
double total = 0;
double installment = 0;
if (txtUnits.Text == "")
{
MessageBox.Show("Input a number", "Input", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
if (units < 9)
{
MessageBox.Show("Error Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUnits.Clear();
txtUnits.Focus();
}
else
totalLabFee = units * labfee;
txtLabFee.Text = totalLabFee.ToString("C");
totalTuition = units * tuitionfee;
txtTuitionFee.Text = totalTuition.ToString("C");
totalMiscFee = totalTuition * miscfee;
txtMiscFee.Text = totalMiscFee.ToString("C");
totalLabFee = units * labfee;
txtLabFee.Text = totalLabFee.ToString("C");
if (rdbFull.Checked)
{
computeModePayment = fullpaymentDiscount;
}
else
computeModePayment = 0;
if (rdbScholar.Checked)
{
computeScholarDiscount = scholarDiscount;
}
else
computeScholarDiscount = 0;
totalDiscount = computeModePayment + computeScholarDiscount;
txtDiscount.Text = totalDiscount.ToString();
if (rdbFull.Checked)
{
modeOfPayment = totalTuition * 0.05;
}
else
modeOfPayment = 0;
if (rdbScholar.Checked)
{
status = totalTuition * .8;
}
else
status = 0;
convertedDiscount = modeOfPayment + status;
// txtConvertedDiscount.Text = convertedDiscount.ToString("C");
if (rdbInstallment.Checked)
{
installment = totalTuition * .005;
total = (totalTuition + totalLabFee + totalMiscFee - convertedDiscount) + installment;
txtTotal.Text = total.ToString("C");
}
else
total = totalTuition + totalLabFee + totalMiscFee - convertedDiscount;
txtTotal.Text = total.ToString("C");
}
private void btnClear_Click(object sender, EventArgs e)
{
txtUnits.Clear();
txtTuitionFee.Clear();
txtMiscFee.Clear();
txtLabFee.Clear();
txtDiscount.Clear();
txtTotal.Clear();
// txtConvertedDiscount.Clear();
txtUnits.Focus();
rdbFull.Checked = false;
rdbInstallment.Checked = false;
rdbRegular.Checked = false;
rdbScholar.Checked = false;
}
private void btnExit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to exit?", "Exit Application",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
}
Close();
}
}
}
这是我们教授的指示,希望你能帮助我
*单位不得少于9*学费按每学分1250计算*杂项费用按每件商品 1250 计算*实验室费用按每单位 750 计算* 学者80%折扣*全额付款可享受5%的折扣*分期付款收取0.5%的费用
尝试
int units = Convert.ToInt32(txtUnits.Text).Trim();