1 Replies - 19436 Views - Last Post: 29 May 2009 - 08:32 AM Rate Topic: -----

#1 taichi2910  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-May 09

C# Payroll Application

Posted 29 May 2009 - 08:17 AM

Got this project write a C# windows app program that computes employee wages. Input the employee's payroll number and number of hours worked. The employee receives 7.45 per hour as hourly rate and is taxed 20% from gross pay and 7% also national insurance. and to display this information in a seperate group box which i cant do. but me main problem is the error i recieved running the app .

my code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		
		
		string name;
		int employeeNumber;
		double hours;
		const double hourlyWage = 7.5;
		double gross;
		double tax;
		double insurance;
		double deduction;

		

		private void btnCompute_Click(object sender, EventArgs e)
		{
			if (txtName.Text == "")
			{
				MessageB.Text = "...";
			}
			else if (txtPNumber.Text.Length <= 8)
			{
				MessageB.Text = "...";
			}
			else if (txtHoursWork.Text == "")
			{
				MessageB.Text = "...";
			}
			else if (btnCompute.Text == "Compute")
			{
				name = txtName.Text;
				employeeNumber = Convert.ToInt32(txtPNumber);
				hours = Convert.ToDouble(txtHoursWork.Text);
				gross = hours * hourlyWage;
				txtGrossPay.Text = "" + Convert.ToString(gross);
				tax = gross / 100 * 20;

				txtIncomeTax = "" + Convert.ToString(tax);

				insurance = gross / 100 * 7;

				txtNI = "" + Convert.ToString(insurance);
				deduction = tax + insurance;
				txtTotalDeduction = "" + Convert.ToString(deduction);

				



			}
			else
			{
				txtName.Text = "";
				txtPNumber.Text = "";
				txtHoursWork.Text = "";
				txtGrossPay.Text = "";
				txtIncomeTax.Text = "";
				txtNI.Text = "";
				txtTotalDeduction.Text = "";

				btnCompute.Text = "Compute";

				

			}
		}
		private void button1_Click(object sender, EventArgs e)
		{
			Close();
		}
	  
	}
}




error message

Error 1 Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

also attached the app

any of your help would be highly aappriciated
thank you in advance

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: C# Payroll Application

#2 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: C# Payroll Application

Posted 29 May 2009 - 08:32 AM

View Posttaichi2910, on 29 May, 2009 - 09:17 AM, said:

Got this project write a C# windows app program that computes employee wages. Input the employee's payroll number and number of hours worked. The employee receives 7.45 per hour as hourly rate and is taxed 20% from gross pay and 7% also national insurance. and to display this information in a seperate group box which i cant do. but me main problem is the error i recieved running the app .

my code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		
		
		string name;
		int employeeNumber;
		double hours;
		const double hourlyWage = 7.5;
		double gross;
		double tax;
		double insurance;
		double deduction;

		

		private void btnCompute_Click(object sender, EventArgs e)
		{
			if (txtName.Text == "")
			{
				MessageB.Text = "...";
			}
			else if (txtPNumber.Text.Length <= 8)
			{
				MessageB.Text = "...";
			}
			else if (txtHoursWork.Text == "")
			{
				MessageB.Text = "...";
			}
			else if (btnCompute.Text == "Compute")
			{
				name = txtName.Text;
				employeeNumber = Convert.ToInt32(txtPNumber);
				hours = Convert.ToDouble(txtHoursWork.Text);
				gross = hours * hourlyWage;
				txtGrossPay.Text = "" + Convert.ToString(gross);
				tax = gross / 100 * 20;

				txtIncomeTax = "" + Convert.ToString(tax);

				insurance = gross / 100 * 7;

				txtNI = "" + Convert.ToString(insurance);
				deduction = tax + insurance;
				txtTotalDeduction = "" + Convert.ToString(deduction);

				



			}
			else
			{
				txtName.Text = "";
				txtPNumber.Text = "";
				txtHoursWork.Text = "";
				txtGrossPay.Text = "";
				txtIncomeTax.Text = "";
				txtNI.Text = "";
				txtTotalDeduction.Text = "";

				btnCompute.Text = "Compute";

				

			}
		}
		private void button1_Click(object sender, EventArgs e)
		{
			Close();
		}
	  
	}
}




error message

Error 1 Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

also attached the app

any of your help would be highly aappriciated
thank you in advance


Are "txtIncomeTax", "txtNI", and "txtTotalDeduction" textBoxes? If so, you need to assign their value like this:
txtIncomeTax.Text = "" + Convert.ToString(tax);"


The error says that you are trying to assign a string to a textbox, you need to assign it to the textBox's "Text" property.

*Edit* You also have to change "txtPNumber" to "txtPNumber.Text" in the line that assigns a value to "employeeNumber" *Edit*

Hope this helps!

This post has been edited by lesPaul456: 29 May 2009 - 08:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1