public void loadDataCat(int page = 1) { var db = new DIVINGSUITEntities(); var lsCat = db.Categories.ToList(); started = true; currentPage = page; int itemsPerPage = int.Parse((cmbItemsPerPage.SelectedItem as ComboBoxItem).Content.ToString()); var query = from c in lsCat.Skip((page - 1) * itemsPerPage).Take(itemsPerPage) where c.Exist == true select c; int totalItems = lsCat.Count; totalPages = totalItems / itemsPerPage; if (totalPages == 0) { currentPage = 0; } int m = totalItems % itemsPerPage; if (m > 0) { totalPages++; } dtgCategory.ItemsSource = query; lblPageStatus.Content = $"Page {currentPage} of {totalPages}"; }
private void txtKeyword_TextChanged(object sender, TextChangedEventArgs e) { var db = new DIVINGSUITEntities(); var lsPro = db.Products.ToList(); var keyword = txtKeyword.Text; var query = from p in lsPro where p.ProName.ToLower().Contains(keyword.ToLower()) select p; dtgProduct.ItemsSource = query; }
private void btnDel_Click(object sender, RoutedEventArgs e) { Category cat = (Category)dtgCategory.SelectedItem; cat.Exist = false; var db = new DIVINGSUITEntities(); db.Entry(cat).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); loadDataCat(); }
private void txtKeyword_TextChanged(object sender, TextChangedEventArgs e) { var db = new DIVINGSUITEntities(); var lsCat = db.Categories.ToList(); var keyword = txtKeyword.Text; var query = from c in lsCat where c.CatName.ToLower().Contains(keyword.ToLower()) && c.Exist == true select c; dtgCategory.ItemsSource = query; }
public void updateDataPro(int page = 1) { var db = new DIVINGSUITEntities(); var lsPro = db.Products.ToList(); started = true; currentPage = page; itemsPerPage = int.Parse((cmbItemsPerPage.SelectedItem as ComboBoxItem).Content.ToString()); totalPages = lsPro.Count / itemsPerPage; int m = lsPro.Count % itemsPerPage; if (m > 0) { totalPages++; } var query = lsPro.Skip((page - 1) * itemsPerPage).Take(itemsPerPage); dtgProduct.ItemsSource = query; lblPageStatus.Content = $"Page {currentPage} of {totalPages}"; }