Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. public ArrayList GetAll()
  2.         {
  3.             ArrayList DishList = new ArrayList();
  4.  
  5.             using (SqlConnection connection = new SqlConnection(connectString))
  6.             {
  7.                 SqlCommand command = new SqlCommand("SELECT * FROM Dish;", connection);
  8.                 connection.Open();
  9.  
  10.                 SqlDataReader reader = command.ExecuteReader();
  11.  
  12.                 if (reader.HasRows)
  13.                 {
  14.                     while (reader.Read())
  15.                     {
  16.                         int IdDish = reader.GetInt32(0);
  17.                         string NameDish = reader.GetString(1);
  18.                         int PriceDish = reader.GetInt32(2);
  19.                         byte[] ImageDish = (byte[])reader[3];
  20.                         int CatIdDish = reader.GetInt32(4);
  21.                         string CatNameDish = GetCategoryName(CatIdDish);
  22.  
  23.                         DishList.Add(new DishData() { Id = IdDish, Name = NameDish, Price = PriceDish, CatId = CatIdDish, CatName = CatNameDish, Image = ImageDish});
  24.                     }
  25.                 }
  26.                 reader.Close();
  27.  
  28.                 return DishList;
  29.             }
  30.         }
  31.  
  32. private void LoadDishGridView()
  33.         {
  34.             DishGridView.Rows.Clear();
  35.  
  36.             if (CategoriesComboBox.SelectedIndex == 0)
  37.             {
  38.                 btnEditCat.Enabled = false;
  39.  
  40.                 foreach (DishData Dish in _Dish.GetAll())
  41.                 {
  42.                     DishGridView.Rows.Add(Dish.Id, Dish.Name, Dish.Price, Dish.CatName, Dish.Image);
  43.                 }
  44.             }
  45.             else if (CategoriesComboBox.SelectedIndex > 0)
  46.             {
  47.                 btnEditCat.Enabled = true;
  48.                 string CategoryName = CategoriesComboBox.SelectedItem.ToString();
  49.  
  50.                 int CategoryID = _Category.GetId(CategoryName);
  51.                 foreach (DishData Dish in _Dish.GetAllfromCat(CategoryID))
  52.                 {
  53.                     DishGridView.Rows.Add(Dish.Id, Dish.Name, Dish.Price, CategoryName, Dish.Image);
  54.                 }
  55.             }
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement