I have learned on how to create a reminder application from this website http://www.c-sharpcorner.com/uploadfile/f397b9/reminder-application-in-windows-phone-mango/ But from here it allows to just add one reminder. As I make a new reminder, the previous will be overrided. How do i make it to be able to accept multiple reminders. Below are my code:
void btnSave_Click(object sender, RoutedEventArgs e)
{
DateTime _Date = rDate.Value.Value;
TimeSpan _Time = rTime.Value.Value.TimeOfDay;
_Date = _Date.Date + _Time;
String _Content = titleTBox.Text;
if (_Date < DateTime.Now)
MessageBox.Show("Your time is not match !\nPlease Enter again !");
else if (String.IsNullOrEmpty(_Content))
MessageBox.Show("Your task can't be empty !\n Please enter to do task !");
else
{
ScheduledAction _OldReminder = ScheduledActionService.Find("TodoReminder"); if (_OldReminder != null)
ScheduledActionService.Remove(_OldReminder.Name);
Reminder _Reminder = new Reminder("TodoReminder")
{
BeginTime = _Date,
Title = "Reminder",
Content = _Content,
};
ScheduledActionService.Add(_Reminder);
//MessageBox.Show("Set Reminder Completed");
}
}
Code is working as expected, you are finding a previously registered reminder, when it exists, you remove it and then register a new one with the same name.
separate your code into a simple method
private void RegisterScheduleIfNotExist(string name, string title, string content, DateTime time)
{
ScheduledAction currentReminder = ScheduledActionService.Find(name);
if (currentReminder != null)
{
ScheduledActionService.Remove(currentReminder.Name);
}
var reminder = new Reminder(name)
{
BeginTime = time,
Title = title,
Content = content,
};
ScheduledActionService.Add(reminder);
}
then call the method with Unique names IF you do not wish to override an existing reminder, e.g.with Task1, Task2
RegisterScheduleIfNotExist("Task1", "Task 1 title", "Task 1 content", DateTime.Now.AddMinutes(3));
RegisterScheduleIfNotExist("Task2", "Task 2 title", "Task 2 content", DateTime.Now.AddMinutes(5));