Domanda

I have a list of days and time and I want to create a reminder for all days with time. Example : monday 10am 12am 15pm friday 10am 12am 15pm saturday 10am 12am 15pm every week. I know that an application can store 50 reminders but I think users open application before :D

I don't understand the logic in my mind tonight :( Please help me. Best regards

I have a list of days.Exemple : Monday Tuesday Saturday and i want a reminder for dat tree days all week.

private ObservableCollection<Day> _days;
        public ObservableCollection<Day> Days
        {
            get { return _days; }
            set { _days = value; RaisePropertyChanged("Days"); }
        }

Create reminder :

Reminder r = new Reminder("Time To Train!!!");
r.Content = AppResources.TimeToTrain;
r.BeginTime = //Here the problem;
r.ExpirationTime = //Here the problem //DateTime.Now.AddDays(52 * 7));
r.RecurrenceType = RecurrenceInterval.Weekly;
r.NavigationUri = new Uri("/View/MainPage.xaml", UriKind.RelativeOrAbsolute);
ScheduledActionService.Add(r);

I look this post for take some idea.Windows Phone 7 Reminders. I have a list of times.Exemple 10:14am 17:00pm.

private ObservableCollection<DateTime> _times;
            public ObservableCollection<DateTime> Times
            {
                get { return _days; }
                set { _days = value; RaisePropertyChanged("Times"); }
            }

I want to create reminder now for all times at all days. Reminder for monday at 10:14am and 17:00pm / Tuesday at 10:14am and 17:00pm / Saturday at 10:14am and 17:00pm

È stato utile?

Soluzione

So let's say you want to create a reminder for 12 AM Monday. I'd first create a method to find out first "occurrence" of Monday in the future, something like this:

private DateTime getFirstDate(DayOfWeek day, TimeSpan time)
        {
            DateTime date = DateTime.Today;
            while(date.DayOfWeek != day)
                date.AddDays(1);

            return new DateTime(date.Year,date.Month,date.Day,time.Hours,time.Minutes,time.Seconds);
        }

And then use it in your code like this:

r.BeginTime = getFirstDate(DayOfWeek.Monday, new TimeSpan(12,0,0));

It only creates a reminder for the closest Monday, but you can do the same thing when this reminder is triggered- create one for the next Monday.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top