Ejemplo n.º 1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (nom.Text != "" && prenom.Text != "" && pass.Password != "" && pseudo.Text != "")
                {
                    SqlConnection  con     = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\bdd.mdf;Integrated Security=True");
                    SqlDataAdapter adapter = new SqlDataAdapter("Select Count(*) From Utilisateurs Where Pseudo='" + pseudo.Text + "'", con);
                    DataTable      table   = new DataTable();
                    adapter.Fill(table);
                    if (table.Rows[0][0].ToString() == "1")
                    {
                        //afficher acueil
                        pseu_ext.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(nom.Text))
                        {
                            champs.Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            if (pass.Password.Equals(confirm.Password))
                            {
                                String query = "INSERT INTO Utilisateurs(Nom,Prenom,Pseudo,Mpasse)output INSERTED.Id_utilisateur VALUES ('" + nom.Text + "','" + prenom.Text + "','" + pseudo.Text + "','" + pass.Password + "')";
                                con.Open();

                                SqlCommand cmd = new SqlCommand(query, con);
                                int        id  = 0;
                                id = (int)cmd.ExecuteScalar();
                                if (con.State == System.Data.ConnectionState.Open)
                                {
                                    con.Close();
                                }
                                utilisateur user = new utilisateur(id, nom.Text, prenom.Text, pseudo.Text);

                                acceuil win = new acceuil(user);
                                win.Show();
                                this.Close();
                            }
                            else
                            {
                                confirmation.Visibility = System.Windows.Visibility.Visible;
                            }
                        }
                    }
                }
                else
                {
                    champs.Visibility = Visibility.Visible;
                }
            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void connect_Click(object sender, RoutedEventArgs e)
        {
            methodes    app  = new methodes();
            utilisateur user = app.login(pseudo.Text, pass.Password);

            if (user != null)
            {
                acceuil windo = new acceuil(user);
                windo.Show();
                this.Close();
            }
            else
            {
                error.Visibility = System.Windows.Visibility.Visible;
            }
        }