public UserControlFoodPlan(MainAppWindow main)
 {
     this.user1 = main.user;
     InitializeComponent();
     if (DataBaseSolution.FoodPlanExist(user1) == true)
     {
         foodplan = DataBaseSolution.GetFoodPlan(user1);
         if (user1.UserMealNumber == 3)
         {
             GridFoodPlan.Children.Clear();
             usc = new UserControlFoodPlanGenerated(foodplan);
             GridFoodPlan.Children.Add(usc);
         }
         if (user1.UserMealNumber == 4)
         {
             GridFoodPlan.Children.Clear();
             usc = new UserControlFoodPlanGenerated4M(foodplan);
             GridFoodPlan.Children.Add(usc);
         }
         if (user1.UserMealNumber == 5)
         {
             GridFoodPlan.Children.Clear();
             usc = new UserControlFoodPlanGenerated5M(foodplan);
             GridFoodPlan.Children.Add(usc);
         }
     }
 }
        private void GenerateButton_Click(object sender, RoutedEventArgs e)
        {
            DataBaseSolution.GetUserData(user1);
            Algorithm algorithm = new Algorithm(user1);

            foodplan = algorithm.GetFoodData();
            if (user1.UserMealNumber == 3)
            {
                GridFoodPlan.Children.Clear();
                usc = new UserControlFoodPlanGenerated(foodplan);
                GridFoodPlan.Children.Add(usc);
            }
            if (user1.UserMealNumber == 4)
            {
                GridFoodPlan.Children.Clear();
                usc = new UserControlFoodPlanGenerated4M(foodplan);
                GridFoodPlan.Children.Add(usc);
            }
            if (user1.UserMealNumber == 5)
            {
                GridFoodPlan.Children.Clear();
                usc = new UserControlFoodPlanGenerated5M(foodplan);
                GridFoodPlan.Children.Add(usc);
            }
        }
示例#3
0
        public UserControlFoodPlanGenerated4M(FoodPlan foodPlan)
        {
            this.food = foodPlan;
            InitializeComponent();

            Name1.Text = "   " + food.meal1.Name;
            Kcal1.Text = "   " + (food.meal1.Caloricity).ToString() + " KCAL";
            Ing1.Text  = "    " + food.meal1.Ingredients;
            Desc1.Text = "    " + food.meal1.Description;

            Name2.Text = "   " + food.meal2.Name;
            Kcal2.Text = "   " + (food.meal2.Caloricity).ToString() + " KCAL";
            Ing2.Text  = "    " + food.meal2.Ingredients;
            Desc2.Text = "    " + food.meal2.Description;

            Name3.Text = "   " + food.meal3.Name;
            Kcal3.Text = "   " + (food.meal3.Caloricity).ToString() + " KCAL";
            Ing3.Text  = "    " + food.meal3.Ingredients;
            Desc3.Text = "    " + food.meal3.Description;

            Name4.Text = "   " + food.meal4.Name;
            Kcal4.Text = "   " + (food.meal4.Caloricity).ToString() + " KCAL";
            Ing4.Text  = "    " + food.meal4.Ingredients;
            Desc4.Text = "    " + food.meal4.Description;
        }
示例#4
0
        public FoodPlan GetFoodData()
        {
            CountMealCaloricty();
            FoodPlan food = new FoodPlan();

            food = DataBaseSolution.GenerateFoodPlan(user);
            DataBaseSolution.SaveFoodPlan(food);
            return(food);
        }
