コード例 #1
0
ファイル: ModuleClient.xaml.cs プロジェクト: Coco-House/BDD
        private void Connexion_Click(object sender, RoutedEventArgs e)
        {
            ConnexionCompte window = new ConnexionCompte();

            window.Show();
            this.Close();
        }
コード例 #2
0
ファイル: LoginPage.xaml.cs プロジェクト: Coco-House/BDD
        private void Valider_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NonBox.IsChecked == true)
                {
                    string connectionString = "SERVER=localhost;PORT=3306;DATABASE=projet;UID=" + MainWindow.Username + ";PASSWORD="******"C" + IDClientBox.Text;
                    char   sexe = 'F';

                    if (MBox.IsChecked == true)
                    {
                        sexe = 'M';
                    }

                    string nomC          = NomBox.Text.ToUpper();
                    string prenomC       = PrenomBox.Text;
                    string dateNaissance = AnneeBox.Text + "-" + MoisBox.Text + "-" + JourBox.Text;
                    int    age           = Convert.ToInt32(CalculAgeLabel.Content);
                    string adresse       = AdresseBox.Text;
                    string email         = EmailBox.Text;
                    string password      = PswdBoxVerif.Password;
                    string telC          = TelephoneBox.Text;

                    MySqlCommand command = connection.CreateCommand();
                    command.CommandText = " INSERT INTO projet.client(`idC`,`nomC`,`prenomC`,`DateNaissance`,`age`,`adresse`,`sexe`,`email`,`password`,`telC`) VALUES('" + idC + "','" + nomC + "','" + prenomC + "','" + dateNaissance + "'," + age + ",'" + adresse + "','" + sexe + "','" + email + "','" + password + "','" + telC + "');";
                    MySqlDataReader reader;
                    reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                    }

                    connection.Close();


                    if (CdRBox.IsChecked == true)
                    {
                        int    cook  = 0;
                        string idCdR = "CdR" + IDCdRBox.Text;

                        CdR newCdR = new CdR(idC, sexe, nomC, prenomC, dateNaissance, age, adresse, email, password, telC, idCdR, cook);
                        MainWindow.listeCdR.Add(newCdR);

                        connection.Open();
                        MySqlCommand commandCdR = connection.CreateCommand();
                        commandCdR.CommandText = "INSERT INTO projet.cdr(`idCdR`,`cook`,`idC`) VALUES('" + idCdR + "','" + cook + "','" + idC + "');";

                        MySqlDataReader readerCdR;
                        readerCdR = commandCdR.ExecuteReader();

                        while (readerCdR.Read())
                        {
                        }

                        connection.Close();
                    }
                    else if (ClientBox.IsChecked == true)
                    {
                        Client newClient = new Client(idC, sexe, nomC, prenomC, dateNaissance, age, adresse, email, password, telC);
                        MainWindow.listeClients.Add(newClient);
                    }

                    MessageBox.Show("Inscription reussie !", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);
                    ConnexionCompte window = new ConnexionCompte();
                    window.Show();

                    this.Close();
                }
                else if (OuiBox.IsChecked == true)
                {
                    string connectionString = "SERVER=localhost;PORT=3306;DATABASE=projet;UID=" + MainWindow.Username + ";PASSWORD="******"SELECT idC FROM projet.Client WHERE email='" + EmailBox.Text + "';";
                    MySqlDataReader reader1;
                    reader1 = command1.ExecuteReader();

                    string idC = "";

                    while (reader1.Read())
                    {
                        idC = reader1.GetString(0);
                    }

                    connection.Close();

                    int    cook  = 0;
                    string idCdR = "CdR" + IDCdRBox.Text;

                    connection.Open();
                    MySqlCommand commandCdR = connection.CreateCommand();
                    commandCdR.CommandText = "INSERT INTO projet.cdr(`idCdR`,`cook`,`idC`) VALUES('" + idCdR + "','" + cook + "','" + idC + "');";

                    MySqlDataReader readerCdR;
                    readerCdR = commandCdR.ExecuteReader();

                    while (readerCdR.Read())
                    {
                    }

                    connection.Close();

                    connection.Open();
                    MySqlCommand commandRecherche = connection.CreateCommand();
                    commandRecherche.CommandText = "SELECT sexe,UPPER(nomC),prenomC,DateNaissance,age,adresse,telC FROM projet.client WHERE idC='" + idC + "';";

                    MySqlDataReader readerRecherche;
                    readerRecherche = commandRecherche.ExecuteReader();

                    char     sexe           = ' ';
                    string   nomC           = "";
                    string   prenomC        = "";
                    string   dateNaissance  = "";
                    DateTime dateNaissance2 = new DateTime();
                    int      age            = 0;
                    string   adresse        = "";
                    string   email          = EmailBox.Text;
                    string   password       = PswdBoxVerif.Password;
                    string   telC           = "";

                    while (readerRecherche.Read())
                    {
                        sexe           = readerRecherche.GetChar(0);
                        nomC           = readerRecherche.GetString(1);
                        prenomC        = readerRecherche.GetString(2);
                        dateNaissance2 = readerRecherche.GetDateTime(3);


                        dateNaissance = dateNaissance2.Year + "-" + dateNaissance2.Month + "-" + dateNaissance2.Day;

                        age     = readerRecherche.GetInt32(4);
                        adresse = readerRecherche.GetString(5);
                        telC    = readerRecherche.GetString(6);
                    }

                    connection.Close();


                    CdR newCdR = new CdR(idC, sexe, nomC, prenomC, dateNaissance, age, adresse, email, password, telC, idCdR, cook);
                    MainWindow.listeCdR.Add(newCdR);

                    MessageBox.Show("Inscription reussie !", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);

                    ConnexionCompte window = new ConnexionCompte();
                    window.Show();

                    this.Close();
                }
                MainWindow.LoadDatabase();
            }
            catch
            {
                MessageBox.Show("Inscription non reussie !", "Erreur!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #3
0
        private void FinaliserButton_Click(object sender, RoutedEventArgs e)
        {
            if (PasserCommande.listeIdRecettesCommandees.Count == 0)
            {
                MessageBox.Show("Vous n'avez rien commandé ! ");
            }
            else
            {
                if (ConnexionCompte.ClientConnecte == false && ConnexionCompte.CdRConnecte == false)
                {
                    this.Close();
                    ConnexionCompte window = new ConnexionCompte();
                    window.Show();
                }
                else
                {
                    if (ConnexionCompte.CdRConnecte == true)
                    {
                        string connectionString = "SERVER=localhost;PORT=3306;DATABASE=projet;UID=" + MainWindow.Username + ";PASSWORD="******"SELECT cook FROM projet.cdr WHERE idCdR ='" + ConnexionCompte.IdCdRConnecte + "';";

                        MySqlDataReader readerRemplir;
                        readerRemplir = commandRemplir.ExecuteReader();

                        int balanceCook = 0;

                        while (readerRemplir.Read())
                        {
                            balanceCook = readerRemplir.GetInt32(0);
                        }


                        connection.Close();

                        if (balanceCook < Convert.ToInt32(PrixCook.Content))
                        {
                            MessageBox.Show("Vous n'avez pas assez de points cook ! ", "Erreur ! ", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            var result = MessageBox.Show("La somme à payer est de  " + PrixCook.Content + " cook. Vous avez " + balanceCook + " cook ! Etes-vous sûr de vouloir procéder au paiement ? Reste : " + (balanceCook - Convert.ToInt32(PrixCook.Content)) + " cook !", "Warning !", MessageBoxButton.YesNo, MessageBoxImage.Information);

                            if (result == MessageBoxResult.Yes)
                            {
                                int newBalance = balanceCook - (Convert.ToInt32(PrixCook.Content));

                                connection.Open();

                                MySqlCommand commandUpdate = connection.CreateCommand();
                                commandUpdate.CommandText = "UPDATE projet.cdr SET cook=" + newBalance + " WHERE idCdR='" + ConnexionCompte.IdCdRConnecte + "';";

                                MySqlDataReader readerUpdate;
                                readerUpdate = commandUpdate.ExecuteReader();

                                while (readerUpdate.Read())
                                {
                                }

                                connection.Close();

                                MettreAJourStockEtPoints();

                                MessageBox.Show("Paiement réussi !", "Success !", MessageBoxButton.OK, MessageBoxImage.Information);

                                MainWindow.LoadDatabase();
                                PasserCommande.listeIdRecettesCommandees.Clear();

                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Paiement annulé !", "Information !", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                        }
                    }
                    else
                    {
                        var result = MessageBox.Show("La somme à payer est de  " + PrixEuros.Content + " euros ! Etes-vous sûr de vouloir procéder au paiement ?", "Warning !", MessageBoxButton.YesNo, MessageBoxImage.Information);

                        if (result == MessageBoxResult.Yes)
                        {
                            MettreAJourStockEtPoints();
                            MessageBox.Show("Paiement réussi !", "Success !", MessageBoxButton.OK, MessageBoxImage.Information);

                            MainWindow.LoadDatabase();
                            PasserCommande.listeIdRecettesCommandees.Clear();

                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Paiement annulé !", "Information !", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
            }
        }