/// <summary> /// 搜索 /// </summary> private void Search(object sender, RoutedEventArgs e) { var db = App.conn; ViewModel = new ViewModels.ListItemViewModel(); string content = searchBox.Text.Trim(); if (content != "") { string searchSQL = @"SELECT * FROM Items WHERE Title LIKE '%" + content + "%' " + "OR Details LIKE '%" + content + "%' " + "OR Date LIKE '%" + content + "%'"; using (var statement = db.Prepare(searchSQL)) { while (SQLiteResult.DONE != statement.Step()) { string tid = statement[0].ToString(); string ttitle = statement[1].ToString(); string tdetails = statement[2].ToString(); string ddate = statement[3].ToString(); string ttag = statement[4].ToString(); DateTime ddateconvert = Convert.ToDateTime(ddate); ViewModel.AddListItem(ttitle, tdetails, ttag, ddateconvert); } } Frame root = Window.Current.Content as Frame; App.ViewModel = ViewModel; root.Navigate(typeof(MainPage)); } }
private void Tags_SelectionChanged(object sender, SelectionChangedEventArgs e) { var db = App.conn; ViewModel = new ViewModels.ListItemViewModel(); if (Tags.SelectedValue.ToString() != "全部") { string searchSQL = @"SELECT * FROM Items WHERE Tag = '" + Tags.SelectedValue.ToString() + "'"; using (var statement = db.Prepare(searchSQL)) { while (SQLiteResult.DONE != statement.Step()) { string tid = statement[0].ToString(); string ttitle = statement[1].ToString(); string tdetails = statement[2].ToString(); string ddate = statement[3].ToString(); string ttag = statement[4].ToString(); DateTime ddateconvert = Convert.ToDateTime(ddate); ViewModel.AddListItem(ttitle, tdetails, ttag, ddateconvert); } } } else { using (var statement = App.conn.Prepare("select * from Items")) { while (statement.Step() != SQLiteResult.DONE) { string tid = statement[0].ToString(); string ttitle = statement[1].ToString(); string tdetails = statement[2].ToString(); string ddate = statement[3].ToString(); string ttag = statement[4].ToString(); DateTime ddateconvert = Convert.ToDateTime(ddate); ViewModel.AddListItem(ttitle, tdetails, ttag, ddateconvert); } } } Frame root = Window.Current.Content as Frame; App.ViewModel = ViewModel; root.Navigate(typeof(MainPage)); }
public MainPage() { var db = App.conn; using (var statement = db.Prepare("SELECT * FROM Tags")) { while (SQLiteResult.DONE != statement.Step()) { tags.Add((string)statement[0]); } } tags.Add("全部"); if (App.ViewModel != null) { ViewModel = App.ViewModel; App.ViewModel = null; } else { ViewModel = new ViewModels.ListItemViewModel(); using (var statement = App.conn.Prepare("select * from Items")) { while (statement.Step() != SQLiteResult.DONE) { string tid = statement[0].ToString(); string ttitle = statement[1].ToString(); string tdetails = statement[2].ToString(); string ddate = statement[3].ToString(); string ttag = statement[4].ToString(); DateTime ddateconvert = Convert.ToDateTime(ddate); ViewModel.AddListItem(ttitle, tdetails, ttag, ddateconvert); } } } this.InitializeComponent(); }