c# - Adding multiple reminder - windows phone -
i have learned on how create reminder application website http://www.c-sharpcorner.com/uploadfile/f397b9/reminder-application-in-windows-phone-mango/ here allows add 1 reminder. make new reminder, previous overrided. how make able accept multiple reminders. below 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 not match !\nplease enter again !"); else if (string.isnullorempty(_content)) messagebox.show("your task can't empty !\n please enter 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 working expected, finding registered reminder, when exists, remove , register new 1 same name.
separate code 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 method unique names if not wish override 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));
Comments
Post a Comment