Exemplo n.º 1
0
 private void RemoveMeal(Meal meal)
 {
     Sql.ExecuteNonQuery("DELETE FROM meals WHERE id=" + meal.Id);
     LoadMeals();
     UpdateMealTree();
 }
Exemplo n.º 2
0
        private void LoadMeals()
        {
            meals.Clear();

            SQLiteCommand command = Sql.SqlConnection.CreateCommand();
            command.CommandText = "SELECT id,foodId,date FROM meals";
            using(SQLiteDataReader reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int id = reader.GetInt32(0);
                        int foodId = reader.GetInt32(1);
                        DateTime date = reader.GetDateTime(2);
                        Food food = foods.Where(f => f.Id == foodId).Single();
                        Meal meal = new Meal(id, food, date);
                        meals.Add(meal);
                    }
                }
            }
        }