I have got the data from a text file to fill in the text boxes with the data. However I am trying to get an employees salary from another class into the text box and I am struggling to do so. My first class is the employee class with this code:
public class Employee
{
string _firstName;
string _lastName;
string _address;
string _postCode;
string _phoneNumber;
DateTime _dateOfBirth;
public Employee()
{
}
public Employee(string firstName, string lastName, string address, string postCode, string phoneNumber, DateTime dateOfBirth)
{
_firstName = firstName;
_lastName = lastName;
_address = address;
_postCode = postCode;
_phoneNumber = phoneNumber;
_dateOfBirth = dateOfBirth;
}
public string firstName
{
get
{
return _firstName;
}
set
{
_firstName = value;
}
}
public string lastName
{
get
{
return _lastName;
}
set
{
_lastName = value;
}
}
public string address
{
get
{
return _address;
}
set
{
_address = value;
}
}
public string postCode
{
get
{
return _postCode;
}
set
{
_postCode = value;
}
}
public string phoneNumber
{
get
{
return _phoneNumber;
}
set
{
_phoneNumber = value;
}
}
public DateTime dateOfBirth
{
get
{
return _dateOfBirth;
}
set
{
_dateOfBirth = value;
}
}
followed by the salaried class with this code:
public class SalariedEmployee : Employee
{
decimal _salary;
public SalariedEmployee(string firstName, string lastName, string
address, string postCode, string phoneNumber, DateTime dateOfBirth,
decimal salary) : base(firstName, lastName, address, postCode, phoneNumber,
dateOfBirth)
{
_salary = salary;
}
public decimal salary
{
get
{
return _salary;
}
set
{
_salary = value;
}
}
}
this then goes onto the load method which is as follows:
public bool Load(string employeesFile)
{
List<string> lines = new List<string>();
using (StreamReader reader = new StreamReader("employees.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
//Splitting the data using |
string[] temp = line.Split('|');
int year = Convert.ToInt32(temp[5]);
int month = Convert.ToInt32(temp[6]);
int day = Convert.ToInt32(temp[7]);
//This is to populate an employees detials
Employee emp = new Employee
{
firstName = temp[0],
lastName = temp[1],
address = temp[2],
postCode = temp[3],
phoneNumber = temp[4],
dateOfBirth = new DateTime(year, month, day)
};
//This class is from List, so I used the add method to add the employee.
Add(emp);
}
return true;
and finally the form code:
public Salaried_Employee_Details(Employee emp)
{
InitializeComponent();
textBoxLastName.Text = emp.lastName;
textBoxFirstName.Text = emp.firstName;
textBoxAddress.Text = emp.address;
textBoxPostCode.Text = emp.postCode;
textBoxPhoneNumber.Text = emp.phoneNumber;
dateTimeDateOfBirth.Text = emp.dateOfBirth.ToString();
//textBoxSalary.Text = emp.salary;
}
with the work form here:
the format of the text file is here:
Smyth|Jack|London street, London City, London|01142325413|1990|3|21|37000
so how do I get the salaried data into the text box?