Exemple #1
0
        /// <summary>
        /// Gives a new value to a reminder based on it's repeating type, and inserts it into the database
        /// </summary>
        /// <param name="rem"></param>
        public static void UpdateReminder(Reminder rem)
        {
            if (rem != null)
            {
                BLIO.Log("Updating reminder with id " + rem.Id);
                //Enable the reminder again
                rem.Enabled = 1;

                if (rem.RepeatType == ReminderRepeatType.WORKDAYS.ToString()) //Add days to the reminder so that the next date will be a new workday
                {
                    rem.Date = BLDateTime.GetNextReminderWorkDay(rem, true).ToString();
                }

                if (rem.RepeatType == ReminderRepeatType.DAILY.ToString())    //Add a day to the reminder
                {
                    UpdateReminderDateDaily(rem, true);
                }


                if (rem.RepeatType == ReminderRepeatType.MONTHLY.ToString())
                {
                    if (rem.Date.Split(',').Length > 1)
                    {
                        List <DateTime> reminderDates = new List <DateTime>();

                        foreach (string date in rem.Date.Split(','))     //go through each date. with monthly reminders, it can have multiple dates, seperated by comma's
                        {
                            if (Convert.ToDateTime(date) < DateTime.Now) //get the next day of the monthly day of the date. example: 10-6-2017 -> 10-7-2017 BUT 31-1-2017 -> 31-3-2017, since february doesnt have 31 days
                            {
                                reminderDates.Add(Convert.ToDateTime(BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(date)).ToShortDateString() + " " + Convert.ToDateTime(date).ToShortTimeString()));
                            }
                            else
                            {
                                reminderDates.Add(Convert.ToDateTime(date)); //Date in the future? good! do nothing with it.
                            }
                        }
                        //have to make sure the first date is in front.
                        reminderDates.Sort();

                        //Now, we're going to put the (sorted) dates in a string
                        string newDateString = "";
                        foreach (DateTime date in reminderDates)
                        {
                            if (rem.UpdateTime == 0)
                            {
                                newDateString += date.ToString() + ",";
                            }
                            else
                            {
                                newDateString += date.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ",";
                            }
                        }


                        rem.Date = newDateString.Remove(newDateString.Length - 1, 1);
                    }
                    else
                    {//There's only one date in this string.
                        if (rem.UpdateTime == 0)
                        {
                            rem.Date = BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(rem.Date)).ToShortDateString() + " " + Convert.ToDateTime(rem.Date).ToShortTimeString();
                        }
                        else
                        {
                            rem.Date = BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(rem.Date)).ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                        }
                    }
                }

                if (rem.RepeatType == ReminderRepeatType.MULTIPLE_DAYS.ToString())
                {
                    if (rem.UpdateTime == 0)
                    {
                        rem.Date = Convert.ToDateTime(BLDateTime.GetEarliestDateFromListOfStringDays(rem.RepeatDays)).ToShortDateString() + " " + Convert.ToDateTime(rem.Date).ToShortTimeString();
                    }
                    else
                    {
                        rem.Date = Convert.ToDateTime(BLDateTime.GetEarliestDateFromListOfStringDays(rem.RepeatDays)).ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                    }
                }

                if (rem.EveryXCustom != null)
                {
                    while (Convert.ToDateTime(rem.Date) < DateTime.Now)
                    {
                        //The user has a custom reminder, every x minutes,hours,days,weeks, or months
                        switch (rem.RepeatType.ToLower())
                        {
                        case "minutes":
                            if (rem.UpdateTime == 1)
                            {
                                rem.Date = DateTime.Now.AddMinutes((double)rem.EveryXCustom).ToString();
                            }
                            else
                            {
                                rem.Date = Convert.ToDateTime(rem.Date).AddMinutes((double)rem.EveryXCustom).ToString();
                            }
                            break;

                        case "hours":
                            if (rem.UpdateTime == 1)
                            {
                                rem.Date = DateTime.Now.AddHours((double)rem.EveryXCustom).ToString();
                            }
                            else
                            {
                                rem.Date = Convert.ToDateTime(rem.Date).AddHours((double)rem.EveryXCustom).ToString();
                            }
                            break;

                        case "days":
                            rem.Date = Convert.ToDateTime(rem.Date).AddDays((double)rem.EveryXCustom).ToString();
                            if (rem.UpdateTime == 1)
                            {
                                rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                            }
                            break;

                        case "weeks":
                            rem.Date = Convert.ToDateTime(rem.Date).AddDays((double)rem.EveryXCustom * 7).ToString();
                            if (rem.UpdateTime == 1)
                            {
                                rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                            }
                            break;

                        case "months":
                            rem.Date = Convert.ToDateTime(rem.Date).AddMonths((int)rem.EveryXCustom).ToString();
                            if (rem.UpdateTime == 1)
                            {
                                rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                            }
                            break;
                        }
                    }
                }
                if (rem.RepeatType == ReminderRepeatType.NONE.ToString())
                {
                    if (rem.Date.Split(',').Length > 1) //multiple dates seperated by comma's
                    {
                        string newDateString = "";      //The new date1,date2,date3 string that we will assign to the reminder

                        string[] dateArray = rem.Date.Split(',');

                        dateArray = dateArray.Where(s => Convert.ToDateTime(s) > DateTime.Now).ToArray(); //remove all elements from the array that already happened

                        if (dateArray.Length == 0)
                        {
                            DLReminders.ArchiveReminder(rem);
                            return;
                        }

                        foreach (string date in dateArray)
                        {
                            newDateString += date + ",";
                        }

                        newDateString = newDateString.Remove(newDateString.Length - 1, 1); //remove the last ','

                        rem.Date = newDateString;
                    }
                    else//it had one date, and that date caused this popup. Let's delete the reminder.
                    {
                        DLReminders.ArchiveReminder(rem);
                        return;
                    }
                }
                //finally, Write the changes to the database
                DLReminders.EditReminder(rem);
                BLIO.Log("Reminder updated");
            }
            else
            {
                throw new ArgumentNullException("parameter rem in UpdateReminder is null.");
            }
        }
Exemple #2
0
 /// <summary>
 /// forces the database to refresh the list
 /// </summary>
 public static void NotifyChange()
 {
     BLIO.Log("BLReminder.NotifyChange()");
     DLReminders.NotifyChange();
     GC.Collect();
 }