public void DefineSalaryExecute() { if (String.IsNullOrEmpty(Addition.ToString()) || Addition == 0) { MessageBox.Show("Please fill field for addition.", "Notification"); } else { try { if (Employee != null) { MessageBoxResult result = MessageBox.Show("Are you sure you want to define salary?", "Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Employee.Salary = CalculateSalary.CalculateForOne(Manager, Employee, Addition); bool isDefine = employees.SetSalary(Employee); if (isDefine == true) { MessageBox.Show("Salary is defined.", "Notification", MessageBoxButton.OK); EmployeeList = managers.GetEmployees(Manager); } else { MessageBox.Show("Salary cannot be defined.", "Notification", MessageBoxButton.OK); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/// <summary> /// This method performs calculating salary. /// </summary> /// <param name="sender">Object.</param> /// <param name="e">DoWorkEventArgs object.</param> public void BW_DoWork(object sender, DoWorkEventArgs e) { double count = EmployeeList.Count; double result = 100 / count; int i = 1; Random r = new Random(); foreach (var employee in EmployeeList) { employee.Salary = CalculateSalary.CalculateForOne(Manager, employee, Addition); bool isDefine = employees.SetSalary(employee); if (isDefine == true) { Thread.Sleep(r.Next(250, 500)); backgroundWorker.ReportProgress(Convert.ToInt32(result * i++)); } } }