Esempio n. 1
0
        private void CreateDateListFromItem(IRecurringScheduleAppointment item)
        {
            string[] rulesArray = item.RecurrenceRule.Split(new char[] { RecurrenceSupport.RuleDelimiter });
            DateTime baseDate   = DateTime.Parse(rulesArray[0]);

            item.DateList = new RecurrenceList(rulesArray[2], baseDate, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds recurring appointments.
        /// </summary>
        /// <param name="item">The recurring appointment definition.</param>
        /// <param name="dateLimit">A date limit at which the recurring appointments end.</param>
        /// <remarks> The date limit may be dateTime.MaxValue which indicates no limit.</remarks>
        public void AddNewRecurringAppointments(IRecurringScheduleAppointment item, DateTime dateLimit)
        {
            string[] rulesArray = item.RecurrenceRule.Split(new char[] { RecurrenceSupport.RuleDelimiter });
            DateTime baseDate   = DateTime.Parse(rulesArray[0]);
            DateTime date       = rulesArray[1].Length > 0 ? DateTime.Parse(rulesArray[1]) : dateLimit;

            if (item.DateList == null)
            { //if null, then need to create it.
                CreateDateListFromItem(item);
                //conditionally set terminal date if present in rule.
                if (rulesArray[1].Length > 0)
                {
                    item.DateList.TerminalDate = date;
                }
            }
            item.DateList.IsValidRecurrence(date); //this populates DateList up through date
            bool needToSort = false;

            foreach (DateTime dt in item.DateList)
            {   //now go through and add appointments that match the datelist entries
                if (dt >= item.DateList.BaseDate && dt <= item.DateList.TerminalDate)
                {
                    AddAppointmentFromItem(item, dt);
                    needToSort = true;
                }
            }
            if (needToSort)
            {
                ResetBaseDate(item);
                MasterList.SortStartTime();
            }
        }
Esempio n. 3
0
        private void AddAppointmentFromItem(IRecurringScheduleAppointment item, DateTime dt)
        {
            IRecurringScheduleAppointment item1 = item.Clone() as IRecurringScheduleAppointment;

            item1.StartTime = new DateTime(dt.Year, dt.Month, dt.Day, item.StartTime.Hour, item.StartTime.Minute, 0);
            item1.EndTime   = new DateTime(dt.Year, dt.Month, dt.Day, item.EndTime.Hour, item.EndTime.Minute, 0);
            this.MasterList.Add(item1);
        }
Esempio n. 4
0
        private void ResetBaseDate(IRecurringScheduleAppointment item)
        {
            item.DateList.BaseDate = item.DateList[item.DateList.Count - 1];//.AddDays(1);
            if (item.DateList.BaseDate > item.DateList.TerminalDate)
            {
                item.DateList.BaseDate = item.DateList.TerminalDate;
            }
            int i = item.RecurrenceRule.IndexOf(RecurrenceSupport.RuleDelimiter);

            if (i > -1)
            {
                item.RecurrenceRule = string.Format("{0}{1}", item.DateList.BaseDate.ToShortDateString(), item.RecurrenceRule.Substring(i));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Removes all occurrences the given appointment.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool RemoveRecurringAppointments(IRecurringScheduleAppointment recurItem)
        {
            bool      deleted = false;
            ArrayList list    = new ArrayList();

            foreach (IRecurringScheduleAppointment item in this.MasterList)
            {
                if (item.RecurrenceRuleID == recurItem.RecurrenceRuleID)
                {
                    list.Add(item);
                }
            }

            foreach (IRecurringScheduleAppointment item in list)
            {
                this.MasterList.Remove(item);
                deleted = true;
            }
            IRecurringScheduleAppointment found = null;

            foreach (IRecurringScheduleAppointment item in this.RecurringList)
            {
                if (item.RecurrenceRuleID == recurItem.RecurrenceRuleID)
                {
                    found   = item;
                    deleted = true;
                    break;
                }
            }

            if (found != null)
            {
                RecurringList.Remove(found);
            }

            return(deleted);
        }
Esempio n. 6
0
        /// <summary>
        /// Makes changes to appointments in a recurring sequence of appointments.
        /// </summary>
        /// <param name="item">The edit appointment.</param>
        /// <param name="action">The requested edit action.</param>
        public void SaveModifiedRecurringAppointment(IRecurringScheduleAppointment modifiedItem, IRecurringScheduleAppointment originalItem, RecurringAppointmentEditAction action)
        {
            switch (action)
            {
            case RecurringAppointmentEditAction.ChangeAllAppointments:
                for (int i = 0; i < this.MasterList.Count; ++i)
                {
                    IRecurringScheduleAppointment item = this.MasterList[i] as IRecurringScheduleAppointment;
                    if (item.RecurrenceRuleID == originalItem.RecurrenceRuleID)
                    {
                        this.MasterList[i] = SetExceptDates(this.MasterList[i], modifiedItem);
                        // this.MasterList[i] = modifiedItem;
                    }
                }
                for (int i = 0; i < this.RecurringList.Count; ++i)
                {
                    IRecurringScheduleAppointment item = this.MasterList[i] as IRecurringScheduleAppointment;

                    if (item.RecurrenceRuleID == originalItem.RecurrenceRuleID &&
                        this.RecurringList[i].StartTime >= originalItem.StartTime)
                    {
                        this.RecurringList[i] = SetExceptDates(this.RecurringList[i], modifiedItem);
                        // this.RecurringList[i] = modifiedItem;
                    }
                }
                break;

            case RecurringAppointmentEditAction.ChangeAllFutureAppointments:

                for (int i = 0; i < this.MasterList.Count; ++i)
                {
                    IRecurringScheduleAppointment item = this.MasterList[i] as IRecurringScheduleAppointment;

                    if (item.RecurrenceRuleID == originalItem.RecurrenceRuleID &&
                        this.MasterList[i].StartTime >= originalItem.StartTime)
                    {
                        // this.MasterList[i] = modifiedItem;
                        this.MasterList[i] = SetExceptDates(this.MasterList[i], modifiedItem);
                    }
                }

                for (int i = 0; i < this.RecurringList.Count; ++i)
                {
                    IRecurringScheduleAppointment item = this.MasterList[i] as IRecurringScheduleAppointment;

                    if (item.RecurrenceRuleID == originalItem.RecurrenceRuleID &&
                        this.RecurringList[i].StartTime >= originalItem.StartTime)
                    {
                        this.RecurringList[i] = SetExceptDates(this.RecurringList[i], modifiedItem);
                        // this.RecurringList[i] = modifiedItem;
                    }
                }

                break;

            case RecurringAppointmentEditAction.ChangeSingleAppointmentOnly:
                for (int i = 0; i < this.MasterList.Count; ++i)
                {
                    if (this.MasterList[i].Equals(originalItem))
                    {
                        this.MasterList[i] = modifiedItem;
                        break;
                    }
                }
                break;

            case  RecurringAppointmentEditAction.Cancel:
                //no action....
                break;

            default:
                break;
            }
        }