Esempio n. 1
0
        //on affecte les valeurs de la base de donnée au client correspondant
        public Recette BDRecette(string IDR)
        {
            Recette         recette_BD       = new Recette();
            string          connectionString = "SERVER=localhost ; DATABASE=Cooking; UID=root; PASSWORD=***;";
            MySqlConnection connection       = new MySqlConnection(connectionString);

            connection.Open();

            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "select * from Recette where idRecette = @id;";
            command.Parameters.AddWithValue("@id", IDR);
            MySqlDataReader reader;

            reader = command.ExecuteReader();

            string nom, typ, descrip, idC;
            int    prix, nb, temps;

            while (reader.Read())
            {
                nom        = reader.GetString(1);
                typ        = reader.GetString(2);
                descrip    = reader.GetString(3);
                prix       = reader.GetInt32(4);
                nb         = reader.GetInt32(5);
                temps      = reader.GetInt32(6);
                idC        = reader.GetString(7);
                recette_BD = new Recette(IDR, nom, typ, descrip, prix, nb, temps, idC);
            }
            reader.Close();

            connection.Close();

            return(recette_BD);
        }
Esempio n. 2
0
        public void IdentificationCdR(string IDC)
        {
            //on récupère les données du client dont l'identifiant est IDC
            Client c0 = BDClient(IDC);

            //on demande à l'utilisateur s'il veut devenir CdR
            if (c0.Statut_Cdr == false)
            {
                string i = "";
                do
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Voulez-vous être CdR ?(oui/non) ");
                    Console.ForegroundColor = ConsoleColor.White;
                    i = Console.ReadLine().ToLower();
                } while (i != "oui" && i != "non");
                if (i == "oui")
                {
                    if (c0.Statut_Cdr == false)
                    {
                        c0.Statut_Cdr = true;
                        string          connectionString = "SERVER=localhost ; DATABASE=Cooking; UID=root; PASSWORD=***;";
                        MySqlConnection connection       = new MySqlConnection(connectionString);
                        connection.Open();
                        MySqlCommand command = connection.CreateCommand();
                        command.CommandText = "UPDATE client SET statut_cdr = REPLACE(statut_cdr, false, true) WHERE idClient = @id;";
                        command.Parameters.AddWithValue("@id", IDC);
                        MySqlDataReader reader;
                        reader = command.ExecuteReader();
                        reader.Close();
                        connection.Close();
                    }
                }
            }
            //on accède aux fonctionnalités de CdR-cuisinier en vérifiant qu'il soit bien cdr
            int j = 0;

            if (c0.Statut_Cdr)
            {
                string fin = "non";
                do
                {
                    do
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("Vous êtes bien créateur de recettes. Que voulez-vous faire ? ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(" saisir une nouvelle recette : tapez 1 \n consulter votre solde : tapez 2 \n afficher la liste de vos recettes : tapez 3");
                        j = Convert.ToInt32(Console.ReadLine());
                    } while (j != 1 && j != 2 && j != 3);

                    Recette r = new Recette();
                    if (j == 1)
                    {
                        r.SaisieRecette(IDC);
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("Voulez-vous faire autre chose concernant les fonctionnalités CdR ? (oui/non) ");
                        Console.ForegroundColor = ConsoleColor.White;
                        fin = Console.ReadLine().ToLower();
                    }
                    else
                    {
                        if (j == 2)
                        {
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("Votre solde cook est de : " + c0.Solde_cook);
                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.WriteLine("Voulez-vous faire autre chose concernant les fonctionnalités CdR ? (oui/non) ");
                            Console.ForegroundColor = ConsoleColor.White;
                            fin = Console.ReadLine().ToLower();
                        }
                        else
                        {
                            if (j == 3)
                            {
                                Console.ForegroundColor = ConsoleColor.Gray;
                                r.AffichageListe(IDC);
                                Console.ForegroundColor = ConsoleColor.Magenta;
                                Console.WriteLine("Voulez-vous faire autre chose concernant les fonctionnalités CdR ? (oui/non) ");
                                Console.ForegroundColor = ConsoleColor.White;
                                fin = Console.ReadLine().ToLower();
                            }
                        }
                    }
                } while (fin == "oui");
            }

            //reader.Close();
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void ModifSiCommande(string idRec, int q)
        {
            //modification du prix de vente selon le nombre de commandes
            //le nombre de commandes augmente à chaque fois qu'on appelle cette fonction
            Recette r0 = BDRecette(idRec);

            r0.Nb_commande = r0.Nb_commande + q;
            string          connectionString = "SERVER=localhost ; DATABASE=Cooking; UID=root; PASSWORD=***;";
            MySqlConnection connection       = new MySqlConnection(connectionString);

            connection.Open();
            int aug = 0;

            if (r0.Nb_commande > 10)
            {
                r0.Prix_vente += 2;
            }
            if (r0.Nb_commande > 50)
            {
                r0.Prix_vente += 5; aug = 2;
            }
            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "UPDATE Recette SET prix_vente = @prix , nb_commande = @nbr WHERE idRecette = @id;";
            command.Parameters.AddWithValue("@prix", r0.Prix_vente);
            command.Parameters.AddWithValue("@nbr", r0.Nb_commande);
            command.Parameters.AddWithValue("@id", r0.IdRecette);
            MySqlDataReader reader;

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

            //modification du solde cook et du nombre de recettes commandées créées par le CdR
            MySqlCommand command2 = connection.CreateCommand();

            command2.CommandText = "select solde_cook,nbr_recette_com_CdR from Client where idClient = @id;";
            command2.Parameters.AddWithValue("@id", r0.IdClient);
            MySqlDataReader reader2;

            reader2 = command2.ExecuteReader();
            int s = 0;
            int n = 0;

            while (reader2.Read())
            {
                s = reader2.GetInt32(0);
                s = s + 2 + aug; //on fixe la remuneration du cdr à 2 cooks si nb_commandes < 50
                n = reader2.GetInt32(1);
                n = n + 1;
            }
            reader2.Close();

            //la BD est modifiée
            MySqlCommand command3 = connection.CreateCommand();

            command3.CommandText = "UPDATE Client SET solde_cook = @sol , nbr_recette_com_CdR = @nbr WHERE idClient = @id;";
            command3.Parameters.AddWithValue("@sol", s);
            command3.Parameters.AddWithValue("@nbr", n);
            command3.Parameters.AddWithValue("@id", r0.IdClient);
            MySqlDataReader reader3;

            reader3 = command3.ExecuteReader();
            connection.Close();
        }