コード例 #1
0
        public DateTime AddWorkingDays(DateTime registrationDateTime, int daysCount)
        {
            if (daysCount < 0)
            {
                return(RemoveWorkingDays(registrationDateTime, Math.Abs(daysCount)));
            }
            var      registrationDay = Utils.GetCalendarDay(CalendarIdsChain, registrationDateTime, null);
            var      firstDateInDay  = GetFirstDateTimeInDay(registrationDateTime);
            var      lastDateInDay   = GetLastDateTimeInDay(registrationDateTime);
            var      lessFirstDate   = registrationDateTime <= firstDateInDay;
            var      moreLastDate    = registrationDateTime >= lastDateInDay;
            DateTime fromDay         = registrationDateTime.Date.AddDays(daysCount == 0 ? 0 : 1);
            DateTime toDay           = registrationDateTime.Date.AddDays(daysCount);

            List <DayInCalendar> days = Utils.GetCalendarDays(CalendarIdsChain, fromDay, toDay).ToList();
            int weekendDaysCount      = days.Count(d => d.GetTypedColumnValue <bool>("DayType_IsWeekend"));

            while (weekendDaysCount != 0)
            {
                fromDay          = toDay.AddDays(1);
                toDay            = toDay.AddDays(weekendDaysCount);
                days             = Utils.GetCalendarDays(CalendarIdsChain, fromDay, toDay).ToList();
                weekendDaysCount = days.Count(d => d.GetTypedColumnValue <bool>("DayType_IsWeekend"));
            }
            DateTime      maxDate      = days.Max(d => d.Date);
            DayInCalendar maxDay       = days.Single(d => d.Date == maxDate);
            DayInCalendar almostMaxDay = GetNearestNotWeekendDay(maxDay.Date.AddDays(-1), false).Value;

            maxDay.Date = lessFirstDate ?  GetLastWorkingDayDateTime(almostMaxDay): GetLastWorkingDayDateTime(maxDay);
            return(maxDay.Date);
        }
コード例 #2
0
        public DateTime GetPreviousWorkingTimeIntervalEnd(DateTime registrationDateTime)
        {
            KeyValuePair <DateTime, DayInCalendar> foundDay = GetNearestNotWeekendDay(registrationDateTime, false);
            DayInCalendar day      = foundDay.Value;
            DateTime      dateTime = foundDay.Key;

            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "WorkingTimeInterval");

            esq.AddColumn("To");
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "DayInCalendar",
                                                           day.PrimaryColumnValue));
            if (dateTime.TimeOfDay != TimeSpan.Zero)
            {
                esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.LessOrEqual, "To",
                                                               dateTime.TimeOfDay));
            }

            EntityCollection timeIntervals = esq.GetEntityCollection(UserConnection);

            if (!timeIntervals.Any())
            {
                return(GetPreviousWorkingTimeIntervalEnd(dateTime.Date.AddDays(-1)));
            }

            return(dateTime.Date + timeIntervals.Max(d => d.GetTypedColumnValue <DateTime>("To").TimeOfDay));
        }
コード例 #3
0
 public DayInCalendarObject(DayInCalendar dayInCalendarEntity)
 {
     Id               = dayInCalendarEntity.Id;
     CalendarId       = dayInCalendarEntity.CalendarId;
     Date             = dayInCalendarEntity.Date;
     DayTypeId        = dayInCalendarEntity.DayTypeId;
     DayOfWeekId      = dayInCalendarEntity.DayOfWeekId;
     IsDayTypeWeekend = dayInCalendarEntity.GetTypedColumnValue <bool>("DayType_IsWeekend");
     DayOfWeekNumber  = dayInCalendarEntity.GetTypedColumnValue <int>("DayOfWeek_Number");
 }
コード例 #4
0
        /// <summary>
        /// ########## ########### ####.
        /// </summary>
        /// <param name="calendarIds">############## ######## ########## ### #######</param>
        /// <param name="date">#### ### #######</param>
        /// <param name="ignoredIds">############## ####, ####### ## ##### ############ # #######</param>
        /// <returns>########### ####</returns>
        public DayInCalendar GetCalendarDay(IEnumerable <Guid> calendarIds, DateTime date,
                                            IEnumerable <Guid> ignoredIds = null)
        {
            DayInCalendar day = GetCalendarDayInner(calendarIds, date, ignoredIds);

            if (day.Date == DateTime.MinValue)
            {
                day.Date = date.Date.Date;
            }
            return(day);
        }
