示例#1
0
        /// <summary>
        /// Calculates the needed vacation days for the desired holiday period. Weekends and holidays are deducted.
        /// </summary>
        /// <param name="VacationRequest">VacationRequest of the Requester</param>
        /// <returns>number of needed vacation days</returns>
        public static int DetermineWorkingDaysInVacationRequest(VacationRequest VacationRequest)
        {
            int workingDays = 0;
            int holiDays = 0;
            int netWorkingDays = 0;

            //count weekdays between vacation start day and vacation end day
            int n = 0;
            while (VacationRequest.getVacationStartDate().AddDays(n) <= VacationRequest.getVacationEndDate()) // vacation start day == vacation start day is possible
            {
                if (VacationRequest.getVacationStartDate().AddDays(n).DayOfWeek != DayOfWeek.Saturday && VacationRequest.getVacationStartDate().AddDays(n).DayOfWeek != DayOfWeek.Sunday) //== no weekday
                {
                    workingDays++;
                }
                n++;
            }

            // check if holidays days are in the vacation period
            DBQuery dbq = new DBQuery();
            holiDays = dbq.SelectHolidays(VacationRequest);

            // correct required vacation days
            netWorkingDays = workingDays - holiDays;

            return netWorkingDays;
        }