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(); } }
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); } }
//进入时注册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(); }
public MainPage() { this.InitializeComponent(); MySQLiteHelper.createDB(); }