private void Validation(object sender, RoutedEventArgs e)
        {
            MySqlConnection maConnexion = null;

            try
            {
                string connexionString = "SERVER=localhost;PORT=3306;DATABASE=tableprojet;UID=root;PASSWORD="******";convert zero datetime=True";
                maConnexion = new MySqlConnection(connexionString);
                maConnexion.Open();
            }
            catch (MySqlException er)
            {
                Console.WriteLine(" ErreurConnexion : " + er.ToString());
                return;
            }

            string nom_recette = nomrecette.Text.ToString();        //Nom saisi
            string descriptife = descriptif.Text.ToString();        //Descriptif
            float  prixs       = float.Parse(prix.Text.ToString()); //Prix

            string cat = "";

            if (entree.IsChecked == true)
            {
                cat = "Entrée";
            }
            else if (plat.IsChecked == true)
            {
                cat = "Plat";
            }
            else if (dessert.IsChecked == true)
            {
                cat = "Dessert";
            }

            string       requete  = "Select Nom from Recette where categorie='" + cat + "';"; //On verifie que le nom de la recette n'existe pas deja
            MySqlCommand command1 = maConnexion.CreateCommand();

            command1.CommandText = requete;

            MySqlDataReader reader = command1.ExecuteReader();
            bool            existe = false;

            while (reader.Read())
            {
                if (nom_recette == reader.GetValue(0).ToString()) //La valeur 0 c'est le nom car tu select que le nom
                {
                    existe = true;
                    MessageBox.Show("Un recette avec le meme nom existe deja");
                }
            }
            command1.Dispose();

            if (existe == false)
            {
                string requete2 = "insert into tableprojet.recette(`Nom`,`descriptif`,`prix`,`idCreateur`,`categorie`) Values('" + nom_recette + "','" + descriptife + "'," + prixs + "," + ClientStatic.idCreateur + ",'" + cat + "');";
                MessageBox.Show(requete2);
                MySqlCommand command2 = maConnexion.CreateCommand();
                command2.CommandText = requete2;

                MySqlDataReader reader2 = command2.ExecuteReader();
                command2.Dispose();

                string       requete_idRecette = "select idRecette from Recette where Nom = '" + nom_recette + "'; ";
                MySqlCommand command_idRecette = maConnexion.CreateCommand();
                command_idRecette.CommandText = requete_idRecette;

                MySqlDataReader reader_idRecette = command_idRecette.ExecuteReader();
                reader_idRecette.Read();
                int id_recette = int.Parse(reader_idRecette["idRecette"].ToString());
                command_idRecette.Dispose();

                foreach (string valeur in listBox1.Items)
                {
                    string[]     a      = valeur.Split(":");
                    string[]     new_a1 = a[1].Split("-");
                    string       requete_idingredient = "select idIngredient from Ingredient where Nom = '" + a[0] + "'; ";
                    MySqlCommand command_idIngredient = maConnexion.CreateCommand();
                    command_idIngredient.CommandText = requete_idingredient;

                    MySqlDataReader reader_idIngredient = command_idIngredient.ExecuteReader();
                    reader_idIngredient.Read();
                    int id_ingredient = int.Parse(reader_idIngredient["idIngredient"].ToString());
                    command_idIngredient.Dispose();

                    string       requete_inset_list_ingre   = "insert into tableprojet.Liste_ingredient(`idRecette1`,`idIngredient1`,`quantite`) Values(" + id_recette + "," + id_ingredient + "," + new_a1[0] + ");";
                    MySqlCommand command_insert_liste_ingre = maConnexion.CreateCommand();
                    command_insert_liste_ingre.CommandText = requete_inset_list_ingre;
                    MySqlDataReader reader_insert = command_insert_liste_ingre.ExecuteReader();
                    MessageBox.Show(requete_inset_list_ingre);
                    command_insert_liste_ingre.Dispose();
                }

                MessageBox.Show("Merci pour la creation de la recette");
                Acceuil pa = new Acceuil();
                pa.Show();
                this.Close();
            }
        }
Пример #2
0
        private void conexion(object sender, RoutedEventArgs e)
        {
            MySqlConnection maConnexion = null;

            try
            {
                string connexionString = "SERVER=localhost;PORT=3306;DATABASE=tableprojet;UID=root;PASSWORD="******";convert zero datetime=True";
                maConnexion = new MySqlConnection(connexionString);
                maConnexion.Open();
            }
            catch (MySqlException er)
            {
                Console.WriteLine(" ErreurConnexion : " + er.ToString());
                return;
            }

            if (mail.Text.Trim() != "" && mdp.Text.Trim() != "")
            {
                string p       = mail.Text;
                string requete = "SELECT * FROM client WHERE client.adresseEmail='" + p + "';";

                MySqlCommand command_all = maConnexion.CreateCommand();
                command_all.CommandText = requete;

                MySqlDataReader reader = command_all.ExecuteReader();  //reader a les valeurs retourner par la requette
                reader.Read();

                if (mdp.Text == reader["motDePasse"].ToString())  //Verification avec le mdp
                {
                    ClientStatic.idClient = int.Parse(reader["idClient"].ToString());
                    ClientStatic.nom      = reader["nom"].ToString();
                    ClientStatic.prenom   = reader["prenom"].ToString();
                    ClientStatic.adresse  = reader["adresse"].ToString();
                    ClientStatic.ville    = reader["ville"].ToString();
                    DateTime date = (DateTime)reader["date_naissance"];
                    ClientStatic.d_naissance  = date;
                    ClientStatic.tel          = int.Parse(reader["numeroDeTelephone"].ToString());
                    ClientStatic.mail         = reader["adresseEmail"].ToString();
                    ClientStatic.estCreateur  = int.Parse(reader["estCreateur"].ToString());
                    ClientStatic.capitalCooks = int.Parse(reader["capitalCooks"].ToString());
                    ClientStatic.mdp          = reader["motDePasse"].ToString();
                    string affichage_client = ClientStatic.affichage();
                    command_all.Dispose();
                    reader.Close();

                    if (ClientStatic.estCreateur == 1)
                    {
                        ClientStatic.idCreateur = recupt_idcreateur();
                        Acceuil page = new Acceuil();
                        page.Show();
                        this.Close();
                    }
                    else
                    {
                        Acceuil_commande page = new Acceuil_commande();
                        page.Show();
                        this.Close();
                    }
                }
                else
                {
                    erreur_connexion a = new erreur_connexion();
                    a.Show();
                }
            }


            else
            {
                erreur_connexion a = new erreur_connexion();
                a.Show();
            }
        }