//Record employee hours #region private void btnRecordHours_Click(object sender, EventArgs e) { //validation if (!ValidationHelper.NumberWithDashOrDecimal(txtHours.Text)) { MessageBox.Show("Please enter the amount of hours employee has worked."); return; } //read input EmpHours empHours = new EmpHours(); empHours.EmpID = int.Parse(txtIdEmp.Text); empHours.WorkDate = DateTime.Parse(dtbWorkDate.Text); empHours.Hours = decimal.Parse(txtHours.Text); //pass to controller EmpHoursController controller = new EmpHoursController(); ResultEnum result = controller.AddHours(empHours); //show output switch (result) { case ResultEnum.Success: MessageBox.Show("Hours added."); break; case ResultEnum.Fail: MessageBox.Show("Cannot add hours"); break; } }
//display employee total hours #region private void btnDisplay_Click(object sender, EventArgs e) { //validation if (!ValidationHelper.NumberOnly(txtIdDisplay.Text)) { MessageBox.Show("Please enter a valid id number"); return; } //read input int id = int.Parse(txtIdDisplay.Text); //pass to controller //call emphours controller for hours info EmpHoursController controller = new EmpHoursController(); Result <EmpHours> result = controller.DisplayWorkInfo(id); //call employee controller to retrieve employee name EmployeeController controller1 = new EmployeeController(); Result <Employee> result1 = controller1.SelectById(id); Employee emp = new Employee(); switch (result.Status) { case ResultEnum.Success: if (result.Data.Count == 0) { if (result1.Data.Count == 0) { lblEmployeeName.Text = "Employee does not exist."; lblTotalHours.Text = "No recorded hours."; break; } lblEmployeeName.Text = result1.Data[0].ToString(); lblTotalHours.Text = "No recorded hours."; break; } txtIdDisplay.Text = result.Data[0].EmpID.ToString(); lblEmployeeName.Text = result1.Data[0].ToString(); decimal total = 0; foreach (var item in result.Data) { total += item.Hours; } lblTotalHours.Text = total.ToString(); break; case ResultEnum.Fail: MessageBox.Show("Cannot display employee info."); break; } }