/// <summary>
        /// ######### ######### # #########
        /// </summary>
        /// <param name="previousSelectedDay">###### ### # #########</param>
        /// <returns>##/###</returns>
        protected bool SaveChangesToStore(DayInCalendarObject previousSelectedDay)
        {
            bool isDiffFromParent  = GetIsCurrentDayDiffFromParent();
            bool wasDiffFromParent = GetIsDiffFromParent(previousSelectedDay);
            Guid dayInCalendarId   = previousSelectedDay.Id;
            bool isUpdated         = true;

            if (!isDiffFromParent && wasDiffFromParent)
            {
                ChangesStore.AddRemovedDay(previousSelectedDay);
            }
            else if (isDiffFromParent && !wasDiffFromParent)
            {
                var newDay = (DayInCalendarObject)previousSelectedDay.Clone();
                newDay.Id                 = Guid.NewGuid();
                newDay.DayTypeId          = (Guid)DayTypeEdit.Value;
                newDay.CalendarId         = _page.DataSource.ActiveRowPrimaryColumnValue;
                newDay.IsCalendarDayValue = IsCalendarDayValue;
                ChangesStore.AddNewDay(newDay);
                dayInCalendarId = newDay.Id;
                ChangedWorkingTimeIntervalsIndexes = GetChagedTimeIntervalIndexesFromFilledControls().ToList();
                CurrentWorkingTimeIntervalsData.Clear();
            }
            else if (isDiffFromParent && NeedUpdateDayInCalendarData(previousSelectedDay))
            {
                previousSelectedDay.DayTypeId = (Guid)DayTypeEdit.Value;
                ChangesStore.AddChangedDay(previousSelectedDay);
            }
            else
            {
                isUpdated = false;
            }
            UpdateIntervals(dayInCalendarId);
            return(isUpdated);
        }
        /// <summary>
        /// ########### ########## #######
        /// </summary>
        /// <param name="day">#### #########</param>
        private void DisplayWorkingTimeIntervals(DayInCalendarObject day)
        {
            var calendarUtils = new CalendarUtils(UserConnection);
            IEnumerable <WorkingTimeInterval> timeIntervalsEntities = calendarUtils.GetWorkingTimeIntervals(day.Id);
            List <WorkingTimeIntervalObject>  timeIntervals         =
                ChangesStore.MergeIntervals(day.Id, timeIntervalsEntities
                                            .Select(t => new WorkingTimeIntervalObject(t))).ToList();

            CurrentWorkingTimeIntervalsData = timeIntervals;
            ClearIntervalDateTimeControls();
            var container = _page.PageContainer;

            foreach (WorkingTimeIntervalObject timeInterval in CurrentWorkingTimeIntervalsData)
            {
                var i        = timeInterval.Index;
                var fromDate =
                    (DateTimeEdit)
                    container.FindControl(string.Format(FromControlNameFormat, TimeIntervalTypeControlAlias, i));
                var toDate =
                    (DateTimeEdit)
                    container.FindControl(string.Format(ToControlNameFormat, TimeIntervalTypeControlAlias, i));
                fromDate.SuspendAjaxEvents();
                toDate.SuspendAjaxEvents();
                fromDate.SelectedDate = timeInterval.From;
                toDate.SelectedDate   = timeInterval.To;
                fromDate.ResumeAjaxEvents();
                toDate.ResumeAjaxEvents();
            }
        }
 /// <summary>
 /// ########## ####### ##########. ########## ########## # #########
 /// </summary>
 public void HandleDataSourceSaved()
 {
     if (CurrentTreeGridRecordId != Guid.Empty && CurrentDaysGridData.Keys.Contains(CurrentTreeGridRecordId))
     {
         SaveChangesToStore(CurrentDaysGridData[CurrentTreeGridRecordId]);
     }
     ChangesStore.SaveChanges(UserConnection);
 }