コード例 #5
0
        private KeyValuePair <DateTime, DayInCalendar> GetNearestNotWeekendDay(DateTime registrationDateTime,
                                                                               bool moveForvard = true)
        {
            DayInCalendar day = Utils.GetCalendarDay(CalendarIdsChain, registrationDateTime);

            if (!day.GetTypedColumnValue <bool>("DayType_IsWeekend"))
            {
                return(new KeyValuePair <DateTime, DayInCalendar>(registrationDateTime, day));
            }
            registrationDateTime = registrationDateTime.Date.AddDays(moveForvard ? 1 : -1);
            return(GetNearestNotWeekendDay(registrationDateTime, moveForvard));
        }
コード例 #6
0
        /// <summary>
        /// ########## ########### ########### ####.
        /// </summary>
        /// <param name="calendarIds">############## ######## ########## ### #######</param>
        /// <param name="date">#### ### #######</param>
        /// <param name="ignoredIds">############## ####, ####### ## ##### ############ # #######</param>
        /// <returns>########### ########### ####</returns>
        public DayInCalendarExtended GetCalendarDayExtended(IEnumerable <Guid> calendarIds, DateTime date,
                                                            IEnumerable <Guid> ignoredIds = null)
        {
            DayInCalendar day       = GetCalendarDayInner(calendarIds, date, ignoredIds);
            var           isMinDate = day.Date == DateTime.MinValue;

            if (isMinDate)
            {
                day.Date = date.Date;
            }
            return(new DayInCalendarExtended(day, !isMinDate));
        }
コード例 #7
0
        public TimeSpan GetWorkingTimeSpan(DateTime fromDateTime, DateTime toDateTime)
        {
            bool isNegative = false;

            if (fromDateTime > toDateTime)
            {
                DateTime tempDateTime = fromDateTime;
                fromDateTime = toDateTime;
                toDateTime   = tempDateTime;
                isNegative   = true;
            }

            List <DayInCalendar> days =
                Utils.GetCalendarDays(CalendarIdsChain, fromDateTime, toDateTime).OrderBy(d => d.Date).ToList();
            DayInCalendar fromDay = days.First();
            DayInCalendar toDay   = days.Last();

            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "WorkingTimeInterval");

            esq.AddColumn("From");
            esq.AddColumn("To");
            esq.AddColumn("DayInCalendar");
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "DayInCalendar",
                                                           days.Select(d => d.Id).Distinct().Select(d => (object)d).ToArray()));
            List <WorkingTimeInterval> timeIntervals =
                esq.GetEntityCollection(UserConnection).Select(d => (WorkingTimeInterval)d).ToList();

            TimeSpan workingTimeSpan = TimeSpan.Zero;

            foreach (DayInCalendar day in days)
            {
                List <WorkingTimeInterval> dayTimeIntervals = timeIntervals.Where(t => t.DayInCalendarId == day.Id).
                                                              ToList();
                foreach (WorkingTimeInterval interval in dayTimeIntervals)
                {
                    if (Equals(day, fromDay) && interval.From.TimeOfDay < fromDateTime.TimeOfDay)
                    {
                        interval.From = fromDateTime;
                    }
                    if (Equals(day, toDay) && interval.To.TimeOfDay > toDateTime.TimeOfDay)
                    {
                        interval.To = toDateTime;
                    }
                    if (interval.From.TimeOfDay < interval.To.TimeOfDay)
                    {
                        workingTimeSpan = workingTimeSpan.Add(interval.To.TimeOfDay - interval.From.TimeOfDay);
                    }
                }
            }

            return(isNegative ? -workingTimeSpan : workingTimeSpan);
        }
