Ejemplo n.º 1
0
        private void ButtonSupprimer_Click(object sender, RoutedEventArgs e)
        {
            if (DatePickerStock.Text != "" & TextBoxCodeProduit.Text != "" & TextBoxNomProduit.Text != "" &
                TextBoxQuantite.Text != "" & ComboBoxEtat.Text != "" & ComboBoxCategorie.Text != "") // Si les champs ne sont pas vides, la suppression est impossible
            {
                SqlConnection connection = new SqlConnection(ConString);
                connection.Open(); // Ouvertue de la connexion

                SqlCommand cmdSqlCommand =
                    new SqlCommand(
                        "DELETE FROM dbo.Produits WHERE CodeProduit=@CodeProduit",
                        connection);                                                             // Requête de suppression du client
                cmdSqlCommand.Parameters.AddWithValue("@CodeProduit", TextBoxCodeProduit.Text);  // Paramètre du CodeProduit
                if (MessageBox.Show("Oui ou Non", "Êtes vous sûr de vouloir supprimer ce produit ?", MessageBoxButton.YesNo,
                                    MessageBoxImage.Question) == MessageBoxResult.Yes)           // Boite de dialogue demandant la confirmation pour la suppression du produit
                {
                    cmdSqlCommand.ExecuteNonQuery();                                             // Execution de la requête
                    MessageBox.Show("Le produit " + TextBoxNomProduit.Text + " a été supprimé"); // Affichage du message après execution de la requête
                }
                FillDataGrid();                                                                  // Recharge la table Produit
                TextBoxCodeProduit.Clear();                                                      // Vide le champs Code Produit
                TextBoxNomProduit.Clear();                                                       // Vide le champs Nom Produit
                TextBoxPrixHt.Clear();                                                           // Vide le champs Prix HT
                TextBoxQuantite.Clear();                                                         // Vide le champs Quantite
                ComboBoxEtat.Text            = "";                                               // Vide la ComboBox Etat
                DatePickerStock.SelectedDate = DateTime.Today;;                                  // Remet la date du jour
                TextBoxRecherche.Text        = "";
                connection.Close();                                                              // Fermeture de la connexion
            }
        }
Ejemplo n.º 2
0
        private void ButtonAjouter_Click(object sender, RoutedEventArgs e)
        {
            if (DatePickerStock.Text != "" & TextBoxCodeProduit.Text != "" & TextBoxNomProduit.Text != "" &
                TextBoxQuantite.Text != "" & ComboBoxEtat.Text != "" & ComboBoxCategorie.Text != "") // Si les champs ne sont pas vides, la création est impossible
            {
                SqlConnection connection = new SqlConnection(ConString);
                connection.Open(); // Ouvertue de la connexion

                SqlCommand cmdSqlCommand =
                    new SqlCommand(
                        "INSERT INTO dbo.Produits(CodeProduit, NomProduit, Categorie, Quantite, PrixHt, Etat, DateAjout) Values(@CodeProduit, @NomProduit, @Categorie, @Quantite, @PrixHt, @Etat, @DateAjout)",
                        connection);                                                            // Requête d'insertion d'un nouveau client

                cmdSqlCommand.Parameters.AddWithValue("@CodeProduit", TextBoxCodeProduit.Text); // Paramètre du Nom du client
                cmdSqlCommand.Parameters.AddWithValue("@NomProduit", TextBoxNomProduit.Text);   // Paramètre du Prenom du client
                switch (ComboBoxCategorie.Text)
                {
                case "Disque dur et SSD":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "HDD");     // Ajout HDD dans catégorie
                    break;

                case "Carte graphique":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "GPU");     // Ajout GPU dans catégorie
                    break;

                case "Processeur":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "CPU");     // Ajout CPU dans catégorie
                    break;

                case "Carte mère":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "MoBo");     // Ajout MoBo dans catégorie
                    break;

                case "Barette mémoire":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "RAM");     // Ajout RAM dans catégorie
                    break;

                case "Alimentatin":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "ALIM");     // Ajout ALIM dans catégorie
                    break;

                case "Accessoire":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "ACC");     // Ajout ACC dans catégorie
                    break;
                }
                cmdSqlCommand.Parameters.AddWithValue("@Quantite", TextBoxQuantite.Text);  // Paramètre du prix HT du produit
                cmdSqlCommand.Parameters.AddWithValue("@Prixht", TextBoxPrixHt.Text);      // Paramètre du prix HT du produit
                cmdSqlCommand.Parameters.AddWithValue("@Etat", ComboBoxEtat.Text);         // Paramètre de l'etat du produit
                cmdSqlCommand.Parameters.AddWithValue("@DateAjout", DateTime.Now);         // Paramètre de la date d'ajout
                cmdSqlCommand.ExecuteNonQuery();                                           // Execution de la requête
                MessageBox.Show("Le produit " + TextBoxNomProduit.Text + " a été ajouté"); // Affichage du message après execution de la requête
                FillDataGrid();                                                            // Recharge la table Clients
                TextBoxCodeProduit.Clear();                                                // Vide le champs Nom
                TextBoxNomProduit.Clear();                                                 // Vide le champs Prenom
                TextBoxQuantite.Clear();                                                   // Vide le champs Societe
                TextBoxPrixHt.Clear();                                                     // Vide le champs Prix HT
                connection.Close();                                                        // Fermeture de la connexion
            }
        }
