Ejemplo n.º 1
0
 public void AddSickDay(Employee employee, int year = 0, int month = 0)
 {
     do
     {
         List <DateTime> dates = GetDates("sick-leave");
         if (year == 0 && month == 0)
         {
             dates = GetDates("sick-leave");
         }
         else if (year > 0 && month == 0)
         {
             dates = GetDates("sick-leave", year);
         }
         else if (month > 0 && year > 0)
         {
             dates = GetDates("sick-leave", year, month);
         }
         DateTime startdate = dates[0];
         DateTime enddate   = dates[1];
         DateTime date      = startdate;
         bool     fact      = true;
         do
         {
             var day = date.DayOfWeek.ToString();
             int notworkingemployees = Reader.GetNumberOfOffEmployees(date) + Reader.GetNumberOfSickEmployees(date) + Reader.GetNumberOfVacaEmployees(date);
             int workableemployees   = Reader.GetNumberOfWorkableEmployees(date);
             if ((day != "Saturday") && (day != "Sunday"))
             {
                 if ((notworkingemployees - workableemployees) > (GetEmployees() / 2) - 3)
                 {
                     Console.WriteLine("Sorry but there is a conflict with this day:" + date.ToString());
                     Console.ReadLine();
                     fact = false;
                 }
             }
             date = date.AddDays(1.0);
         } while ((!(date > enddate)) && fact);
         bool conflictfact = DoesConflictExist(employee.ID, startdate, enddate);
         if (fact && !(conflictfact))
         {
             if (Lawyer.GetYesNo("Are you sure you want to add the sick day/s of " + employee.PrintName() + " from " + startdate.ToLongDateString() + " to " + enddate.ToLongDateString()))
             {
                 Creator.AddSickDay(employee.ID, startdate, enddate);
             }
         }
         else if (conflictfact)
         {
             Console.WriteLine("Sorry but there was a conflict with trying to schedule this employee for the given sick days.");
             Console.ReadLine();
         }
         else if (!fact)
         {
             Console.WriteLine("Not enough workers some how");
             Console.ReadLine();
         }
         Console.Clear();
         if (Lawyer.GetYesNo("Do you want to add sick days for the same employee?"))
         {
             if (Lawyer.GetYesNo("Do you want to add sick days for this employee using the same year?"))
             {
                 if (Lawyer.GetYesNo("Do you want to add sick days for this employee using the same month?"))
                 {
                     AddSickDay(employee, int.Parse(date.Year.ToString()), int.Parse(date.Month.ToString()));
                 }
                 else
                 {
                     AddSickDay(employee, int.Parse(date.Year.ToString()));
                 }
             }
             else
             {
                 AddSickDay(employee);
             }
         }
     } while (Lawyer.GetYesNo("Do you want to add a sick days for another employee?"));
 }