Skip to content

Commit

Permalink
datepicker date fromat set to MM/dd/YYYY
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranshahi committed Oct 3, 2023
1 parent 8099d23 commit f72315a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
3 changes: 2 additions & 1 deletion EmployeeManagementSystem/AddEmployee.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 35 additions & 27 deletions EmployeeManagementSystem/AddEmployee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public AddEmployee(int nextEmployeID)
}

//This method will set the values on controls received from the selected row.
public void LoadData(string id, string name, string address, string contact, string email, string desigination,
string department, string dateOfJoin, string wageRate, string workedHour)
public void LoadData(string id, string name, string address, string contact, string email, string desigination, string department, string dateOfJoin, string wageRate, string workedHour)
{
txtIdNo.Text = id;
txtFullName.Text = name;
Expand All @@ -52,13 +51,14 @@ public AddEmployee(int nextEmployeID)
txtEmail.Text = email;
txtDesignation.Text = desigination;
comboBoxDepartment.Text = department;
dateTimePicker.Text = dateOfJoin;
string[] dateParts = dateOfJoin.Split('/');
dateTimePicker.Value = new DateTime(int.Parse(dateParts[2]), int.Parse(dateParts[0]), int.Parse(dateParts[1]));
txtWage.Text = wageRate;
txtWorkedHour.Text = workedHour;
}
private void BtnCancel_Click(object sender, EventArgs e)
{
this.Close();
Close();
}

private void OnMouseDown(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -86,31 +86,39 @@ private void LblClose_Click(object sender, EventArgs e)

private async void BtnSave_Click(object sender, EventArgs e)
{
var id = int.TryParse(txtIdNo.Text, out int EmployeeNo);
var name = txtFullName.Text;
var address = txtAddress.Text;
var contactNo = txtContact.Text;
var email = txtEmail.Text;
var desigination = txtDesignation.Text;
var department = comboBoxDepartment.Text;
var dateOfJoin = dateTimePicker.Text;
var wageRate = txtWage.Text;
var hourWorked = txtWorkedHour.Text;

using (var context = new EmployeeManagementContext())
try
{
var emp = new Employee(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);
context.Employees.Add(emp);
await context.SaveChangesAsync();
}

//instance event args and value has been passed
var args = new IdentityEventArgs(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);

//Event has be raised with update arguments of delegate
IdentityUpdated?.Invoke(this, args);

this.Hide();
int EmployeeNo = int.Parse(txtIdNo.Text);
string name = txtFullName.Text;
string address = txtAddress.Text;
string contactNo = txtContact.Text;
string email = txtEmail.Text;
string desigination = txtDesignation.Text;
string department = comboBoxDepartment.Text;
string dateOfJoin = dateTimePicker.Value.ToString("MM-dd-yyyy");
string wageRate = txtWage.Text;
string hourWorked = txtWorkedHour.Text;

using (var context = new EmployeeManagementContext())
{
var emp = new Employee(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);
context.Employees.Add(emp);
await context.SaveChangesAsync();
}

//instance event args and value has been passed
var args = new IdentityEventArgs(EmployeeNo, name, address, contactNo, email, desigination, department, dateOfJoin, wageRate, hourWorked);

//Event has be raised with update arguments of delegate
IdentityUpdated?.Invoke(this, args);

Hide();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Add Employee", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

//This method valid the textoBox full name, if you put a number it return an error
Expand Down

0 comments on commit f72315a

Please sign in to comment.