How to read and Write Text to a file from a textbox

Dubb1234
Posted by Dubb1234 under C# category on | Points: 40 | Views : 960
Program requirements: Write a graphical user application that accepts employee name number pay rate and number of hours worked. Store the name number and total amount of pay in a text file. Close the file and then retrieve the stored values and display the employee name formatted total pay??


I am having trouble retrieving the info written in the textboxes and saving them in a file using system io.. Can anyone help


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

namespace page826num9
{
partial class Form1 : Form
{
Employee EmployeeTemp = new Employee();

public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

}
public void computeTotalPayToolStripMenuItem_Click(object sender, EventArgs e)
{

EmployeeTemp.NameFirst = EmpFirstName.Text.ToString();

EmployeeTemp.NameLast = EmpLastName.Text.ToString();

EmployeeTemp.Number = System.Convert.ToDouble(EmpNumber.Text);

EmployeeTemp.PayRate = System.Convert.ToDouble(PayRate.Text);

EmployeeTemp.NumofHoursWorked = System.Convert.ToDouble(NumbofHoursWorked.Text);

TotalPay.Text = System.Convert.ToString(Employee.CalcTotalPay());

string namestr = EmpFirstName.Text + EmpLastName.Text;
comboBox1.Items.Add(namestr);
}
}
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace page826num9
{
class Employee
{
// All data members are private

private static string nameLast, nameFirst;
private static double number;
private static double payrate;
private static double numofhoursworked;


public Employee()
{

}
public Employee(string empNameLast, string empNameFirst)
{
nameLast = empNameLast;
nameFirst = empNameFirst;
}
public Employee(string empNameLast, string empNameFirst, int empNumber)
{
nameLast = empNameLast;
nameFirst = empNameFirst;
number = empNumber;
}

public Employee(string empNameLast, string empNameFirst, int empNumber, int empPayRate)
{
nameLast = empNameLast;
nameFirst = empNameFirst;
number = empNumber;
payrate = empPayRate;
}

public Employee(string empNameLast, string empNameFirst, int empNumber, int empPayRate,
int empNumofHoursWorked)
{
nameLast = empNameLast;
nameFirst = empNameFirst;
number = empNumber;
payrate = empPayRate;
numofhoursworked = empNumofHoursWorked;

}

public string NameLast
{
get
{
return nameLast;
}
set
{
nameLast = value;
}
}


public string NameFirst
{
get
{
return nameFirst;
}
set
{
nameFirst = value;
}
}


public double Number
{
get
{
return number;
}
set
{
number = value;
}
}

public double PayRate
{
get
{
return payrate;
}
set
{
payrate = value;
}
}
public double NumofHoursWorked
{
get
{
return numofhoursworked;
}
set
{
numofhoursworked = value;
}
}


public static double CalcTotalPay()
{

double totalPay=0;

if (numofhoursworked <= 40)
{


totalPay = (numofhoursworked * payrate);
}
else
{


totalPay = ((payrate * 40) + ((numofhoursworked - 40)* (payrate * 1.5)));
}


return totalPay;

}
}
}

Comments or Responses

Login to post response