protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            String taskId;
            if (NavigationContext.QueryString.TryGetValue("taskId", out taskId))
            {
                this.viewingTask = App.ViewModel.LoadTaskFromDatabase(int.Parse(taskId));
                this.DataContext = this.viewingTask;
                this.Repeats_TextBlock.Text = viewingTask.RecurringOption == Task.RecurringOptions.Never ? "Occurs only once" : "Repeats next on " + viewingTask.Next.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("/yyyy", ""));
                if (viewingTask.IsComplete)
                    (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false;
                this.Reminders_TextBlock.Text = viewingTask.HasReminders ? "ON" : "OFF";
            }
        }
Example #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            this.categoryListPicker.DataContext = App.ViewModel.CategoryList.Where(s => s.Id != App.ViewModel.All.Id);

            String categoryId;
            if (NavigationContext.QueryString.TryGetValue("categoryId", out categoryId))
                this.categoryListPicker.SelectedIndex = App.ViewModel.CategoryList.IndexOf(App.ViewModel.CategoryList.Single<Category>(s => s.Id == int.Parse(categoryId))) - 1;

            String taskId;
            if (updatingTask == null && NavigationContext.QueryString.TryGetValue("taskId", out taskId))
            {
                updatingTask = App.ViewModel.LoadTaskFromDatabase(int.Parse(taskId));
                this.newTaskName_TextBox.Text = updatingTask.Name;
                if (updatingTask.Notes == null)
                    updatingTask.Notes = "";
                this.newTaskNotes_TextBox.Text = updatingTask.Notes;
                this.categoryListPicker.SelectedIndex = App.ViewModel.CategoryList.IndexOf(updatingTask.Category) - 1;
                this.newTaskDate_datePicker.Value = updatingTask.When;
                this.newTaskTime_timePicker.Value = updatingTask.When;
                this.Completed_CheckBox.IsChecked = updatingTask.IsComplete;
                this.Reminders_ToggleSwitch.IsChecked = updatingTask.HasReminders;
                switch (updatingTask.Reward)
                {
                    case 5: this.rewardListPicker.SelectedIndex = 0; break;
                    case 15: this.rewardListPicker.SelectedIndex = 1; break;
                    case 25: this.rewardListPicker.SelectedIndex = 2; break;
                    case 50: this.rewardListPicker.SelectedIndex = 3; break;
                    default: this.rewardListPicker.SelectedIndex = 4; this.customReward.Visibility = Visibility.Visible; this.rewardCategoryValue_TextBlock.Text = updatingTask.Reward.ToString(); break;
                }
                switch (updatingTask.RecurringOption)
                {
                    case Task.RecurringOptions.Never: this.recurringOptionListPicker.SelectedIndex = 0; break;
                    case Task.RecurringOptions.Days:
                        if (updatingTask.RecurringAmount == 1)
                            this.recurringOptionListPicker.SelectedIndex = 1;
                        else if (updatingTask.RecurringAmount == 2)
                            this.recurringOptionListPicker.SelectedIndex = 2;
                        break;
                    case Task.RecurringOptions.DaysOfWeek:
                        if (updatingTask.RecurringAmount == 31)
                            this.recurringOptionListPicker.SelectedIndex = 3;
                        else if (updatingTask.RecurringAmount == (int)Math.Pow(2, ((int)updatingTask.When.DayOfWeek - 1)))
                        {
                            recurringOptions.RemoveAt(4);
                            recurringOptions.Insert(4, new RecurringOptionListItem { Name = "every " + updatingTask.When.ToString("dddd") });
                            this.recurringOptionListPicker.SelectedIndex = 4;
                        }
                        else
                        {
                            this.recurringOptionListPicker.SelectedIndex = 5;
                            this.DaysOfWeek_SelectList.Visibility = Visibility.Visible;

                            int localRecurringAmount = updatingTask.RecurringAmount;
                            for (int i = 6; i >= 0; i--)
                            {
                                if ((localRecurringAmount - Math.Pow(2, i)) >= 0){
                                    this.selectedDaysOfWeek.Add(daysOfWeek[i]);
                                    localRecurringAmount -= (int)Math.Pow(2, i);
                                }
                            }
                            if (selectedDaysOfWeek.Count != 0)
                            {
                                this.DaysOfWeek_SelectList.SelectedItems = selectedDaysOfWeek;
                            }
                        }
                        break;
                    case Task.RecurringOptions.Months:
                        if (updatingTask.RecurringAmount == 1)
                        {
                            recurringOptions.RemoveAt(5);
                            recurringOptions.Insert(5, new RecurringOptionListItem { Name = "day " + updatingTask.When.Day + " of every month" });
                            this.recurringOptionListPicker.SelectedIndex = 6;
                        }
                        break;
                }
            }

            if (categoryCount < App.ViewModel.CategoryList.Count)
                this.categoryListPicker.SelectedIndex = 0;
            categoryCount = App.ViewModel.CategoryList.Count;
        }
 private void detach_Task(Task item)
 {
     NotifyPropertyChanging("Task");
     item.Skill = null;
 }
 private void attach_Task(Task item)
 {
     NotifyPropertyChanging("Task");
     item.Skill = this;
 }