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

            plan = GetSeletcedPlan();

            bookService = BookService.getInstance();

            List<string> pl = new List<string>() { "高", "中", "低" };
            this.prioritylist.ItemsSource = pl;

            this.prioritylist.SelectedItem = plan.Priority;

            this.bookname.Text = plan.Title;
            //this.bookname.IsEnabled = false;
            this.bookname.IsReadOnly = true;
            this.bookname.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));

            if (flag)
            {
                this.datePicker.Value = DateTime.Parse(plan.DatePicker);
                this.timepicker.Value = DateTime.Parse(plan.RingTime);
                flag = false;
            }

            this.detail.Text = plan.Detail;

            this.toggle.IsChecked = plan.IsReminder;

            isRemind = plan.IsReminder;
        }
        //删除计划
        private void DeletePlan_Click(object sender, RoutedEventArgs e)
        {
            Button      b    = (Button)sender;
            ReadingPlan plan = b.DataContext as ReadingPlan;

            MessageBoxResult result = MessageBox.Show("确认删除?",
                                                      "删除计划", MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                //删除计划
                bookService.deletePlan(plan);
                //删除闹钟

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

            //RefreshWishBookList();

            //新增
            RefreshReadingPlanItems();

            RefreshBookList();
            //RefreshFinishBookList();
        }
Exemple #3
0
        private ReadingPlan GetSeletcedPlan()
        {
            string      planid;
            ReadingPlan selectedplan = null;

            if (NavigationContext.QueryString.TryGetValue("planID", out planid))
            {
                dbPath = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "jadeface.sqlite"));
                dbConn = new SQLiteConnection(dbPath);
                int                Id      = Int32.Parse(planid);
                SQLiteCommand      command = dbConn.CreateCommand("select * from readingplan where Id = " + Id);
                List <ReadingPlan> plans   = command.ExecuteQuery <ReadingPlan>();
                if (plans.Count == 1)
                {
                    selectedplan = plans.First();
                }
            }
            else
            {
                MessageBox.Show("编辑计划出错!");
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }

            return(selectedplan);
        }
        //编辑计划
        private void EditPlan_Click(object sender, RoutedEventArgs e)
        {
            Button      b    = (Button)sender;
            ReadingPlan plan = b.DataContext as ReadingPlan;

            NavigationService.Navigate(new Uri("/EditReadingPlan.xaml?planID=" + plan.Id, UriKind.Relative));
        }
        //显示计划中书籍详细信息
        private void ReadingPlanBookDetail_Click(object sender, RoutedEventArgs e)
        {
            Button      b    = (Button)sender;
            ReadingPlan plan = b.DataContext as ReadingPlan;

            string isbn = plan.ISBN;

            Debug.WriteLine("the ISBN is:" + isbn);
            NavigationService.Navigate(new Uri("/BookDetailPage.xaml?BookISBN=" + plan.ISBN, UriKind.Relative));
        }
 public bool deletePlan(ReadingPlan plan)
 {
     if (plan.Id.Equals(""))
     {
         return false;
     }
     Debug.WriteLine("delete from readingplan where Id = " + plan.Id);
     SQLiteCommand command = dbConn.CreateCommand("delete from readingplan where Id = " + plan.Id);
     command.ExecuteQuery<ReadingPlan>();
     return true;
 }
        public bool deletePlan(ReadingPlan plan)
        {
            if (plan.Id.Equals(""))
            {
                return(false);
            }
            Debug.WriteLine("delete from readingplan where Id = " + plan.Id);
            SQLiteCommand command = dbConn.CreateCommand("delete from readingplan where Id = " + plan.Id);

            command.ExecuteQuery <ReadingPlan>();
            return(true);
        }
        public bool updateReadingPlan(ReadingPlan plan)
        {
            if (plan.UserId == null || plan.Title == null || plan.ISBN == null || plan.UserId.Equals("") || plan.Title.Equals("") || plan.ISBN.Equals(""))
            {
                return(false);
            }

            if (dbConn.Update(plan) > 0)
            {
                return(true);
            }

            return(false);
        }
        //readingplan
        public bool insertPlan(ReadingPlan plan)
        {
            if (plan.UserId == null || plan.ISBN == null || plan.UserId.Equals("") || plan.ISBN.Equals(""))
            {
                return(false);
            }

            if (dbConn.Insert(plan) > 0)
            {
                return(true);
            }

            return(false);
        }
