public HumanResourcesData(DataSet dataSet) { employeesTable = dataSet.Tables["Employees"]; departmentsTable = dataSet.Tables["Departments"]; endDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); endDate = endDate.AddMonths(-1); startDate = new DateTime(endDate.Year - FullYears, 1, 1); CreateImployeesHistory(); DateTime dt = startDate; while (dt <= endDate) { foreach (DataRow employee in Employees) { string fullName = GetEmployeeFullName(employee); HistoryItem historyItem = employeesHistory[fullName]; if (historyItem.IsEmployeed(dt)) { int departmentID = GetEmployeeDepartmentID(employee); DataRow department = GetDepartmentByDepartmentID(departmentID); string departmentName = GetDepartmentName(department); DepartmentDataKey departmentDataKey = new DepartmentDataKey(dt, departmentName); DepartmentData departmentDataValue = null; if (!deptData.TryGetValue(departmentDataKey, out departmentDataValue)) { departmentDataValue = new DepartmentData { CurrentDate = dt, Department = departmentName }; deptData.Add(departmentDataKey, departmentDataValue); } departmentDataValue.HeadCount++; if (historyItem.IsRetired(dt)) { departmentDataValue.RetiredCount++; } decimal baseSalary = GetDepartmentBaseSalary(department); decimal salary = baseSalary + (decimal)DataHelper.Random(rand, (double)baseSalary / rand.Next(1, 5)); decimal bonus = (decimal)DataHelper.Random(rand, (double)salary, true); decimal overtime = (decimal)DataHelper.Random(rand, (double)salary / rand.Next(1, 5), true); int vacationDays = 0; if (rand.NextDouble() > 0.5) { vacationDays = rand.Next(0, 10); } int sickLeaveDays = 0; if (rand.NextDouble() > 0.5) { sickLeaveDays = rand.Next(0, 5); } empData.Add(new EmployeeData { CurrentDate = dt, Department = departmentName, Employee = fullName, Salary = salary, Bonus = bonus, Overtime = overtime, VacationDays = vacationDays, SickLeaveDays = sickLeaveDays }); } } dt = dt.AddMonths(1); } foreach (DepartmentData data in deptData.Values) { data.StaffTurnrover = data.HeadCount > 0 ? (double)data.RetiredCount / data.HeadCount : 0; data.StaffTurnroverCritical = 0.01; } }
public override bool Equals(object obj) { DepartmentDataKey key = (DepartmentDataKey)obj; return(key.dt == dt && key.dept == dept); }