コード例 #1
0
ファイル: ShiftTable.cs プロジェクト: vnovikov746/ShifterMan
 private bool checkMaxHoursExceeded(Shift option)
 {
     int totalHours = countWorkersHours(option.getWroker_ID());
     int optionHours = option.getShiftHours();
     if (totalHours + optionHours > MAX_WORK_HOURS_PER_WEEK)
     {
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: ShiftTable.cs プロジェクト: vnovikov746/ShifterMan
 public bool optionExists(Shift other)
 {
     foreach (Shift sh in shiftTable)
     {
         if (sh.getWroker_ID() == other.getWroker_ID() && sh.getDay() == other.getDay() && sh.getBegin_Time() == other.getBegin_Time() && sh.getEnd_Time() == other.getEnd_Time())
         {
             return true;
         }
     }
     return false;
 }
コード例 #3
0
ファイル: ShiftTable.cs プロジェクト: vnovikov746/ShifterMan
    public bool optionLegal(Shift option)
    {
        if (checkMaxHoursExceeded(option))
        {
            return false;
        }

        int optBeginHour = Convert.ToInt32(option.getBegin_Time().Trim().Split(':')[0]);
        int optEndHour = Convert.ToInt32(option.getEnd_Time().Trim().Split(':')[0]);
        string optBeginDay = option.getDay();
        string optEndDay = option.getDay();

        if (optBeginHour > optEndHour)
        {
            optEndDay = getNextDay(optEndDay);
        }

        optBeginHour -= MINIMUM_REST_TIME;
        optEndHour += MINIMUM_REST_TIME;

        if (optBeginHour < 0)
        {
            optBeginHour = optBeginHour + DAY_HOURS;
            optBeginDay = getPrevDay(optBeginDay);
        }

        if (optEndHour > DAY_HOURS)
        {
            optEndHour -= DAY_HOURS;
            optEndDay = getNextDay(optEndDay);
        }

        foreach (Shift sh in shiftTable)
        {
            if (sh.getWroker_ID() == option.getWroker_ID())
            {
                int shBeginHour = Convert.ToInt32(sh.getBegin_Time().Trim().Split(':')[0]);
                int shEndHour = Convert.ToInt32(sh.getEnd_Time().Trim().Split(':')[0]);
                string shBeginDay = sh.getDay();
                string shEndDay = sh.getDay();

                if (shBeginHour > shEndHour)
                {
                    shEndDay = getNextDay(shEndDay);
                }

                if (shBeginDay == optBeginDay)  //SHIFT AND OPTION START AT THE SAME DAY
                {
                    if (shBeginHour == optBeginHour) //shift and otions starts at the same time
                    {
                        return false;
                    }
                    if (shBeginHour > optBeginHour) //shift starts after option
                    {
                        if (shBeginDay == optEndDay && shBeginHour < optEndHour)
                        {
                            return false;
                        }
                        if (optBeginDay != optEndDay)
                        {
                            return false;
                        }
                    }
                    if (shBeginHour < optBeginHour) //shift starts before option
                    {
                        if (shEndDay == optBeginDay && shEndHour > optBeginHour)
                        {
                            return false;
                        }
                        if (shBeginDay != shEndDay)
                        {
                            return false;
                        }

                    }
                }

                if (shBeginDay == optEndDay)  //SHIFT STARTS AT THE DAY OPTION ENDS
                {
                    if (shBeginHour < optEndHour)
                    {
                        return false;
                    }
                }

                if (shEndDay == optBeginDay)  //SHIFT ENDS AT THE DAY OPTION STARTS
                {
                    if (shEndHour > optBeginHour)
                    {
                        return false;
                    }
                }

                if (optBeginDay == getPrevDay(shBeginDay) && optEndDay == getNextDay(shEndDay)) //SHIFT STARTS END ENDS WHILE OPTION LASTS
                {
                    return false;
                }

            }

        }
        return true;
    }