Example #4
0
        protected override IEnumerable <DayInCalendarObject> GetDays()
        {
            Guid calendarId     = _page.DataSource.ActiveRowPrimaryColumnValue;
            var  calendarHelper = new CalendarUtils(UserConnection);
            IEnumerable <DayInCalendar> daysEntities = calendarHelper.GetWeekDays(CalendarIdsChain,
                                                                                  ChangesStore.GetDeletedDaysIds());

            return
                (ChangesStore.MergeWeekDays(calendarId, daysEntities.Select(d => new DayInCalendarObject(d)))
                 .OrderBy(d => d.DayOfWeekNumber));
        }
        protected override DayInCalendarObject GetDay(Guid treeGridRecordId)
        {
            Guid     calendarId = _page.DataSource.ActiveRowPrimaryColumnValue;
            DateTime date       = CurrentDaysGridData[treeGridRecordId].Date;

            var calendarUtils = new CalendarUtils(UserConnection);

            CalendarEditPageChangesStore.DayInCalendarChangedObject changedDay = ChangesStore.Days.SingleOrDefault(d =>
                                                                                                                   d.DayInCalendar.CalendarId == calendarId && d.DayInCalendar.Date.Date == date.Date &&
                                                                                                                   d.ChangedStatus != CalendarEditPageChangesStore.ChangedStatus.Deleted);
            if (changedDay != null)
            {
                return(changedDay.DayInCalendar);
            }
            DayInCalendarExtended day = calendarUtils.GetCalendarDayExtended(CalendarIdsChain, date,
                                                                             ChangesStore.GetDeletedDaysIds());

            return(new DayInCalendarObject(day));
        }
Example #6
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));
        }
        protected override IEnumerable <DayInCalendarObject> GetDays()
        {
            Guid     calendarId    = _page.DataSource.ActiveRowPrimaryColumnValue;
            var      calendarUtils = new CalendarUtils(UserConnection);
            DateTime fromDate      = _page.StartDateEdit.SelectedDate;
            DateTime toDate        = _page.EndDateEdit.SelectedDate;

            if (fromDate.Date == DateTime.MinValue.Date || toDate.Date == DateTime.MinValue.Date)
            {
                return(new List <DayInCalendarObject>());
            }
            List <Guid> ignoredIds = ChangesStore.GetDeletedDaysIds().ToList();

            IEnumerable <DayInCalendarObject> calendarDaysEntities =
                calendarUtils.GetCalendarDaysExtended(CalendarIdsChain, fromDate, toDate, ignoredIds)
                .Select(d => new DayInCalendarObject(d));
            List <DayInCalendarObject> calendarDays =
                ChangesStore.MergeCalendarDays(calendarId, calendarDaysEntities, fromDate, toDate).ToList();

            return(calendarDays);
        }
 /// <summary>
 /// ######### #########
 /// </summary>
 /// <param name="dayInCalendarId">############# ### # #########</param>
 private void UpdateIntervals(Guid dayInCalendarId)
 {
     foreach (int i in ChangedWorkingTimeIntervalsIndexes)
     {
         var container = _page.PageContainer;
         var fromDate  =
             (DateTimeEdit)
             container.FindControl(string.Format(FromControlNameFormat, TimeIntervalTypeControlAlias, i));
         var toDate =
             (DateTimeEdit)
             container.FindControl(string.Format(ToControlNameFormat, TimeIntervalTypeControlAlias, i));
         var  minDate = DateTime.MinValue;
         bool isIntervalControlsFilled          = fromDate.SelectedDate != minDate && toDate.SelectedDate != minDate;
         WorkingTimeIntervalObject timeInterval = CurrentWorkingTimeIntervalsData
                                                  .SingleOrDefault(t => t.Index == i);
         if (isIntervalControlsFilled && timeInterval != null)
         {
             timeInterval.From = fromDate.SelectedDate;
             timeInterval.To   = toDate.SelectedDate;
             ChangesStore.AddChangedInterval(timeInterval);
         }
         else if (isIntervalControlsFilled)
         {
             var newTimeInterval = new WorkingTimeIntervalObject {
                 Id              = Guid.NewGuid(),
                 Index           = i,
                 DayInCalendarId = dayInCalendarId,
                 From            = fromDate.SelectedDate,
                 To              = toDate.SelectedDate
             };
             ChangesStore.AddNewInterval(newTimeInterval);
         }
         else if (timeInterval != null)
         {
             ChangesStore.AddRemovedInterval(timeInterval);
         }
     }
 }