public async Task <ActionResult <CategorieProduit> > PostCategorieProduit(CategorieProduit categorieProduit)
        {
            _context.CategorieProduits.Add(categorieProduit);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCategorieProduit", new { id = categorieProduit.Id }, categorieProduit));
        }
        public async Task <IActionResult> PutCategorieProduit(int id, CategorieProduit categorieProduit)
        {
            if (id != categorieProduit.Id)
            {
                return(BadRequest());
            }

            _context.Entry(categorieProduit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategorieProduitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public List <Produit> getAllProduitsBy(string whereClause)
        {
            List <Produit> listeProduit = new List <Produit>();
            string         query        = "SELECT p.*, cp.nom AS categorie FROM produit p INNER JOIN categorie_produit cp ON p.id_categorie_produit = cp.id";

            if (whereClause != null && whereClause != "")
            {
                query += " WHERE " + whereClause;
            }

            SQLiteDataReader dataReader = sqliteAccess.ExecuteCommandWReturn(query);

            while (dataReader.Read())
            {
                int idCategorieProduit = int.Parse(dataReader["id_categorie_produit"].ToString());
                List <CategorieProduit> categoriesProduit = getAllCategorieProduitBy("id=" + idCategorieProduit);
                if (categoriesProduit.Count == 0)
                {
                    return(null);
                }

                CategorieProduit categorieProduit = categoriesProduit[0];
                listeProduit.Add(new Produit(int.Parse(dataReader["id"].ToString()), dataReader["nom"].ToString(), dataReader["type"].ToString(),
                                             int.Parse(dataReader["nombre_stock"].ToString()), int.Parse(dataReader["seuil_alerte"].ToString()), dataReader["fournisseur"].ToString(),
                                             dataReader["reference_fournisseur"].ToString(), float.Parse(dataReader["prix_ttc"].ToString()),
                                             float.Parse(dataReader["prix_fournisseur"].ToString()), categorieProduit
                                             ));
            }

            return(listeProduit);
        }
예제 #4
0
 // constructeur avec paramètres
 public Produit(int c, string n, float p, CategorieProduit ct, string sct)
 {
     this._code    = c;
     this._nom     = n;
     this._prix    = p;
     this._cat     = ct;
     this._sousCat = sct;
 }
예제 #5
0
 // constructeur par défaut
 public Produit()
 {
     this._code    = -1;
     this._nom     = "Inconnu";
     this._prix    = 0;
     this._cat     = CategorieProduit.Consommable;
     this._sousCat = "";
 }
예제 #6
0
 private void comboBoxCategorieProduit_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (comboBoxCategorieProduit.SelectedIndex >= 0)
     {
         CategorieProduit selectedCategorieProduit = listCategorieProduit[comboBoxCategorieProduit.SelectedIndex];
         listProduits = controller.getProduitByCategorie(selectedCategorieProduit);
     }
 }
예제 #7
0
        public int addCategorieProduit(CategorieProduit categorie)
        {
            string        query         = "INSERT INTO categorie_produit('nom', 'id_famille_produit') VALUES(";
            StringBuilder stringBuilder = new StringBuilder(query);

            stringBuilder.Append("'" + categorie.Nom.Replace("'", "''") + "'" + ",");
            stringBuilder.Append(categorie.Famille.Id + ")");
            int res = sqliteAccess.ExecuteComandWOReturn(stringBuilder.ToString());

            return(res);
        }
예제 #8
0
 public Produit(string nom, string type, int nombreStock, int seuilAlerte, string fournisseur, string referenceFournisseur,
                float prix, float prixFournisseur, CategorieProduit categorie)
 {
     Id                   = -1;
     Nom                  = nom;
     Type                 = type;
     NombreStock          = nombreStock;
     SeuilAlerte          = seuilAlerte;
     Fournisseur          = fournisseur;
     ReferenceFournisseur = referenceFournisseur;
     PrixTTC              = prix;
     PrixFournisseur      = prixFournisseur;
     Categorie            = categorie;
 }
예제 #9
0
        private Produit creerProduitFromView()
        {
            Produit res = null;

            try
            {
                CategorieProduit selectedCategorie = null;
                if (ComboBoxCategorie.SelectedIndex >= 0)
                {
                    selectedCategorie = listCategorie[ComboBoxCategorie.SelectedIndex];
                }
                return(new Produit(textBoxNom.Text, textBoxType.Text, int.Parse(textBoxNombreStock.Text), int.Parse(textBoxSeuilAlerte.Text), textBoxFournisseur.Text, textBoxReferenceFournisseur.Text, float.Parse(textBoxPrix.Text), float.Parse(textBoxPrixFournisseur.Text), selectedCategorie));
            }
            catch
            {
            }
            return(res);
        }
예제 #10
0
 private void DataGrid_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete || e.Key == Key.Back)
     {
         if (MessageBox.Show("Etes vous sûr de supprimer cet élement ?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             CategorieProduit selectedCategorie = DataGrid.SelectedItem as CategorieProduit;
             int res = produitController.supprimerCategorieProduit(selectedCategorie);
             if (res == 1)
             {
                 MessageBox.Show("L'élement a été supprimé", "Informations");
                 listCategorieProduit = produitController.getAllCategorieProduit();
             }
             else
             {
                 MessageBox.Show("Echec de la supression", "Informations");
             }
         }
     }
 }
예제 #11
0
        private CategorieProduit creerCategorieFromView()
        {
            CategorieProduit res = null;

            if (comboBox_famille.SelectedIndex < 0)
            {
                return(null);
            }
            FamilleProduit famille = listFamille[comboBox_famille.SelectedIndex];

            if (famille != null)
            {
                try
                {
                    res = new CategorieProduit(textBoxNom.Text, famille);
                }
                catch
                {
                }
            }
            return(res);
        }
예제 #12
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CategorieProduit categorieToAdd = creerCategorieFromView();

            if (categorieToAdd != null)
            {
                int res = produitController.ajouterCategorieProduit(categorieToAdd);
                if (res == 1)
                {
                    MessageBox.Show("La catégorie a été rajouté");
                    textBoxNom.Text       = "";
                    comboBox_famille.Text = "";
                }
                else
                {
                    MessageBox.Show("Problème interne, la catégorie n'a pas été rajoutée");
                }
            }
            else
            {
                MessageBox.Show("Veuillez vérifier que les informations sont correctes (Bon format de date par exemple)");
            }
        }
예제 #13
0
        public int supprimerCategorieProduit(CategorieProduit categorie)
        {
            int res = transition.deleteCategorieProduitBy("id=" + categorie.Id);

            return(res);
        }
예제 #14
0
        public int ajouterCategorieProduit(CategorieProduit categorie)
        {
            int res = transition.addCategorieProduit(categorie);

            return(res);
        }
예제 #15
0
        public List <Produit> getProduitByCategorie(CategorieProduit selectedCategorieProduit)
        {
            List <Produit> resultat = transition.getAllProduitsBy("id_categorie_produit=" + selectedCategorieProduit.Id);

            return(resultat);
        }