Example #1
0
        //private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        //{
        //    if (this.bookname.Text.Equals("书名"))
        //    {
        //        this.bookname.Text = "";
        //        this.bookname.Foreground = new SolidColorBrush(Color.FromArgb(255,0,0,0));
        //    }
        //}



        private void save_clicked(object sender, EventArgs e)
        {
            plan.DatePicker = this.datePicker.ValueString;
            plan.Priority   = (string)this.prioritylist.SelectedItem;
            plan.IsReminder = (bool)this.toggle.IsChecked;
            plan.RingTime   = this.timepicker.ValueString;
            plan.Detail     = this.detail.Text.ToString();

            if (plan.IsReminder)
            {
                plan.Image = "/Icon/feature.alarm.png";

                string clockname = "alarm" + plan.ISBN;
                //IEnumerable <Alarm> list = ScheduledActionService.GetActions<Alarm>();


                if (isRemind)
                {
                    if (ScheduledActionService.Find(clockname) != null)
                    {
                        ScheduledActionService.Remove(clockname);
                    }
                }
                Alarm clock = new Alarm(clockname);
                //开始时间(注意考虑开始时间小于系统时间的情况)
                DateTime beginTime = (DateTime)this.timepicker.Value;
                TimeSpan timespan  = beginTime.TimeOfDay;
                if (beginTime < DateTime.Now)
                {
                    DateTime date = DateTime.Now.AddDays(1).Date;

                    beginTime = date + timespan;

                    Debug.WriteLine("[Debug]date:" + date + "timespan" + timespan + "beginTime.TimeOfDay" + beginTime);
                }
                clock.BeginTime = beginTime;
                //结束时间
                //clock.ExpirationTime = clock.BeginTime + new TimeSpan(0, 0, 30);

                DateTime expirationtime = (DateTime)this.datePicker.Value + timespan;
                Debug.WriteLine("[Debug]expirationtime:" + expirationtime);

                if (expirationtime < beginTime)
                {
                    MessageBox.Show("截止提醒时间已过,请修改截止时间或提醒时间");
                    return;
                }
                clock.ExpirationTime = expirationtime;

                //提醒内容
                clock.Content = "别忘了今天要读<<" + plan.Title + ">>.";


                //提醒铃声
                clock.Sound = new Uri("/SleepAway.mp3", UriKind.Relative);

                //提醒类型
                clock.RecurrenceType = RecurrenceInterval.Daily;

                ScheduledActionService.Add(clock);
            }
            else
            {
                plan.Image = "";

                string clockname = "alarm" + plan.ISBN;
                if (isRemind)
                {
                    if (ScheduledActionService.Find(clockname) != null)
                    {
                        ScheduledActionService.Remove(clockname);
                    }
                }
            }

            Debug.WriteLine("[DEBUG]plan.userid: " + plan.UserId + "plan.ISBN;" + plan.ISBN + "plan.title:" + plan.Title +
                            "plan.dataPicker:" + plan.DatePicker + "plan.priority;" + plan.Priority + "plan.IsReminder:" + plan.IsReminder + "plan.ringtime:" + plan.RingTime
                            + "plan.Detail:" + plan.Detail);

            bool result = bookService.updateReadingPlan(plan);

            if (result)
            {
                //MessageBox.Show("succeed!");

                //NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative));
                NavigationService.GoBack();
            }
            else
            {
                MessageBox.Show("failed!");
            }
        }