private void InitializeItems()
        {
            this.todos_Today = (App.Current as App).todos_Today;
            Todo todo = new Todo();
            todo.Name = "Good";
            todo.Options = new List<Thing>()
            {
                new Thing()
            };

            this.todos_Today.Add(todo);
        }
Пример #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 居然还要判断是不是从当前页面的子页面导航回来的
            // 因为在选择日期时,确定后会再次触发OnNavigatedTo事件,会再进行一次赋值
            // 为了避免这种情况发生,要设一个标志位。。。
            if (inPage)
            {
                base.OnNavigatedTo(e);
                return;
            }

            NavigationContext.QueryString.TryGetValue("action", out msg);

            // 如果导航来时有edit参数,则代表要修改一个项目
            if (msg == "edit")
            {
                // 获取要修改的todo
                todo_edit = (App.Current as App).todo_edit;

                contentBox.Text = todo_edit.Name;
                AlarmToggle.IsChecked = todo_edit.HasAlarm;

                DatePicker.Value = todo_edit.AlarmTime;
                TimePicker.Value = todo_edit.AlarmTime;
                ImportanceToggle.IsChecked = todo_edit.Importance;
                ForwardListPicker.SelectedIndex = 1;

                string page = null;
                if(NavigationContext.QueryString.TryGetValue("page", out page))
                {
                    if (page == "1")
                    {
                        AlarmToggle.IsChecked = true;
                        editPivot.SelectedIndex = 1;
                    }
                }
            }

            // 如果导航来时有addnew参数,则代表要添加一个新的项目
            else if (msg == "addnew")
            {
                ImportanceToggle.IsChecked = false;
                AlarmToggle.IsChecked = false;
                DatePicker.Value = DateTime.Now;
                TimePicker.Value = DateTime.Now;

                ForwardListPicker.SelectedIndex = 1;
            }

            inPage = true;
            base.OnNavigatedTo(e);
        }
Пример #3
0
        /// <summary>
        /// 将从XML文件获取的列表读取到内存中
        /// </summary>
        /// <param name="collect"></param>
        /// <param name="todos"></param>
        private void GetItemsFromXml(IEnumerable<XElement> collect,
            ObservableCollection<Todo> todos)
        {
            foreach (var item in collect)
            {
                Todo todo = new Todo();
                todo.Options = new List<Thing>
                {
                    new Thing()
                };

                // 根据文件内容进行变动
                todo.Name = item.Element("Name").Value;
                todo.HasAlarm = todo.Options.First().HasAlarm = to_bool(item.Element("HasAlarm").Value);
                todo.IsCompleted = todo.Options.First().IsCompleted = to_bool(item.Element("Completed").Value);
                todo.AlarmTime = DateTime.Parse(item.Element("AlarmTime").Value);

                // 闹钟时间早于当前时间了,就意味着这个闹钟已经被消除了
                if (todo.HasAlarm && todo.AlarmTime < DateTime.Now)
                {
                    todo.HasAlarm = todo.Options.First().HasAlarm = false;
                    todo.IsCompleted = true;
                    todo.Options.First().IsCompleted = true;
                }

                todo.Importance = to_bool(item.Element("Importance").Value);
                todo.IsExpanded = false;
                todo.ReminderName = item.Element("ReminderName").Value;

                todos.Add(todo);
            }
        }
Пример #4
0
        /// <summary>
        /// 构建初次运行的数据
        /// </summary>
        /// <returns>ObservableCollection<Todo></returns>
        private ObservableCollection<Todo> BuildFirstRunData()
        {
            ObservableCollection<Todo> firstRunTodos = new ObservableCollection<Todo>();

            for (int i = 0; i < 5; i++)
            {
                Todo todo = new Todo();

                todo.Options = new List<Thing>()
                {
                    new Thing()
                };

                todo.IsCompleted = false;
                todo.Options.First().IsCompleted = false;
                todo.Importance = false;
                todo.HasAlarm = false;
                todo.Options.First().HasAlarm = false;
                todo.ReminderName = System.Guid.NewGuid().ToString();
                firstRunTodos.Add(todo);
            }

            firstRunTodos.ElementAt(0).Name = "向右滑以标记为完成";
            firstRunTodos.ElementAt(1).Name = "向左滑以标记为未完成";
            firstRunTodos.ElementAt(1).IsCompleted = true;
            firstRunTodos.ElementAt(1).Options.First().IsCompleted = true;
            firstRunTodos.ElementAt(2).Name = "长按以删除";
            firstRunTodos.ElementAt(3).Name = "点击条目并添加闹钟";
            firstRunTodos.ElementAt(4).Name = "点击条目并进行编辑";

            return firstRunTodos;
        }