コード例 #8
0
        protected override DayInCalendarObject GetDay(Guid treeGridRecordId)
        {
            Guid calendarId      = _page.DataSource.ActiveRowPrimaryColumnValue;
            int  dayOfWeekNumber = CurrentDaysGridData[treeGridRecordId].DayOfWeekNumber;

            var calendarHelper = new CalendarUtils(UserConnection);

            CalendarEditPageChangesStore.DayInCalendarChangedObject changedDay = ChangesStore.Days.SingleOrDefault(d =>
                                                                                                                   d.DayInCalendar.CalendarId == calendarId && d.DayInCalendar.DayOfWeekNumber == dayOfWeekNumber &&
                                                                                                                   d.ChangedStatus != CalendarEditPageChangesStore.ChangedStatus.Deleted);
            if (changedDay != null)
            {
                return(changedDay.DayInCalendar);
            }
            DayInCalendar day = calendarHelper.GetWeekDay(CalendarIdsChain, dayOfWeekNumber,
                                                          ChangesStore.GetDeletedDaysIds());

            return(new DayInCalendarObject(day));
        }
コード例 #9
0
        private DateTime RemoveWorkingDays(DateTime registrationDateTime, int daysCount)
        {
            DateTime fromDay = registrationDateTime.Date.AddDays(-daysCount);
            DateTime toDay   = registrationDateTime.Date.AddDays(-1);

            List <DayInCalendar> days = Utils.GetCalendarDays(CalendarIdsChain, fromDay, toDay).ToList();
            int weekendDaysCount      = days.Count(d => d.GetTypedColumnValue <bool>("DayType_IsWeekend"));

            while (weekendDaysCount != 0)
            {
                toDay            = fromDay.AddDays(-1);
                fromDay          = fromDay.AddDays(-weekendDaysCount);
                days             = Utils.GetCalendarDays(CalendarIdsChain, fromDay, toDay).ToList();
                weekendDaysCount = days.Count(d => d.GetTypedColumnValue <bool>("DayType_IsWeekend"));
            }

            DateTime      minDate = days.Min(d => d.Date);
            DayInCalendar minDay  = days.Single(d => d.Date == minDate);

            return(minDay.Date + GetLastWorkingTimeIntervalEnd(minDay.PrimaryColumnValue));
        }
コード例 #10
0
        public bool IsTimeInWorkingInterval(DateTime registrationDateTime)
        {
            DayInCalendar day = Utils.GetCalendarDay(CalendarIdsChain, registrationDateTime);

            if (day.GetTypedColumnValue <bool>("DayType_IsWeekend"))
            {
                return(false);
            }

            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "WorkingTimeInterval");

            esq.AddColumn("Id");
            esq.RowCount = 1;
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "DayInCalendar",
                                                           day.PrimaryColumnValue));
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.GreaterOrEqual, "To",
                                                           registrationDateTime.TimeOfDay));
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.LessOrEqual, "From",
                                                           registrationDateTime.TimeOfDay));
            return(esq.GetEntityCollection(UserConnection).Any());
        }
コード例 #11
0
        public DateTime GetNextWorkingTimeIntervalStart(DateTime registrationDateTime)
        {
            KeyValuePair <DateTime, DayInCalendar> foundDay = GetNearestNotWeekendDay(registrationDateTime);
            DayInCalendar day      = foundDay.Value;
            DateTime      dateTime = foundDay.Key;
            var           esq      = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "WorkingTimeInterval");

            esq.AddColumn("From");
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "DayInCalendar",
                                                           day.PrimaryColumnValue));
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.GreaterOrEqual, "From",
                                                           dateTime.TimeOfDay));

            EntityCollection timeIntervals = esq.GetEntityCollection(UserConnection);

            if (!timeIntervals.Any())
            {
                return(GetNextWorkingTimeIntervalStart(dateTime.Date.AddDays(1)));
            }

            return(dateTime.Date + timeIntervals.Min(d => d.GetTypedColumnValue <DateTime>("From").TimeOfDay));
        }
コード例 #12
0
 public DayInCalendar(DayInCalendar source)
     : base(source)
 {
 }
コード例 #13
0
 public DayInCalendar(Terrasoft.Configuration.DayInCalendar source)
     : base(source)
 {
     this.CopyEntityLookupProperties(source);
 }
コード例 #14
0
 private DateTime GetLastWorkingDayDateTime(DayInCalendar day)
 {
     return(day.Date.Date + GetLastWorkingTimeIntervalEnd(day.PrimaryColumnValue));
 }
コード例 #15
0
 public DayInCalendarExtended(DayInCalendar dayInCalendar, bool isCalendarValue)
 {
     IsCalendarValue = isCalendarValue;
     DayInCalendar   = dayInCalendar;
 }