private void btnFilter_Click(object sender, EventArgs e) { flpFood.Controls.Clear(); int?cateId = (cbbFoodCates.SelectedItem as dynamic).Value; using (var DbContext = new AppContext()) { if (cateId != null && tbKeyword.Text != "") { foods = DbContext.Foods .Where(f => f.FoodCategoryId == cateId) .Where(f => f.Name.Contains(tbKeyword.Text)).ToList(); } else if (cateId != null) { foods = DbContext.Foods .Where(f => f.FoodCategoryId == cateId).ToList(); } else if (tbKeyword.Text != "") { foods = DbContext.Foods .Where(f => f.Name.Contains(tbKeyword.Text)).ToList(); } else { foods = DbContext.Foods.ToList(); } } foods.ForEach(x => { ucFood uc = new ucFood(x); flpFood.Controls.Add(uc); }); }
private void LoadFood() { flpFood.Controls.Clear(); using (var DbContext = new AppContext()) { foods = DbContext.Foods.ToList(); } foods.ForEach(e => { ucFood uc = new ucFood(e); uc.changeFoodCount += new EventHandler <Events.BillInfoArg>(ucFood_changeFoodCount); flpFood.Controls.Add(uc); }); }