Пример #1
0
        public Produit Find(int id)
        {
            CategorieDAO     bdCat      = new CategorieDAO();
            List <Categorie> categories = bdCat.FindAll();

            Categorie c = null;
            Produit   m = null;

            try
            {
                cnx = ConnexionCoffe.GetInstance();
                MySqlCommand cmd = new MySqlCommand("select * from tproduit where id=@id", cnx);
                cmd.Parameters.Add("@id", id);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    foreach (Categorie med in categories)
                    {
                        if (med.IdCat.Equals(reader.GetInt32(3)))
                        {
                            c = med; break;
                        }
                    }
                    m = new Produit(reader.GetInt32("id"), reader.GetString(1), reader.GetString(2), c, reader.GetDecimal(4), (byte[])reader[5]);
                }
                cnx.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Requete recherche Produit : Find  \n " + ex.Message, "Attention");
            }
            return(m);
        }
Пример #2
0
        public List <Produit> FindToCat(int cat)
        {
            CategorieDAO     bdCat      = new CategorieDAO();
            List <Categorie> categories = bdCat.FindAll();
            Categorie        c          = null;

            List <Produit> res = new List <Produit>();

            try
            {
                cnx = ConnexionCoffe.GetInstance();
                MySqlCommand cmd = new MySqlCommand("select * from tproduit where idCateg=@idCateg", cnx);
                cmd.Parameters.Add("@idCateg", cat);//
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    foreach (Categorie med in categories)
                    {
                        if (med.IdCat.Equals(reader.GetInt32(3)))
                        {
                            c = med; break;
                        }
                    }
                    Produit m = new Produit(reader.GetInt32("id"), reader.GetString(1), reader.GetString(2), c, reader.GetDecimal(4), (byte[])reader[5]);
                    res.Add(m);
                }
                cnx.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Pb d'ouverture de la connexion \n " + ex.Message, "Attention");
            }
            return(res);
        }
Пример #3
0
        public List <Produit> FindAll()
        {
            CategorieDAO     bdCat      = new CategorieDAO();
            List <Categorie> categories = bdCat.FindAll();
            Categorie        c          = null;

            List <Produit> res         = new List <Produit>();
            ArrayList      ProduitList = new ArrayList();


            try
            {
                cnx = ConnexionCoffe.GetInstance();
                MySqlCommand    cmd    = new MySqlCommand("select * from tproduit", cnx);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    foreach (Categorie med in categories)
                    {
                        if (med.IdCat.Equals(reader.GetInt32(3)))
                        {
                            c = med; break;
                        }
                    }

                    Produit m = new Produit(reader.GetInt32("id"), reader.GetString(1), reader.GetString(2), c, reader.GetDecimal(4), (byte[])reader[5]);
                    res.Add(m);
                }
                // reader.Close();
                cnx.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Produit : Pb de FindAll \n " + ex.Message, "Attention");
            }
            return(res);
        }