Exemple #1
0
        /// <summary>
        /// Возвращает приблизительное количество дней, за которое наберется ресурс remains с заданной среднестатистической наработкой
        /// </summary>
        /// <param name="from"></param>
        /// <param name="remains"></param>
        /// <param name="average"></param>
        /// <param name="conditionType"></param>
        /// <returns></returns>
        public static Double?GetApproximateDays(DateTime from,
                                                Lifelength remains, AverageUtilization average,
                                                ThresholdConditionType conditionType = ThresholdConditionType.WhicheverFirst)
        {
            //
            if (remains == null || average == null)
            {
                return(null);
            }

            if (remains.CalendarValue != null && remains.CalendarValue != 0)
            {
                DateTime to = from.AddCalendarSpan(remains.CalendarSpan);
                return((to - from).Days);
            }

            Double?d1 = average.CyclesPerMonth != 0 && remains.Cycles != null ? new Double?(remains.Cycles.Value / (average.Hours / average.Cycles)) : null;
            Double?d2 = average.HoursPerMonth != 0 && remains.Hours != null ? remains.Hours * 30 / average.HoursPerMonth : null;
            Double?d3 = remains.Days;

            // Whichever First vs. Whichever Later
            if (conditionType == ThresholdConditionType.WhicheverFirst)
            {
                // Выбираем минимум
                Double?min = null;
                if (d1 != null)
                {
                    min = d1;
                }
                if (d2 != null && (min == null || d2 < min))
                {
                    min = d2;
                }
                if (d3 != null && (min == null || d3 < min))
                {
                    min = d3;
                }
                // Возвращаем результат
                return(min);
            }

            // Выбираем максимум
            Double?max = null;

            if (d1 != null)
            {
                max = d1;
            }
            if (d2 != null && (max == null || d2 > max))
            {
                max = d2;
            }
            if (d3 != null && (max == null || d3 > max))
            {
                max = d3;
            }
            // Возвращаем результат
            return(max);
        }
        /// <summary>
        /// Прибавляет заданную наработку к уже существующей
        /// </summary>
        /// <param name="from"></param>
        /// <param name="lifelength"></param>
        public void Add(DateTime from, Lifelength lifelength)
        {
            // прибавляем к this
            // null + cycles = cycles
            // cycles + null = cycles
            // null + null = null
            // cycles + cycles = cycles + cycles
            if (Cycles == null && lifelength.Cycles != null)
            {
                Cycles = lifelength.Cycles;
            }
            else if (Cycles != null && lifelength.Cycles != null)
            {
                Cycles += lifelength.Cycles;
            }

            if (TotalMinutes == null && lifelength.TotalMinutes != null)
            {
                TotalMinutes = lifelength.TotalMinutes;
            }
            else if (TotalMinutes != null && lifelength.TotalMinutes != null)
            {
                TotalMinutes += lifelength.TotalMinutes;
            }

            if (CalendarValue == null && lifelength.CalendarValue != null)
            {
                DateTime to = from.AddCalendarSpan(lifelength.CalendarSpan);
                Days = (to - from).Days;
            }
            else if (Days != null && lifelength.Days != null)
            {
                DateTime to = from.AddCalendarSpan(lifelength.CalendarSpan);
                Days += (to - from).Days;
            }
        }