Пример #5
0
        private void expandes_click(object sender, RoutedEventArgs e)
        {
            // 因为点击子项也属于点击该Item,所以要判断上次的点击
            // 是否来自子项,如果是,则不进行Expand的处理
            if (isFromExpandedItem)
            {
                isFromExpandedItem = false;
                return;
            }

            // 获取被点击的todo
            todo = ListBox_Today.SelectedItem as Todo;

            if ((lastTodo != null) & (lastTodo != todo))
            {
                lastTodo.IsExpanded = false;
            }

            isFromExpandedItem = false;
            lastTodo = todo;
        }
Пример #6
0
        private void save(object sender, EventArgs e)
        {
            if (contentBox.Text == "")
            {
                MessageBox.Show("您还没有填写内容哦~", "友情提示", MessageBoxButton.OK);
                editPivot.SelectedIndex = 0;
                return;
            }

            if (msg == "edit")
            {
                // 存储修改项的内容
                todo_edit.Name = contentBox.Text;

                // 时间设置有误
                if ((todo_edit.AlarmTime = GetMeAlarmTime()) == DateTime.MinValue)
                {
                    MessageBox.Show("您设置的闹钟时间比当前时间早哟~", "友情提示", MessageBoxButton.OK);
                    return;
                }

                // 既然进行了编辑,就意味着任务未完成
                todo_edit.IsCompleted = todo_edit.Options.First().IsCompleted = false;
                todo_edit.HasAlarm = todo_edit.Options.First().HasAlarm =  (bool)AlarmToggle.IsChecked;
                todo_edit.Importance = (bool)ImportanceToggle.IsChecked;

                if (todo_edit.HasAlarm)
                {
                    Reminder reminder = new Reminder(todo_edit.ReminderName);
                    reminder.Title = "提醒";
                    reminder.Content = todo_edit.Name;
                    reminder.BeginTime = todo_edit.AlarmTime;

                    if (ScheduledActionService.Find(reminder.Name) != null)
                    {
                        ScheduledActionService.Remove(reminder.Name);
                        ScheduledActionService.Add(reminder);
                    }
                    else
                    {
                        ScheduledActionService.Add(reminder);
                    }
                }
            }
            else if (msg == "addnew")
            {
                string date = DatePicker.Value.Value.ToShortDateString();
                string time = TimePicker.Value.Value.ToShortTimeString();

                Todo todo = new Todo();
                Thing thing = new Thing();

                todo.Name = contentBox.Text;

                // 时间设置有误
                if ((todo.AlarmTime = GetMeAlarmTime()) == DateTime.MinValue)
                {
                    MessageBox.Show("您设置的闹钟时间比当前时间早哟~", "友情提示", MessageBoxButton.OK);
                    return;
                }

                todo.IsCompleted = thing.IsCompleted = false;
                todo.HasAlarm = thing.HasAlarm = (bool)AlarmToggle.IsChecked;
                todo.Importance = (bool)ImportanceToggle.IsChecked;

                // 使用GUID作为每一个todo的ReminderName
                todo.ReminderName = System.Guid.NewGuid().ToString();
                todo.IsExpanded = false;
                todo.Options = new List<Thing>();
                todo.Options.Add(thing);

                (App.Current as App).todos_Today.Add(todo);

                if (todo.HasAlarm)
                {
                    Reminder reminder = new Reminder(todo.ReminderName);
                    reminder.Title = "提醒";
                    reminder.Content = todo.Name;
                    reminder.BeginTime = todo.AlarmTime;

                    ScheduledActionService.Add(reminder);
                }
            }

            inPage = false;
            NavigationService.GoBack();
        }