示例#5
0
        public static FoodPlan GetFoodPlan(User user)
        {
            FoodPlan      food          = new FoodPlan();
            SqlConnection sqlConnection = new SqlConnection();

            sqlConnection = DataBaseSolution.Get_DB_Connection();
            string     sql  = "SELECT * FROM [PlanZywieniowy] WHERE IdUzytkownika = @id;";
            SqlCommand cmd1 = new SqlCommand(sql, sqlConnection);

            cmd1.Parameters.AddWithValue("@id", user.UserId);
            using (SqlDataReader read = cmd1.ExecuteReader())
            {
                if (read.Read())
                {
                    food.meal1.MealId = Int32.Parse(read["IdJadlospisu"].ToString());
                }
            }
            food.meal1 = GetMeal(food.meal1.MealId);
            string     sql1 = "SELECT * FROM  [PlanZywieniowy] WHERE(([PoraDnia] LIKE '%Sniadanie%') AND (IdUzytkownika = @id)); ";
            SqlCommand cmd2 = new SqlCommand(sql1, sqlConnection);

            cmd2.Parameters.AddWithValue("@id", user.UserId);
            using (SqlDataReader read = cmd2.ExecuteReader())
            {
                if (read.Read())
                {
                    food.meal2.MealId = Int32.Parse(read["IdJadlospisu"].ToString());
                }
            }
            food.meal2 = GetMeal(food.meal2.MealId);
            string     sql2 = "SELECT * FROM  [PlanZywieniowy] WHERE( ([PoraDnia] LIKE '%II sniadanie/podwieczorek%') AND (IdUzytkownika = @id)); ";
            SqlCommand cmd3 = new SqlCommand(sql2, sqlConnection);

            cmd3.Parameters.AddWithValue("@id", user.UserId);
            using (SqlDataReader read = cmd3.ExecuteReader())
            {
                if (read.Read())
                {
                    food.meal3.MealId = Int32.Parse(read["IdJadlospisu"].ToString());
                }
            }
            food.meal3 = GetMeal(food.meal3.MealId);
            if ((user.UserMealNumber == 4) || (user.UserMealNumber == 5))
            {
                string     sql3 = "SELECT * FROM  [PlanZywieniowy] WHERE( ([PoraDnia] LIKE '%Obiad%') AND (IdUzytkownika = @id)); ";
                SqlCommand cmd4 = new SqlCommand(sql3, sqlConnection);
                cmd4.Parameters.AddWithValue("@id", user.UserId);
                using (SqlDataReader read = cmd4.ExecuteReader())
                {
                    if (read.Read())
                    {
                        food.meal4.MealId = Int32.Parse(read["IdJadlospisu"].ToString());
                    }
                }
                food.meal4 = GetMeal(food.meal4.MealId);
            }
            if (user.UserMealNumber == 5)
            {
                string     sql4 = "SELECT * FROM  [PlanZywieniowy] WHERE( ([PoraDnia] LIKE '%Kolacja%') AND (IdUzytkownika = @id)); ";
                SqlCommand cmd5 = new SqlCommand(sql4, sqlConnection);
                cmd5.Parameters.AddWithValue("@id", user.UserId);
                using (SqlDataReader read = cmd5.ExecuteReader())
                {
                    if (read.Read())
                    {
                        food.meal5.MealId = Int32.Parse(read["IdJadlospisu"].ToString());
                    }
                }
                food.meal5 = GetMeal(food.meal5.MealId);
            }
            return(food);
        }