Exemple #10
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);


            plan = GetSeletcedPlan();



            bookService = BookService.getInstance();

            List <string> pl = new List <string>()
            {
                "高", "中", "低"
            };

            this.prioritylist.ItemsSource = pl;

            this.prioritylist.SelectedItem = plan.Priority;

            this.bookname.Text = plan.Title;
            //this.bookname.IsEnabled = false;
            this.bookname.IsReadOnly = true;
            this.bookname.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));

            if (flag)
            {
                this.datePicker.Value = DateTime.Parse(plan.DatePicker);
                this.timepicker.Value = DateTime.Parse(plan.RingTime);
                flag = false;
            }


            this.detail.Text = plan.Detail;

            this.toggle.IsChecked = plan.IsReminder;

            isRemind = plan.IsReminder;
        }
        //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)
        {
            int index = booknamelist.SelectedIndex;

            Debug.WriteLine("index :" + index);
            if (index >= 0)
            {
                List <ReadingPlan> items = bookService.searchReadingPlanByISBN(bl[booknamelist.SelectedIndex].ISBN, phoneAppServeice.State["username"].ToString());
                Debug.WriteLine("the count of items is :" + items.Count);
                if (items.Count > 0)
                {
                    MessageBox.Show("这本书已在计划列表,如需要修改,可以选择编辑按钮");
                    return;
                }
                ReadingPlan plan = new ReadingPlan();
                plan.UserId = phoneAppServeice.State["username"].ToString();
                plan.ISBN   = bl[booknamelist.SelectedIndex].ISBN;

                plan.Title      = (string)this.booknamelist.SelectedItem;
                plan.DatePicker = this.datePicker.ValueString;
                //plan.DatePicker = this.datePicker.Value.ToString();
                plan.Priority   = (string)this.prioritylist.SelectedItem;
                plan.IsReminder = (bool)this.toggle.IsChecked;
                plan.RingTime   = this.timepicker.ValueString;
                //plan.RingTime = this.timepicker.Value.ToString();
                plan.Detail = this.detail.Text.ToString();

                if (plan.IsReminder)
                {
                    plan.Image = "/Icon/feature.alarm.png";
                    string clockname = "alarm" + plan.ISBN;
                    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);

                    Debug.WriteLine("[DEBUG]clock.BeginTime: " + clock.BeginTime + "  clock.ExpirationTime;" + clock.ExpirationTime + "  clock.Content:" + clock.Content +
                                    "  clock.Sound:" + clock.Sound + "  clock.RecurrenceType;" + clock.RecurrenceType);
                }
                else
                {
                    plan.Image = "";
                }

                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.insertPlan(plan);
                if (result)
                {
                    //MessageBox.Show("succeed!");

                    //NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative));
                    NavigationService.GoBack();
                }
                else
                {
                    MessageBox.Show("failed!");
                }
            }
            else
            {
                MessageBox.Show("请先添加书到\"在读的书\"列表中");
            }
        }
        //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)
        {
            int index = booknamelist.SelectedIndex;

            Debug.WriteLine("index :" + index);
            if (index >= 0)
            {
                List<ReadingPlan> items = bookService.searchReadingPlanByISBN(bl[booknamelist.SelectedIndex].ISBN, phoneAppServeice.State["username"].ToString());
                Debug.WriteLine("the count of items is :" + items.Count);
                if (items.Count > 0)
                {
                    MessageBox.Show("这本书已在计划列表,如需要修改,可以选择编辑按钮");
                    return;
                }
                ReadingPlan plan = new ReadingPlan();
                plan.UserId = phoneAppServeice.State["username"].ToString();
                plan.ISBN = bl[booknamelist.SelectedIndex].ISBN;

                plan.Title = (string)this.booknamelist.SelectedItem;
                plan.DatePicker = this.datePicker.ValueString;
                //plan.DatePicker = this.datePicker.Value.ToString();
                plan.Priority = (string)this.prioritylist.SelectedItem;
                plan.IsReminder = (bool)this.toggle.IsChecked;
                plan.RingTime = this.timepicker.ValueString;
                //plan.RingTime = this.timepicker.Value.ToString();
                plan.Detail = this.detail.Text.ToString();

                if (plan.IsReminder)
                {
                    plan.Image = "/Icon/feature.alarm.png";
                    string clockname = "alarm" + plan.ISBN;
                    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);

                    Debug.WriteLine("[DEBUG]clock.BeginTime: " + clock.BeginTime + "  clock.ExpirationTime;" + clock.ExpirationTime + "  clock.Content:" + clock.Content +
                    "  clock.Sound:" + clock.Sound + "  clock.RecurrenceType;" + clock.RecurrenceType);

                }
                else
                {
                    plan.Image = "";
                }

                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.insertPlan(plan);
                if (result)
                {
                    //MessageBox.Show("succeed!");

                    //NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative));
                    NavigationService.GoBack();
                }
                else
                {
                    MessageBox.Show("failed!");
                }
            }
            else
            {
                MessageBox.Show("请先添加书到\"在读的书\"列表中");
            }
        }
        public bool updateReadingPlan(ReadingPlan plan)
        {
            if (plan.UserId == null || plan.Title == null || plan.ISBN == null || plan.UserId.Equals("") || plan.Title.Equals("") || plan.ISBN.Equals(""))
            {
                return false;
            }

            if (dbConn.Update(plan) > 0)
            {
                return true;
            }

            return false;
        }
        //readingplan
        public bool insertPlan(ReadingPlan plan)
        {
            if (plan.UserId == null || plan.ISBN == null || plan.UserId.Equals("") || plan.ISBN.Equals(""))
            {
                return false;
            }

            if (dbConn.Insert(plan) > 0)
            {
                return true;
            }

            return false;
        }