コード例 #1
0
        public ListeIngredients liste(string idr)
        {
            string          connectionString = "SERVER=localhost ; DATABASE=Cooking; UID=root; PASSWORD=***;";
            MySqlConnection connection       = new MySqlConnection(connectionString);

            connection.Open();

            MySqlCommand com = connection.CreateCommand();

            com.CommandText = "SELECT nom_p, idproduit From Produit order by idProduit;";
            MySqlDataReader read;

            read = com.ExecuteReader();
            List <string> ids = new List <string>();

            while (read.Read())
            {
                ids.Add(read.GetString(1));
                Console.WriteLine("Le produit " + read.GetString(0) + " a pour identifiant " + read.GetString(1));
            }
            read.Close();
            string idP = ""; int i = 0;

            do
            {
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.WriteLine("Veuillez saisir l'identifiant du produit choisi et sa quantité nécessaire pour la recette " + idr + " : ");
                Console.ForegroundColor = ConsoleColor.White;
                idP = Console.ReadLine();
                i   = Convert.ToInt32(Console.ReadLine());
            } while (ids.Contains(idP) == false);

            ListeIngredients newl = new ListeIngredients(idP, idr, i);

            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "INSERT INTO ListeIngredients Values (@p1,@p2,@p3)";
            command.Parameters.AddWithValue("@p1", newl.IdProduit);
            command.Parameters.AddWithValue("@p2", newl.IdRecette);
            command.Parameters.AddWithValue("@p3", newl.Unite_Quantite);
            MySqlDataReader reader;

            reader = command.ExecuteReader();
            reader.Close();
            connection.Close();

            return(newl);
        }
コード例 #2
0
        public Recette SaisieRecette(string idc)
        {
            List <Recette> recettes = this.Recettes();
            List <string>  id       = new List <string>();

            foreach (Recette r in recettes)
            {
                id.Add(r.IdRecette);
            }
            Console.ForegroundColor = ConsoleColor.Magenta;
            string idr;

            do
            {
                Console.WriteLine("Choisissez un identifiant de recette tel que R****"); Console.ForegroundColor = ConsoleColor.White; idr = Console.ReadLine();
            } while (id.Contains(idr));
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Veuillez nommer cette recette : ");
            Console.ForegroundColor = ConsoleColor.White;
            string nom = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Veuillez donner un type à cette recette : ");
            Console.ForegroundColor = ConsoleColor.White;
            string t = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Veuillez décrire cette recette : ");
            Console.ForegroundColor = ConsoleColor.White;
            string descrip = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Veuillez donner un prix de vente (prix entier): ");
            Console.ForegroundColor = ConsoleColor.White;
            int prix = Convert.ToInt32(Console.ReadLine());

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Veuillez saisir le nombre de jours où cette recette peut être conservée : ");
            Console.ForegroundColor = ConsoleColor.White;
            int     temps = Convert.ToInt32(Console.ReadLine());
            Recette newr  = new Recette(idr, nom, t, descrip, prix, 0, temps, idc);


            //insertion dans la BD
            string          connectionString = "SERVER=localhost ; DATABASE=Cooking; UID=root; PASSWORD=***;";
            MySqlConnection connection       = new MySqlConnection(connectionString);

            connection.Open();

            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "INSERT INTO Recette Values (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8)";
            command.Parameters.AddWithValue("@p1", newr.IdRecette);
            command.Parameters.AddWithValue("@p2", newr.Nom_R);
            command.Parameters.AddWithValue("@p3", newr.Type);
            command.Parameters.AddWithValue("@p4", newr.Descriptif);
            command.Parameters.AddWithValue("@p5", newr.Prix_vente);
            command.Parameters.AddWithValue("@p6", newr.Nb_commande);
            command.Parameters.AddWithValue("@p7", newr.Temps_conservation);
            command.Parameters.AddWithValue("@p8", newr.IdClient);
            MySqlDataReader reader2;

            reader2 = command.ExecuteReader();
            connection.Close();

            //liste ingrédients

            ListeIngredients l = new ListeIngredients();
            string           i = "";

            do
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Voulez-vous ajouter un ingrédient à la liste ? (oui/non)");
                Console.ForegroundColor = ConsoleColor.White;
                i = Console.ReadLine().ToLower();
                if (i == "oui")
                {
                    l.liste(idr);
                }
            } while (i != "non");

            return(newr);
        }