public ResultsEnum AddEmp(Employee newEmp) { ResultsEnum result = ResultsEnum.SUCCESS; try { if (dao.SearchEmail(newEmp.Email) == newEmp.Email) { throw new EmailDuplicatedException(); } if (dao.SearchPhone(newEmp.Phone) == newEmp.Phone) { throw new PhoneDuplicatedException(); } dao.CreateEmp(newEmp); } catch (EmailDuplicatedException) { result = ResultsEnum.FAIL; MessageBox.Show("Email already existed in system"); } catch (PhoneDuplicatedException) { result = ResultsEnum.FAIL; MessageBox.Show("Phone number already existed in system"); } catch (Exception ex) { result = ResultsEnum.FAIL; Console.WriteLine("Error, AddEmp, " + ex.Message); } return(result); }
private void btnRecordHours_Click(object sender, EventArgs e) { try { EmpHour empH = new EmpHour(); empH.WorkDate = DateTime.Parse(dtpWorkDate.Text); empH.Hour = double.Parse(txtHours.Text); empH.EmpID = (int)cmbEmp.SelectedValue; Validation v = new Validation(); v.ValidateDate(empH.WorkDate); v.ValidateHour(empH.Hour); EmpHourManager empHManager = new EmpHourManager(); ResultsEnum result = empHManager.AddWork(empH); Employee emp = (Employee)cmbEmp.SelectedItem; string empFullName = emp.FirstName + " " + emp.LastName; switch (result) { case ResultsEnum.SUCCESS: MessageBox.Show("Employee ID " + emp.EmpID + "\n" + empFullName + "\nWork Date: " + empH.WorkDate.ToShortDateString() + "\nHour: " + decimal.Round((decimal)empH.Hour, 2) + "\n\nWork Added"); break; case ResultsEnum.FAIL: MessageBox.Show("Sorry... please try again later"); break; } } catch (FormatException) { MessageBox.Show("Invalid input"); } catch (EmptyInputException) { MessageBox.Show("Input cannot be empty"); } catch (WhiteSpaceException) { MessageBox.Show("Input cannot contain space"); } catch (FutureException) { MessageBox.Show("Invalid work date"); } catch (NoWorkHourException) { MessageBox.Show("Work hour must greater than zero"); } catch (MaxDailyWorkException) { MessageBox.Show("No more than 24 hours work in a day"); } }
/// <summary> /// updates an employees details and returns a string with the result /// </summary> /// <param name="emp"></param> /// <returns></returns> private string UpdateEmployeeResult(Employee emp) { ResultsEnum result = _empController.Update(emp); if (result == ResultsEnum.Success) { LoadEmployeeData(); // update the home page with the new data return(@"Employee details updated"); } return(@"Update failed, check the fields and try again"); }
private void btnSaveChanges_Click(object sender, EventArgs e) { EmpHour empH = (EmpHour)cmbWorkDate.SelectedItem; try { EmpHour empH1 = (EmpHour)lstEmp.SelectedItem; empH1.WorkDate = empH.WorkDate; empH1.Hour = double.Parse(txtHours.Text); empH1.EmpHourID = empH.EmpHourID; Validation v = new Validation(); v.ValidateDate(empH1.WorkDate); v.ValidateHour(empH1.Hour); EmpHourManager empHManager = new EmpHourManager(); ResultsEnum result = empHManager.UpdateWorkHour(empH1); switch (result) { case ResultsEnum.SUCCESS: MessageBox.Show("Work Hour updated"); break; case ResultsEnum.FAIL: MessageBox.Show("Sorry...please try again later"); break; } } catch (FormatException) { MessageBox.Show("Invalid input"); } catch (EmptyInputException) { MessageBox.Show("Input cannot be empty"); } catch (WhiteSpaceException) { MessageBox.Show("Input cannot contain space"); } catch (FutureException) { MessageBox.Show("Invalid date"); } catch (NoWorkHourException) { MessageBox.Show("Work hour must greater than zero"); } catch (MaxDailyWorkException) { MessageBox.Show("No more than 24 hours work in a day"); } }
/// <summary> /// returns a string depending on the success or failure of adding the hours /// </summary> /// <param name="hours"></param> /// <returns></returns> private string EmployeeHoursAdded(EmployeeHours hours) { ResultsEnum result = _hoursController.AddHours(hours); if (result != ResultsEnum.Success) { return("Hours not added.. check all the fields and try again"); } _empTracker.LoadEmployeeHours(); // update the new employee hours return("Employee hours added"); }
public ResultsEnum UpdateDetails(Employee emp) { ResultsEnum result = ResultsEnum.SUCCESS; try { dao.UpdateEmp(emp); } catch (Exception ex) { result = ResultsEnum.FAIL; Console.WriteLine("Error, UpdateDetails, " + ex.Message); } return(result); }
/// <summary> /// Deletes an employee based on the Id entered /// </summary> /// <param name="id"></param> private void DeleteEmployeeById(int id) { ResultsEnum result = _empController.Delete(id); if (result == ResultsEnum.Success) { lblStatus.Text = @"Employee Deleted"; LoadEmployeeData(); // update the home page ClearTextFields(); } else { lblStatus.Text = @"Could not delete, check all the fields and try again"; } }
private void SetResult(ResultsEnum res) { resultsPanel.gameObject.SetActive(true); StopCoroutine(timerInstance); if (res.Equals(ResultsEnum.GameOver)) { resultText.SetText("Game Over!!!"); } else if (res.Equals(ResultsEnum.Parked)) { if (secondsLeft > 0) { res = ResultsEnum.Perfect; } SetStars((int)res); resultText.SetText("You Won!!!"); } StartCoroutine(RestartGame()); }
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (!e.Cancelled) { if (e.Result is ResultsEnum) { ResultsEnum result = (ResultsEnum)e.Result; switch (result) { case ResultsEnum.NO_INTERNET: { /* In case if the internet connection was lost the program will * be trying each 2 minutes to start new thread */ progressBar.Hide(); _pauseFor = 2 * 60; //in seconds timeInfoLabel.Visible = true; timer.Interval = _TIMER_INTERVAL; timer.Enabled = true; noInternetLabel.Visible = true; } break; case ResultsEnum.COMPLETED: //if there is no more uprocessed data in csv file { progressBar.Hide(); stopButt.Enabled = false; startButt.Enabled = true; MessageBox.Show("Вся работа сделана", "Info"); } break; case ResultsEnum.PAUSE_STARTED: //this case means that background worker stoped processing a csv file { progressBar.Hide(); _pauseFor = _random.Next(15, 19) * 60; //in seconds timeInfoLabel.Visible = true; timer.Interval = _TIMER_INTERVAL; timer.Enabled = true; } break; } } } else // if the processed was interrupted by a user { stopButt.Enabled = false; startButt.Enabled = true; progressBar.Hide(); } }
private void btnSave_Click(object sender, EventArgs e) { try { Employee emp = new Employee(); emp.FirstName = txtFName.Text; emp.LastName = txtLName.Text; emp.Email = txtEmail.Text; emp.DOB = dtpDOB.Value; emp.Phone = txtPhone.Text; Validation v = new Validation(); v.ValidateName(emp.FirstName); v.ValidateName(emp.LastName); v.ValidateEmail(emp.Email); v.ValidateDate(emp.DOB); v.ValidatePhone(emp.Phone); EmployeeManager empManager = new EmployeeManager(); ResultsEnum result = empManager.AddEmp(emp); switch (result) { case ResultsEnum.SUCCESS: MessageBox.Show("One employee added to the database:" + "\n\nFirst Name: " + emp.FirstName + "\nLast Name: " + emp.LastName + "\nEmail: " + emp.Email + "\nDOB: " + emp.DOB.ToShortDateString() + "\nPhone: " + emp.Phone); break; case ResultsEnum.FAIL: MessageBox.Show("Sorry...please try again later"); break; } } catch (FormatException) { MessageBox.Show("Invalid input"); } catch (EmptyInputException) { MessageBox.Show("Input cannot be empty"); } catch (WhiteSpaceException) { MessageBox.Show("Input cannot contain space"); } catch (InvalidPhoneNumberException) { MessageBox.Show("Invalid phone number"); } catch (TextMaxLengthException) { MessageBox.Show("Too many characters in input"); } catch (FutureException) { MessageBox.Show("Invalid DOB"); } catch (InvalidEmaiException) { MessageBox.Show("Invalid email address"); } }
private void btnSaveChanges_Click(object sender, EventArgs e) { try { Employee emp = (Employee)lstEmp.SelectedItem; emp.FirstName = txtFName.Text; emp.LastName = txtLName.Text; emp.Email = txtEmail.Text; emp.DOB = dtpDOB.Value; emp.Phone = txtPhone.Text; Validation v = new Validation(); v.ValidateName(emp.FirstName); v.ValidateName(emp.LastName); v.ValidateEmail(emp.Email); v.ValidateDate(emp.DOB); v.ValidatePhone(emp.Phone); EmployeeManager empManager = new EmployeeManager(); ResultsEnum result = empManager.UpdateDetails(emp); switch (result) { case ResultsEnum.SUCCESS: MessageBox.Show("Employee details updated"); break; case ResultsEnum.FAIL: MessageBox.Show("Sorry...please try again later"); break; } } catch (FormatException) { MessageBox.Show("Invalid input"); } catch (EmptyInputException) { MessageBox.Show("Input cannot be empty"); } catch (WhiteSpaceException) { MessageBox.Show("Input cannot contain space"); } catch (TextMaxLengthException) { MessageBox.Show("Too many characters in input"); } catch (InvalidPhoneNumberException) { MessageBox.Show("Invalid phone number"); } catch (FutureException) { MessageBox.Show("Invalid DOB"); } catch (InvalidEmaiException) { MessageBox.Show("Invalid email address"); } }