【发布时间】:2017-09-25 09:55:16
【问题描述】:
我正在构建一个表单,允许用户输入员工的姓名、工资率和支付期间的工作时间。将该信息输入三个文本框后,用户单击一个按钮,该按钮计算总工资、预扣社会保障、预扣医疗保险、预扣州税、预扣联邦税和净工资。此信息输出到标签。我希望用户能够输入多个员工,并将此信息添加到之前的输入中(如果第一个员工的总工资为 2,000.00 美元,第二个员工的总工资为 1,000 美元,则总工资为 3,000 美元,等等.) 我该怎么做呢?
当前代码:
public Employees()
{
InitializeComponent();
}
private void SubmitBtn_Click(object sender, EventArgs e)
{
String name;
decimal hours, payrate, grosspay;
Boolean error = false;
name = NameBox.Text;
if (NameBox.Text == string.Empty)
{
MessageBox.Show("You must enter a full name into the name textbox.");
error = true;
NameBox.Focus();
}
hours = decimal.Parse(HoursWorkedBox.Text);
payrate = decimal.Parse(HourRateBox.Text);
if (hours < 0 || payrate < 0)
{
MessageBox.Show("Cannot have negative hours/hourly rate.");
error = true;
HoursWorkedBox.Focus();
}
if (error == false)
{
decimal netpay, sswithheld, mcwithheld, statetaxwithheld, fedtaxwithheld;
grosspay = hours * payrate;
sswithheld = grosspay * .061m;
mcwithheld = grosspay * .0143m;
statetaxwithheld = 0;
fedtaxwithheld = 0;
if (grosspay > 0 && grosspay < 600)
{
statetaxwithheld = grosspay * .02m;
fedtaxwithheld = grosspay * .05m;
}
else if (grosspay >= 600 && grosspay < 1100)
{
statetaxwithheld = grosspay * .04m;
fedtaxwithheld = grosspay * .10m;
}
else if (grosspay >= 1100 && grosspay < 1600)
{
statetaxwithheld = grosspay * .06m;
fedtaxwithheld = grosspay * .15m;
}
else if (grosspay >= 1600 && grosspay < 2100)
{
statetaxwithheld = grosspay * .06m;
fedtaxwithheld = grosspay * .20m;
}
else if (grosspay >= 2100 && grosspay < 3100)
{
statetaxwithheld = grosspay * .06m;
fedtaxwithheld = grosspay * .25m;
}
else if (grosspay > 3100)
{
statetaxwithheld = grosspay * .06m;
fedtaxwithheld = grosspay * .30m;
}
netpay = grosspay - fedtaxwithheld - statetaxwithheld - sswithheld - mcwithheld;
OutputLbl.Text = ("Employee name: " + name + "\nGross pay: " + grosspay + "\nFederal Tax Withheld : " + fedtaxwithheld + "\nState Tax Withheld: " + statetaxwithheld + "\nSocial Security Withheld: " + sswithheld + "\nMedicare Withheld: " + mcwithheld + "\nNet Pay: " + netpay);
}
}
【问题讨论】:
-
我不太确定你的问题是什么。您是否要求类似:
OutputLbl.Text += ("Employee name: " + name + "\nGross pay: " + grosspay + "\nFederal Tax Withheld : " + fedtaxwithheld + "\nState Tax Withheld: " + statetaxwithheld + "\nSocial Security Withheld: " + sswithheld + "\nMedicare Withheld: " + mcwithheld + "\nNet Pay: " + netpay); -
注意
+= -
这会发生什么?
OutputLbl.Text = ("Employee name: " + name + "\nGross pay: " + grosspay + "\nFederal Tax Withheld : " + fedtaxwithheld + "\nState Tax Withheld: " + statetaxwithheld + "\nSocial Security Withheld: " + sswithheld + "\nMedicare Withheld: " + mcwithheld + "\nNet Pay: " + netpay); -
我的代码现在是这样,我计算了一名员工的总/净工资。我希望能够为多名员工执行此操作,并将他们的工资信息添加到不同的标签,以跟踪我输入的所有员工的总付款信息。
-
@glr22 如果您的要求真的那么简单,那么我上面的评论应该可以为您解决。