예제 #1
0
        private double GetWage(int idx, DateTime wageTime)
        {
            Employee employee = Converter.GetEmployee(EmployeesFromDb[idx]);

            if (employee.EmploymentDate > wageTime)
            {
                throw new Exception("Выберите дату позднее даты трудоустройства сотрудника.");
            }
            string password = PasswordInput != null?PasswordInput() : "";

            // hashes of employee and his/her boss
            List <string> allPossiblePasswordInfos = new List <string>();

            allPossiblePasswordInfos.AddRange(Converter.GetEmployeePasswords(EmployeesFromDb[idx]));
            string adminPswInfo = AdminPasswordReceiver();

            if (adminPswInfo != null)
            {
                allPossiblePasswordInfos.Add(adminPswInfo);
            }

            foreach (string passInfo in allPossiblePasswordInfos)
            {
                if (PasswordChecker?.Invoke(password, passInfo) ?? true)
                {
                    return(EmployeeSalaryCalculator.GetInstance().CalculateSalary(employee, wageTime));
                }
            }
            throw new Exception("У Вас отсутствуют права доступа");
        }
예제 #2
0
        public double CalcSalary(Employee employee, DateTime time)
        {
            var wage  = employee.WageRate;
            var span  = time - employee.EmploymentDate;
            int years = span.Days / 365;

            if (years > 0)
            {
                var maxWage = wage * 1.4;
                while (years-- > 0 && wage < maxWage)
                {
                    wage += employee.WageRate * 0.05;
                }
            }

            if (employee.GetDirectSubordinates() != null)
            {
                double subordinateWage = 0;
                foreach (Employee empl in employee.GetDirectSubordinates())
                {
                    subordinateWage += EmployeeSalaryCalculator.GetInstance().CalculateSalary(empl, time);
                }
                wage += subordinateWage * 0.05;
            }

            return(Math.Round(wage, 2));
        }
예제 #3
0
        private double GetCompanyWage(DateTime wageTime)
        {
            string password = PasswordInput != null?PasswordInput() : "";

            if (password.Length > 0)
            {
                if (PasswordChecker(password, AdminPasswordReceiver()))
                {
                    double overallSalary = 0;
                    foreach (CompanyEmployee employee in Context.CompanyEmployees.Local)
                    {
                        if (employee.EmploymentDate > wageTime)
                        {
                            continue;
                        }
                        Employee e = Converter.GetEmployee(employee);
                        overallSalary += EmployeeSalaryCalculator.GetInstance().CalculateSalary(e, wageTime);
                    }
                    return(overallSalary);
                }
            }
            throw new Exception("У Вас отсутствуют права доступа");
        }