Ejemplo n.º 3
0
 private void ButtonRaz_Click(object sender, RoutedEventArgs e)
 {
     DatePickerStock.SelectedDate = DateTime.Today;
     TextBoxCodeProduit.Clear();
     TextBoxNomProduit.Clear();
     TextBoxPrixHt.Clear();
     TextBoxQuantite.Clear();
     ComboBoxCategorie.SelectedIndex = -1;
     ComboBoxEtat.SelectedIndex      = -1;
 }
Ejemplo n.º 4
0
        private void ButtonModifier_Click(object sender, RoutedEventArgs e)
        {
            if (DatePickerStock.Text != "" & TextBoxCodeProduit.Text != "" & TextBoxNomProduit.Text != "" &
                TextBoxQuantite.Text != "" & ComboBoxEtat.Text != "" &
                ComboBoxCategorie.Text != "") // Si les champs sont pas vides, la modification est impossible
            {
                SqlConnection connection = new SqlConnection(ConString);
                connection.Open(); // Ouvertue de la connexion
                SqlCommand cmdSqlCommand =
                    new SqlCommand(
                        "UPDATE dbo.Produits SET NomProduit=@NomProduit, Categorie=@Categorie, PrixHt=@PrixHt, Quantite=@Quantite, Etat=@Etat, DateAjout=@DateAjout, CodeProduit=@CodeProduit WHERE CodeProduit=@CodeProduit",
                        connection);                                           // Requête de suppression du client
                cmdSqlCommand.Parameters.AddWithValue("@NomProduit",
                                                      TextBoxNomProduit.Text); // Paramètre du Nom du produit
                switch (ComboBoxCategorie.Text)
                {
                case "Disque dur et SSD":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "HDD");     // Ajout HDD dans catégorie
                    break;

                case "Carte graphique":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "GPU");     // Ajout GPU dans catégorie
                    break;

                case "Processeur":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "CPU");     // Ajout CPU dans catégorie
                    break;

                case "Carte mère":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "MoBo");     // Ajout MoBo dans catégorie
                    break;

                case "Barette mémoire":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "RAM");     // Ajout RAM dans catégorie
                    break;

                case "Alimentatin":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "ALIM");     // Ajout ALIM dans catégorie
                    break;

                case "Accessoire":
                    cmdSqlCommand.Parameters.AddWithValue("@Categorie", "ACC");     // Ajout ACC dans catégorie
                    break;
                }
                cmdSqlCommand.Parameters.AddWithValue("@PrixHt", TextBoxPrixHt.Text); // Paramètre du Prix HT du produit
                cmdSqlCommand.Parameters.AddWithValue("@Quantite",
                                                      TextBoxQuantite.Text);          // Paramètre du Prix HT du produit
                cmdSqlCommand.Parameters.AddWithValue("@Etat", ComboBoxEtat.Text);    // Paramètre de l'Etat du produit
                cmdSqlCommand.Parameters.AddWithValue("@DateAjout", DateTime.Now);    // Paramètre de la Date d'ajout du produit
                cmdSqlCommand.Parameters.AddWithValue("@CodeProduit",
                                                      TextBoxCodeProduit.Text);       // Paramètre du Code du produit
                cmdSqlCommand.ExecuteNonQuery();                                      // Execution de la requête
                int rows = cmdSqlCommand.ExecuteNonQuery();                           // Variable qui stocke le nombre de requêtes effectuées
                if (rows > 1)
                {
                    MessageBox.Show(
                        rows +
                        " requêtes ont bien été effectuées"); // Affichage du message après execution de la requête (dans le cas où il y en a plusieurs)
                }
                else
                {
                    MessageBox.Show(
                        rows +
                        " requête a bien été effectuée"); // Affichage du message après execution de la requête (dans le cas où il n'y en a qu'une seule)
                }

                FillDataGrid();                                // Recharge la table Produit
                TextBoxCodeProduit.Clear();                    // Vide le champs Code Produit
                TextBoxNomProduit.Clear();                     // Vide le champs Nom Produit
                TextBoxPrixHt.Clear();                         // Vide le champs Prix HT
                TextBoxQuantite.Clear();                       // Vide le champs Quantite
                ComboBoxEtat.Text            = "";             // Vide la ComboBox Etat
                DatePickerStock.SelectedDate = DateTime.Today; // Remet la date du jour
                TextBoxRecherche.Text        = "";
                connection.Close();                            // Fermeture de la connexion
            }
        }