示例#6
0
        public static void SaveFoodPlan(FoodPlan food)
        {
            Algorithm algorithm = new Algorithm(food.user1);
            float     kcal      = algorithm.FinalKCALResult();

            SqlConnection sqlConnection = new SqlConnection();

            sqlConnection = DataBaseSolution.Get_DB_Connection();

            SqlCommand check_1 = new SqlCommand("SELECT COUNT(*) FROM [PlanZywieniowy] WHERE (([PoraDnia] LIKE '%Sniadanie%') AND [IdUzytkownika] = '" + food.user1.UserId + "');", sqlConnection);
            int        Exist1  = (int)check_1.ExecuteScalar();
            SqlCommand check_2 = new SqlCommand("SELECT COUNT(*) FROM [PlanZywieniowy] WHERE (([PoraDnia] LIKE '%II sniadanie/podwieczorek%') AND [IdUzytkownika] = '" + food.user1.UserId + "');", sqlConnection);
            int        Exist2  = (int)check_1.ExecuteScalar();
            SqlCommand check_3 = new SqlCommand("SELECT COUNT(*) FROM [PlanZywieniowy] WHERE ((([PoraDnia] LIKE '%Obiad%') AND [IdUzytkownika] = '" + food.user1.UserId + "');", sqlConnection);
            int        Exist3  = (int)check_1.ExecuteScalar();
            SqlCommand check_5 = new SqlCommand("SELECT COUNT(*) FROM [PlanZywieniowy] (([PoraDnia] LIKE '%Kolacja%') AND [IdUzytkownika] = '" + food.user1.UserId + "');", sqlConnection);
            int        Exist4  = (int)check_1.ExecuteScalar();

            MessageBox.Show((food.user1.UserMealCaloricty[0], food.user1.UserMealCaloricty[1], food.user1.UserMealCaloricty[2]).ToString());

            if (food.user1.UserMealNumber == 3)
            {
                if ((Exist1 == 0) && (Exist3 == 0) && (Exist4 == 0))

                {
                    string     sql1    = "INSERT INTO PlanZywieniowy (IdUzytkownika, DzienneKCAL, PoraDnia, IDJadlospisu)  Values (@id, @kcal, @pd, @idj);";
                    SqlCommand command = new SqlCommand(sql1, sqlConnection);
                    command.Parameters.AddWithValue("@id", food.user1.UserId);
                    command.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command.Parameters.AddWithValue("@pd", food.meal1.Daytime);
                    command.Parameters.AddWithValue("@idj", food.meal1.MealId);
                    command.ExecuteNonQuery();

                    SqlCommand command1 = new SqlCommand(sql1, sqlConnection);
                    command1.Parameters.AddWithValue("@id", food.user1.UserId);
                    command1.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command1.Parameters.AddWithValue("@pd", food.meal2.Daytime);
                    command1.Parameters.AddWithValue("@idj", food.meal2.MealId);
                    command1.ExecuteNonQuery();

                    SqlCommand command2 = new SqlCommand(sql1, sqlConnection);
                    command2.Parameters.AddWithValue("@id", food.user1.UserId);
                    command2.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command2.Parameters.AddWithValue("@pd", food.meal3.Daytime);
                    command2.Parameters.AddWithValue("@idj", food.meal3.MealId);
                    command2.ExecuteNonQuery();
                }
                else if ((Exist1 > 0))
                {
                    string     sql1    = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command = new SqlCommand(sql1, sqlConnection);
                    command.Parameters.AddWithValue("@id", food.user1.UserId);
                    command.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command.Parameters.AddWithValue("@pd", food.meal1.Daytime);
                    command.Parameters.AddWithValue("@idj", food.meal1.MealId);
                    command.ExecuteNonQuery();
                }

                else if ((Exist3 > 0))
                {
                    string     sql1     = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command1 = new SqlCommand(sql1, sqlConnection);
                    command1.Parameters.AddWithValue("@id", food.user1.UserId);
                    command1.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command1.Parameters.AddWithValue("@pd", food.meal2.Daytime);
                    command1.Parameters.AddWithValue("@idj", food.meal2.MealId);
                    command1.ExecuteNonQuery();
                }
                else if ((Exist4 > 0))
                {
                    string     sql1     = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command2 = new SqlCommand(sql1, sqlConnection);
                    command2.Parameters.AddWithValue("@id", food.user1.UserId);
                    command2.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command2.Parameters.AddWithValue("@pd", food.meal3.Daytime);
                    command2.Parameters.AddWithValue("@idj", food.meal3.MealId);
                    command2.ExecuteNonQuery();
                }
            }
            if (food.user1.UserMealNumber > 3)
            {
                if ((Exist1 == 0) && ((Exist2 == 0 || Exist2 == 1)) && (Exist3 == 0) && (Exist4 == 0))

                {
                    string     sql1    = "INSERT INTO PlanZywieniowy (IdUzytkownika, DzienneKCAL, PoraDnia, IDJadlospisu)  Values (@id, @kcal, @pd, @idj);";
                    SqlCommand command = new SqlCommand(sql1, sqlConnection);
                    command.Parameters.AddWithValue("@id", food.user1.UserId);
                    command.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command.Parameters.AddWithValue("@pd", food.meal1.Daytime);
                    command.Parameters.AddWithValue("@idj", food.meal1.MealId);
                    command.ExecuteNonQuery();

                    SqlCommand command1 = new SqlCommand(sql1, sqlConnection);
                    command1.Parameters.AddWithValue("@id", food.user1.UserId);
                    command1.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command1.Parameters.AddWithValue("@pd", food.meal2.Daytime);
                    command1.Parameters.AddWithValue("@idj", food.meal2.MealId);
                    command1.ExecuteNonQuery();

                    SqlCommand command2 = new SqlCommand(sql1, sqlConnection);
                    command2.Parameters.AddWithValue("@id", food.user1.UserId);
                    command2.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command2.Parameters.AddWithValue("@pd", food.meal3.Daytime);
                    command2.Parameters.AddWithValue("@idj", food.meal3.MealId);
                    command2.ExecuteNonQuery();

                    if ((food.user1.UserMealNumber == 4) || (food.user1.UserMealNumber == 5))
                    {
                        SqlCommand command3 = new SqlCommand(sql1, sqlConnection);
                        command3.Parameters.AddWithValue("@id", food.user1.UserId);
                        command3.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                        command3.Parameters.AddWithValue("@pd", food.meal4.Daytime);
                        command3.Parameters.AddWithValue("@idj", food.meal4.MealId);
                        command3.ExecuteNonQuery();
                    }

                    if ((food.user1.UserMealNumber == 5))
                    {
                        SqlCommand command4 = new SqlCommand(sql1, sqlConnection);
                        command4.Parameters.AddWithValue("@id", food.user1.UserId);
                        command4.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                        command4.Parameters.AddWithValue("@pd", food.meal5.Daytime);
                        command4.Parameters.AddWithValue("@idj", food.meal5.MealId);
                        command4.ExecuteNonQuery();
                    }
                }
                else if ((Exist1 > 0))
                {
                    string     sql1    = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command = new SqlCommand(sql1, sqlConnection);
                    command.Parameters.AddWithValue("@id", food.user1.UserId);
                    command.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command.Parameters.AddWithValue("@pd", food.meal1.Daytime);
                    command.Parameters.AddWithValue("@idj", food.meal1.MealId);
                    command.ExecuteNonQuery();
                }
                else if ((Exist3 > 0))
                {
                    string     sql1     = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command1 = new SqlCommand(sql1, sqlConnection);
                    command1.Parameters.AddWithValue("@id", food.user1.UserId);
                    command1.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command1.Parameters.AddWithValue("@pd", food.meal2.Daytime);
                    command1.Parameters.AddWithValue("@idj", food.meal2.MealId);
                    command1.ExecuteNonQuery();
                }
                else if ((Exist2 > 1))
                {
                    string     sql1     = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command2 = new SqlCommand(sql1, sqlConnection);
                    command2.Parameters.AddWithValue("@id", food.user1.UserId);
                    command2.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command2.Parameters.AddWithValue("@pd", food.meal3.Daytime);
                    command2.Parameters.AddWithValue("@idj", food.meal3.MealId);
                    command2.ExecuteNonQuery();
                }
                else if ((Exist4 > 0))
                {
                    string     sql1     = "UPDATE PlanZywieniowy SET  DzienneKCAL = @kcal, PoraDnia = @pd , IDJadlospisu = @idj WHERE IdUzytkownika = @id;";
                    SqlCommand command2 = new SqlCommand(sql1, sqlConnection);
                    command2.Parameters.AddWithValue("@id", food.user1.UserId);
                    command2.Parameters.AddWithValue("@kcal", algorithm.FinalKCALResult());
                    command2.Parameters.AddWithValue("@pd", food.meal3.Daytime);
                    command2.Parameters.AddWithValue("@idj", food.meal3.MealId);
                    command2.ExecuteNonQuery();
                }
            }
        }
