コード例 #1
0
        private List <PayRate> GetPaymentRatesDetails(StreamReader file)
        {
            while ((line = file.ReadLine()) != null)
            {
                string[] valueSplit = line.Split(',');

                //Since there are several ranges for the same day, this will help put all ranges together without repeating the days
                if (payRate.Name == valueSplit[0] || payRate.Name == null)
                {
                    payRate.Name = valueSplit[0];                              //Name of the day will always be the first value
                    dayInfo.StartRange.Add(Convert.ToDateTime(valueSplit[1])); //Start hour for that range will be second
                    dayInfo.EndRange.Add(Convert.ToDateTime(valueSplit[2]));   // End hour for the range will be third
                    dayInfo.PayAmount.Add(Int32.Parse(valueSplit[3]));         //The amount to be payed for that range of hours will be last
                }
                else
                {
                    if (payRate.Name != null)
                    {
                        payRate.Day = dayInfo;
                        payRatesList.Add(payRate);
                        dayInfo = new DayInfo(); //since lists store a reference value, we need to create a new object so it doesnt modify the one in the list
                        payRate = new PayRate();
                    }
                    payRate.Name = valueSplit[0];
                    dayInfo.StartRange.Add(Convert.ToDateTime(valueSplit[1]));
                    dayInfo.EndRange.Add(Convert.ToDateTime(valueSplit[2]));
                    dayInfo.PayAmount.Add(Int32.Parse(valueSplit[3]));
                }
            }
            payRate.Day = dayInfo;
            payRatesList.Add(payRate);
            file.Close();
            return(payRatesList);
        }
コード例 #2
0
 public List <Employee> GetSalaryForEmployer(List <Employee> employeeList, List <PayRate> payRates)
 {
     for (int i = 0; i < employeeList.Count; i++)
     {
         employee      = new Employee();
         finalPayCheck = 0;
         employee      = employeeList[i];                                  //this will give me all the information of 1 employee
         for (int j = 0; j < employee.Day.Count; j++)                      //Loop through each day the employee worked
         {
             dailyPayRate = payRates.Find(x => x.Name == employee.Day[j]); //Find the day information for which the employee worked
             DateTime employeeEndHour   = employee.EndHour[j];
             DateTime employeeStartHour = employee.StartHour[j];
             for (int k = 0; k < dailyPayRate.Day.StartRange.Count; k++)//This loop will get the pay ranges the employee worked and calculate his pay
             {
                 if (dailyPayRate.Day.EndRange[k] > employeeStartHour || dailyPayRate.Day.EndRange[k].TimeOfDay == constantException)
                 {
                     //Normal scenario, employee only worked on the same hour range
                     if (dailyPayRate.Day.EndRange[k] >= employeeEndHour || dailyPayRate.Day.EndRange[k].TimeOfDay == constantException)
                     {
                         double workTime = (employeeEndHour - employeeStartHour).TotalHours;
                         finalPayCheck = finalPayCheck + (workTime * dailyPayRate.Day.PayAmount[k]);
                         break;
                     }
                     //Employee worked on 2 different hour ranges
                     else if (dailyPayRate.Day.EndRange[k + 1] >= employeeEndHour || dailyPayRate.Day.EndRange[k + 1].TimeOfDay == constantException)
                     {
                         double workTime = (dailyPayRate.Day.EndRange[k] - employeeStartHour).TotalHours;
                         double cost1    = dailyPayRate.Day.PayAmount[k] * workTime;
                         workTime = (employeeEndHour - dailyPayRate.Day.EndRange[k]).TotalHours;
                         double cost2 = dailyPayRate.Day.PayAmount[k + 1] * workTime;
                         finalPayCheck = finalPayCheck + cost1 + cost2;
                         break;
                     }
                     //Employee worked on the 3 different possible hour ranges
                     else
                     {
                         double workTime = (dailyPayRate.Day.EndRange[k] - employeeStartHour).TotalHours;
                         double cost1    = dailyPayRate.Day.PayAmount[k] * workTime;
                         workTime = (employeeEndHour - dailyPayRate.Day.EndRange[k + 1]).TotalHours;
                         double cost2 = dailyPayRate.Day.PayAmount[k + 2] * workTime;
                         workTime = (dailyPayRate.Day.EndRange[k + 1] - dailyPayRate.Day.EndRange[k]).TotalHours;
                         double cost3 = dailyPayRate.Day.PayAmount[k + 1] * workTime;
                         finalPayCheck = finalPayCheck + cost1 + cost2 + cost3;
                         break;
                     }
                 }
             }
         }
         employee.PayCheck = finalPayCheck; //Add the pay check for each employee and Add it to the list
         employeeSalaryList.Add(employee);
     }
     return(employeeSalaryList);
 }