我正在構建一個表單,允許用戶輸入員工的姓名,工資率和工作時間。一旦將這些信息輸入到三個文本框中,用戶點擊一個按鈕,該按鈕可計算總收入,社會保障預扣,扣留醫療保險,扣留州稅,扣留聯邦稅和淨收入。這個信息被輸出到一個標籤。我希望用戶能夠輸入多個員工,並將此信息添加到之前的輸入中(如果第一個員工的總支付爲$ 2,000.00,第二個員工的總支付爲$ 1,000,總支付總額爲$ 3,000等) )我該如何去完成這件事?C#Windows窗體如何將先前輸入的輸入添加到新輸入中?
當前代碼:
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 + =(「員工姓名:」+姓名+「\ nGross pay:」+ grosspay +「\ n聯邦稅代扣:」+ fedtaxwithheld +「\ n國家稅代扣:」+ statetaxhold +「\ nSocial Security版主:」+ sswithheld +「\ nMedicare版主:」+ mcwithheld +「\ nNet Pay:」+ netpay);' – mydogisbox
注意'+ =' – mydogisbox
這會發生什麼? 'OutputLbl.Text =(「員工姓名:」+姓氏+「\ n交叉薪水:」+ grosspay +「\ n聯邦稅保留:」+ fedtaxwithheld +「\ n國家稅代扣:」+ statetaxwithheld +「\ n社會安全代扣:」 + sswithheld +「\ nMedicare版主:」+ mcwithheld +「\ nNet Pay:」+ netpay); ' –