示例#7
0
        public static FoodPlan GenerateFoodPlan(User user)
        {
            Algorithm algorithm = new Algorithm(user);

            algorithm.CountMealCaloricty();
            FoodPlan foodPlan = new FoodPlan();
            //float kcal = algorithm.FinalKCALResult();

            SqlConnection sqlConnection = new SqlConnection();

            sqlConnection = DataBaseSolution.Get_DB_Connection();

            Meal   meal1              = new Meal();
            Meal   meal2              = new Meal();
            Meal   meal3              = new Meal();
            Meal   meal4              = new Meal();
            Meal   meal5              = new Meal();
            string userRestrictions   = user.UserFoodRestrictions;
            string resultRestricitons = "";

            String[] userRestrictions1 = userRestrictions.Split(',');

            /*  foreach (string uFR in userRestrictions1)
             * {
             *    if (uFR == "False") { resultRestricitons += "True,"; }
             *    else { resultRestricitons += "False,"; }
             * }
             * resultRestricitons = resultRestricitons.Substring(0, resultRestricitons.Length - 1);
             * resultRestricitons = "%" + resultRestricitons + "%";
             * resultRestricitons.Trim();*/
            resultRestricitons = userRestrictions;

            if (user.UserMealNumber == 3)
            {
                //ograniczenia
                string sql1 = "SELECT TOP 1 * FROM  Jadlospisy WHERE(([PoraDnia] LIKE '%Sniadanie%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[0] + "'))   ORDER BY NEWID() ; ";// AND ([Ograniczenia] LIKE ('" + resultRestricitons + "'))
                string sql2 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Obiad%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[1] + "'))  ORDER BY NEWID() ; ";
                string sql3 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Kolacja%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[2] + "'))  ORDER BY NEWID() ; ";

                SqlCommand cmd = new SqlCommand(sql1, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal1.MealId             = Int32.Parse(read["Id"].ToString());
                        meal1.Name               = (read["Nazwa"]).ToString();
                        meal1.Daytime            = (read["PoraDnia"]).ToString();
                        meal1.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal1.Description        = (read["Opis"]).ToString();
                        meal1.Ingredients        = (read["Skladniki"]).ToString();
                        meal1.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql2, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal2.MealId             = Int32.Parse(read["Id"].ToString());
                        meal2.Name               = (read["Nazwa"]).ToString();
                        meal2.Daytime            = (read["PoraDnia"]).ToString();
                        meal2.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal2.Description        = (read["Opis"]).ToString();
                        meal2.Ingredients        = (read["Skladniki"]).ToString();
                        meal2.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql3, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal3.MealId             = Int32.Parse(read["Id"].ToString());
                        meal3.Name               = (read["Nazwa"]).ToString();
                        meal3.Daytime            = (read["PoraDnia"]).ToString();
                        meal3.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal3.Description        = (read["Opis"]).ToString();
                        meal3.Ingredients        = (read["Skladniki"]).ToString();
                        meal3.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }

                foodPlan = new FoodPlan(user, meal1, meal2, meal3);
            }

            if (user.UserMealNumber == 4)
            {
                string     sql1 = "SELECT TOP 1 * FROM  Jadlospisy WHERE(([PoraDnia] LIKE '%Sniadanie%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[0] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; ";
                string     sql2 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%II sniadanie/podwieczorek%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[1] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; ";
                string     sql3 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Obiad%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[2] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; ";
                string     sql4 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Kolacja%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[3] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; ";
                SqlCommand cmd  = new SqlCommand(sql1, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal1.MealId             = Int32.Parse(read["Id"].ToString());
                        meal1.Name               = (read["Nazwa"]).ToString();
                        meal1.Daytime            = (read["PoraDnia"]).ToString();
                        meal1.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal1.Description        = (read["Opis"]).ToString();
                        meal1.Ingredients        = (read["Skladniki"]).ToString();
                        meal1.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql2, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal2.MealId             = Int32.Parse(read["Id"].ToString());
                        meal2.Name               = (read["Nazwa"]).ToString();
                        meal2.Daytime            = (read["PoraDnia"]).ToString();
                        meal2.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal2.Description        = (read["Opis"]).ToString();
                        meal2.Ingredients        = (read["Skladniki"]).ToString();
                        meal2.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql3, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal3.MealId             = Int32.Parse(read["Id"].ToString());
                        meal3.Name               = (read["Nazwa"]).ToString();
                        meal3.Daytime            = (read["PoraDnia"]).ToString();
                        meal3.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal3.Description        = (read["Opis"]).ToString();
                        meal3.Ingredients        = (read["Skladniki"]).ToString();
                        meal3.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql4, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal4.MealId             = Int32.Parse(read["Id"].ToString());
                        meal4.Name               = (read["Nazwa"]).ToString();
                        meal4.Daytime            = (read["PoraDnia"]).ToString();
                        meal4.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal4.Description        = (read["Opis"]).ToString();
                        meal4.Ingredients        = (read["Skladniki"]).ToString();
                        meal4.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                foodPlan = new FoodPlan(user, meal1, meal2, meal3, meal4);
            }

            if (user.UserMealNumber == 5)
            {
                string sql1 = "SELECT TOP 1 * FROM  Jadlospisy WHERE(([PoraDnia] LIKE '%Sniadanie%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[0] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; "; //AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))
                string sql2 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%II sniadanie/podwieczorek%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[1] + "') )  ORDER BY NEWID() ; ";                                        //AND ([Ograniczenia] LIKE ('" + resultRestricitons + "'))
                string sql3 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Obiad%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[2] + "') )  ORDER BY NEWID() ; ";                                                            //AND ([Ograniczenia] LIKE ('" + resultRestricitons + "'))
                string sql4 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%II sniadanie/podwieczorek%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[3] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; "; SqlCommand cmd = new SqlCommand(sql1, sqlConnection);
                string sql5 = "SELECT TOP 1 * FROM  Jadlospisy WHERE( ([PoraDnia] LIKE '%Kolacja%') AND ([KCAL] LIKE '" + user.UserMealCaloricty[4] + "') AND ([Ograniczenia] LIKE ('" + resultRestricitons + "')))  ORDER BY NEWID() ; ";

                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal1.MealId             = Int32.Parse(read["Id"].ToString());
                        meal1.Name               = (read["Nazwa"]).ToString();
                        meal1.Daytime            = (read["PoraDnia"]).ToString();
                        meal1.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal1.Description        = (read["Opis"]).ToString();
                        meal1.Ingredients        = (read["Skladniki"]).ToString();
                        meal1.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql2, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal2.MealId             = Int32.Parse(read["Id"].ToString());
                        meal2.Name               = (read["Nazwa"]).ToString();
                        meal2.Daytime            = (read["PoraDnia"]).ToString();
                        meal2.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal2.Description        = (read["Opis"]).ToString();
                        meal2.Ingredients        = (read["Skladniki"]).ToString();
                        meal2.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql3, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal3.MealId             = Int32.Parse(read["Id"].ToString());
                        meal3.Name               = (read["Nazwa"]).ToString();
                        meal3.Daytime            = (read["PoraDnia"]).ToString();
                        meal3.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal3.Description        = (read["Opis"]).ToString();
                        meal3.Ingredients        = (read["Skladniki"]).ToString();
                        meal3.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql4, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal4.MealId             = Int32.Parse(read["Id"].ToString());
                        meal4.Name               = (read["Nazwa"]).ToString();
                        meal4.Daytime            = (read["PoraDnia"]).ToString();
                        meal4.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal4.Description        = (read["Opis"]).ToString();
                        meal4.Ingredients        = (read["Skladniki"]).ToString();
                        meal4.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                cmd = new SqlCommand(sql5, sqlConnection);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        meal5.MealId             = Int32.Parse(read["Id"].ToString());
                        meal5.Name               = (read["Nazwa"]).ToString();
                        meal5.Daytime            = (read["PoraDnia"]).ToString();
                        meal5.Caloricity         = float.Parse((read["KCAL"]).ToString());
                        meal5.Description        = (read["Opis"]).ToString();
                        meal5.Ingredients        = (read["Skladniki"]).ToString();
                        meal5.FoodRestrictions11 = (read["Ograniczenia"]).ToString();
                    }
                }
                foodPlan = new FoodPlan(user, meal1, meal2, meal3, meal4, meal5);
            }
            return(foodPlan);
        }