Esempio n. 1
0
        public List <Echantillon> RetrouverListeEchantillon(int idCompteRendu)
        {
            List <Echantillon> listeEchantillon = new List <Echantillon>();
            List <int[]>       listeId          = new List <int[]>();
            SqlCommand         command          = Connexion.GetInstance().CreateCommand();

            command.CommandText = "SELECT * FROM echantillon WHERE idCompteRendu = @idCompteRendu";
            command.Parameters.AddWithValue("@idCompteRendu", idCompteRendu);
            // Lecture des résultats
            SqlDataReader dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                int[] ids = new int[2];
                ids[0] = dataReader.GetInt32(1);
                ids[1] = dataReader.GetInt32(2);
                listeId.Add(ids);
            }
            dataReader.Close();

            foreach (int[] ids in listeId)
            {
                ProduitDAO produitDao = new ProduitDAO();
                Produit    produit    = produitDao.Read(ids[0]);

                Echantillon echantillon = new Echantillon(idCompteRendu, produit, ids[1]);
                listeEchantillon.Add(echantillon);
            }

            return(listeEchantillon);
        }
Esempio n. 2
0
        public Echantillon Read(int idCompteRendu, int idProduit)
        {
            Echantillon echantillon = null;
            SqlCommand  commande    = Connexion.GetInstance().CreateCommand();

            commande.CommandText = "SELECT quantite FROM produit WHERE idCompteRendu = @idCompteRendu AND idProduit = @idProduit";
            commande.Parameters.AddWithValue("@idCompteRendu", idCompteRendu);
            commande.Parameters.AddWithValue("@idProduit", echantillon.ProduitEchantillonne.Id);
            SqlDataReader datareader = commande.ExecuteReader();

            if (datareader.Read())
            {
                int quantite = datareader.GetInt32(0);
                datareader.Close();

                ProduitDAO produitDao = new ProduitDAO();
                Produit    produit    = produitDao.Read(idProduit);

                echantillon = new Echantillon(idCompteRendu, produit, quantite);
            }

            return(echantillon);
        }