Exemple #1
0
        private void verif_id_client(Client client1)
        {
            #region Connexion
            MySqlConnection maConnexion = null;
            try
            {
                string connexionString = "SERVER=localhost;PORT=3306;" +
                                         "DATABASE=cooking;" +
                                         "UID=root;PASSWORD=Jessyann1808*";

                maConnexion = new MySqlConnection(connexionString);
                maConnexion.Open();
            }
            catch (MySqlException e1)
            {
                Console.WriteLine(" ErreurConnexion : " + e1.ToString());
                return;
            }
            #endregion

            #region Vérification d'un identifiant bien unique + insertion dans les différentes tables fonciton de créateur ou non
            string       requete_verif = "Select * from client";// where id_client = '" + textbox_idClient + "';";
            MySqlCommand command_verif = maConnexion.CreateCommand();
            command_verif.CommandText = requete_verif;

            MySqlDataReader reader_verif = command_verif.ExecuteReader();

            string[] valueString = new string[reader_verif.FieldCount];
            string   chaine      = "";

            while (reader_verif.Read())
            {
                string id_client_trouve = (string)reader_verif["id_client"];
                chaine += id_client_trouve + " ";

                //for (int i = 0; i < reader.FieldCount; i++)
                //{
                //  valueString[i] = reader.GetValue(i).ToString();
                //Console.Write(valueString[i] + " , ");
                //}
                //Console.WriteLine();
            }

            reader_verif.Close();
            command_verif.Dispose();

            if (chaine.Contains(client1.IdClient))
            {
                MessageBox.Show("Cet identifiant est déjà utilisé!\nVeuillez en entrer un autre.");
            }
            else
            {
                if (!client1.EstCreateur)
                {
                    //créer le client en ajoutant tous les attributs
                    //en fonction de CdR ou non, l'envoyer sur une page ou une autre



                    string       requete  = "Insert into cooking.client values('" + client1.IdClient + "','" + client1.Nom + "','" + client1.Prenom + "','" + client1.Adresse + "','" + client1.Ville + "','" + client1.Tel + "','" + client1.Mail + "'," + client1.EstCreateur + "," + client1.Compte + ",'" + client1.Mdp + "');";
                    MySqlCommand command1 = maConnexion.CreateCommand();
                    command1.CommandText = requete;

                    MySqlDataReader reader = command1.ExecuteReader();
                    reader.Close();
                    command1.Dispose();

                    Client_normal_gestion fen2 = new Client_normal_gestion();
                    fen2.textblock_recup_id.Text = textbox_idClient.Text;
                    fen2.Show();
                    this.Hide();
                }
                else
                {
                    CdR cdr1 = new CdR(textbox_idClient.Text, textbox_nom.Text, textbox_prenom.Text, textbox_adresse.Text, textbox_ville.Text, textbox_tel.Text, textbox_mail.Text, (bool)(checkbox_estCreateur_inscription.IsChecked), 0, textbox_mdp.Text, textbox_idClient.Text);



                    string       requete  = ("Insert into cooking.client values('" + client1.IdClient + "','" + client1.Nom + "','" + client1.Prenom + "','" + client1.Adresse + "','" + client1.Ville + "','" + client1.Tel + "','" + client1.Mail + "'," + client1.EstCreateur + ",'" + client1.Compte + "','" + client1.Mdp + "');");
                    MySqlCommand command1 = maConnexion.CreateCommand();
                    command1.CommandText = requete;

                    MySqlDataReader reader = command1.ExecuteReader();
                    reader.Close();
                    command1.Dispose();

                    string       requete2 = "Insert into cooking.createur_de_recette values('" + client1.IdClient + "','" + client1.IdClient + "','" + 0 + "');";
                    MySqlCommand command2 = maConnexion.CreateCommand();
                    command2.CommandText = requete2;

                    MySqlDataReader reader2 = command2.ExecuteReader();

                    reader.Close();
                    command2.Dispose();


                    CdR_gestion fen2 = new CdR_gestion();
                    fen2.textblock_recup_id.Text = textbox_idClient.Text;
                    fen2.Show();
                    this.Hide();
                }

                #endregion


                maConnexion.Close();
            }
        }
        private void boutton_termine_Click(object sender, RoutedEventArgs e) // Contient la vérification des id et mdp.
        {
            #region Connexion
            MySqlConnection maConnexion = null;
            try
            {
                string connexionString = "SERVER=localhost;PORT=3306;" +
                                         "DATABASE=cooking;" +
                                         "UID=root;PASSWORD=Jessyann1808*";

                maConnexion = new MySqlConnection(connexionString);
                maConnexion.Open();
            }
            catch (MySqlException e1)
            {
                Console.WriteLine(" ErreurConnexion : " + e1.ToString());
                return;
            }
            #endregion

            #region Vérification du mot de passe et de l'identifiant
            string       requete_verif = "Select id_client from client where id_client = '" + textbox_idClient.Text + "' And mdp = '" + passwordbox.Password + "';";
            MySqlCommand command_verif = maConnexion.CreateCommand();
            command_verif.CommandText = requete_verif;

            MySqlDataReader reader_verif = command_verif.ExecuteReader();

            string[] valueString = new string[reader_verif.FieldCount];
            string   chaine      = "";

            while (reader_verif.Read())
            {
                string id_client_trouve = (string)reader_verif["id_client"];
                chaine += id_client_trouve + " ";

                //for (int i = 0; i < reader.FieldCount; i++)
                //{
                //  valueString[i] = reader.GetValue(i).ToString();
                //Console.Write(valueString[i] + " , ");
                //}
                //Console.WriteLine();
            }

            reader_verif.Close();
            command_verif.Dispose();

            if (chaine == "") // Si on trouve rien la chaîne sera vide
            {
                MessageBox.Show("Identifiant ou mot de passe incorrects.\nVeuillez réessayer.");
            }
            else
            {
                string       requete_cdr = "Select * from client where id_client = '" + textbox_idClient.Text + "';";
                MySqlCommand command_cdr = maConnexion.CreateCommand();
                command_cdr.CommandText = requete_cdr;

                MySqlDataReader reader_cdr      = command_cdr.ExecuteReader();
                string[]        valueString_cdr = new string[reader_cdr.FieldCount];

                string chaine_cdr = "";
                bool   est_crea   = false;

                while (reader_cdr.Read())
                {
                    est_crea    = (bool)reader_cdr["est_createur"];
                    chaine_cdr += est_crea;
                }

                //Fenetre_Test fen = new Fenetre_Test();
                //fen.textblock_test.Text += est_crea;
                //fen.Show();

                reader_cdr.Close();
                command_cdr.Dispose();

                if (est_crea) // Condition pour appeler un type de fenêtre ou l'autre
                {
                    CdR_gestion fen1 = new CdR_gestion();
                    fen1.textblock_recup_id.Text = textbox_idClient.Text; //On recup l'id_client dans l'autre fenêtre
                    fen1.Show();
                    this.Hide();
                    MessageBox.Show("Bienvenue " + textbox_idClient.Text + "!");
                }
                else
                {
                    Client_normal_gestion fen2 = new Client_normal_gestion();
                    fen2.textblock_recup_id.Text = textbox_idClient.Text; //On recup l'id_client dans l'autre fenêtre
                    fen2.Show();
                    this.Hide();
                    MessageBox.Show("Bienvenue " + textbox_idClient.Text + "!");
                }
            }
            #endregion
            maConnexion.Close();
        }