Ejemplo n.º 1
0
        private void SureButton_Click(object sender, RoutedEventArgs e)
        {
            SQLiteConnection db    = MySQLiteHelper.CreateSQLiteConnection();
            List <object>    query = db.Query(new TableMapping(typeof(ActivityInfo)), "select * from ActivityInfo");

            //如果出现置顶,将其他置顶设为false
            if ((bool)isTopSwitch.IsOn == true)
            {
                foreach (ActivityInfo mem in query)
                {
                    mem.isTop = false;
                    db.Update(mem);
                }
            }
            foreach (ActivityInfo mem in query)
            {
                if (mem.ID == ID)
                {
                    mem.Date  = MyDate.Date.Date;
                    mem.isTop = (bool)isTopSwitch.IsOn;
                    if (Title.Text == String.Empty)
                    {
                        Title.Text = "某天";
                    }
                    mem.Theme   = Title.Text;
                    mem.Content = TextSource.Text;
                    db.Update(mem);
                }
            }



            db.Close();
            Frame.Navigate(typeof(MainPage));
        }
Ejemplo n.º 2
0
        private ObservableCollection <ActivityListViewItem> SelectAll()
        {
            ObservableCollection <ActivityListViewItem> list = new ObservableCollection <ActivityListViewItem>();

            using (var db = MySQLiteHelper.CreateSQLiteConnection())
            {
                List <object> query = db.Query(new TableMapping(typeof(ActivityInfo)), "select * from ActivityInfo");

                foreach (ActivityInfo mem in query)
                {
                    ActivityInfo ai = mem;

                    //删除已过期的日子
                    if ((int)(ai.Date - DateTime.Now.Date).TotalDays < 0)
                    {
                        db.Delete(mem);
                    }
                    else
                    {
                        ActivityListViewItem info = new ActivityListViewItem()
                        {
                            ID    = ai.ID,
                            Theme = ai.Theme,
                            Date  = (int)(ai.Date - DateTime.Now.Date).TotalDays
                        };
                        list.Add(info);
                    }
                }
                db.Close();
            }
            return(list);
        }
Ejemplo n.º 3
0
 private void deleteButton_Click(object sender, RoutedEventArgs e)
 {
     if (MyListView.SelectedItems.Count > 0)
     {
         ActivityListViewItem temp = new ActivityListViewItem();
         temp = (ActivityListViewItem)MyListView.SelectedItems[0];
         var db = MySQLiteHelper.CreateSQLiteConnection();
         db.Delete <ActivityInfo>(temp.ID);
         init();
     }
 }
Ejemplo n.º 4
0
        private ObservableCollection <ActivityListViewItem> SelectTop()
        {
            ObservableCollection <ActivityListViewItem> list = new ObservableCollection <ActivityListViewItem>();

            using (var db = MySQLiteHelper.CreateSQLiteConnection())
            {
                List <object> query = db.Query(new TableMapping(typeof(ActivityInfo)), "select * from ActivityInfo");

                if (query.Count == 0)
                {
                    return(list);
                }
                ActivityInfo nearest = (ActivityInfo)query[0];
                foreach (ActivityInfo mem in query)
                {
                    ActivityInfo ai = mem;

                    if (ai.isTop == true)
                    {
                        ActivityListViewItem info = new ActivityListViewItem()
                        {
                            ID    = ai.ID,
                            Theme = ai.Theme,
                            Date  = (int)(ai.Date - DateTime.Now.Date).TotalDays
                        };
                        list.Add(info);
                        db.Close();
                        return(list);
                    }
                    else
                    {
                        //选取不过期,但最近的日子
                        if ((int)(ai.Date - DateTime.Now.Date).TotalDays > 0 && (int)(ai.Date - nearest.Date).TotalDays < 0)
                        {
                            nearest = ai;
                        }
                    }
                }

                ActivityListViewItem near = new ActivityListViewItem()
                {
                    ID    = nearest.ID,
                    Theme = nearest.Theme,
                    Date  = (int)(nearest.Date - DateTime.Now.Date).TotalDays
                };
                list.Add(near);
                db.Close();
                return(list);
            }
        }
Ejemplo n.º 5
0
        //进入时注册DataRequested事件
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ID  = (int)e.Parameter;
            dtm = DataTransferManager.GetForCurrentView();
            SQLiteConnection db = MySQLiteHelper.CreateSQLiteConnection();

            //初始化界面设置
            List <object> query = db.Query(new TableMapping(typeof(ActivityInfo)), "select * from ActivityInfo");

            foreach (ActivityInfo mem in query)
            {
                if (mem.ID == ID)
                {
                    Title.Text       = mem.Theme;
                    TextSource.Text  = mem.Content;
                    MyDate.Date      = mem.Date;
                    isTopSwitch.IsOn = mem.isTop;
                }
            }
            db.Close();
        }