Esempio n. 1
0
        private void formEmploye_Load(object sender, EventArgs e)
        {
            cbCateg.DisplayMember = "Infos";
            cbCateg.ValueMember   = "Id";
            cbCateg.DataSource    = CategorieDAO.findAll();

            cbAEnfants.DisplayMember = "Infos";
            cbAEnfants.ValueMember   = "Id";
            cbAEnfants.DataSource    = EnfantDAO.findByEmploye(id);

            List <Cadeau> lesCadeaux = new List <Cadeau>();

            try { lesCadeaux = CadeauDAO.findEnfants(id); }
            catch { MessageBox.Show("Problème avec la fonction pour trouver les jouets."); }

            try
            {
                Int32 i = 0;
                foreach (Cadeau leCadeau in lesCadeaux)
                {
                    dataGridView1.Rows.Insert(i, leCadeau.getEnfant().getPrenom(), leCadeau.getJouet().getLibelle(), leCadeau.getDate());
                    i++;
                }
            }
            catch
            {
                MessageBox.Show("Impossible d'afficher les jouets des enfants");
            }
        }
Esempio n. 2
0
        //Read
        public override Jouet find(int pId)
        {
            Jouet unJouet = null;

            try
            {
                String        requete    = "SELECT * FROM Jouet WHERE id =" + pId;
                SqlCommand    maCommande = new SqlCommand(requete, seConnecter());
                SqlDataReader resultat   = maCommande.ExecuteReader();

                if (resultat.Read())
                {
                    int          id              = (int)resultat["id"];
                    string       libelle         = (string)resultat["libelle"];
                    int          idCategorie     = (int)resultat["idCategorie"];
                    int          idTranche       = (int)resultat["idTranche"];
                    CategorieDAO uneCategorieDAO = new CategorieDAO();
                    Categorie    uneCategorie    = uneCategorieDAO.find(idCategorie);
                    TrancheDAO   uneTrancheDAO   = new TrancheDAO();
                    TrancheAge   uneTranche      = uneTrancheDAO.find(idTranche);
                    unJouet = new Jouet(id, libelle, uneCategorie, uneTranche);
                }
                resultat.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Oups: " + ex);
            }

            return(unJouet);
        }
Esempio n. 3
0
        private void btnSupprCateg_Click(object sender, EventArgs e)
        {
            int idCateg = (int)cbAffCateg.SelectedValue;
            var result  = MessageBox.Show("Vous êtes sûr de vouloir supprimer cette catégorie?(Et tous les jouets qui y sont reliés)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                CategorieDAO uneDAO   = new CategorieDAO();
                Categorie    uneCateg = uneDAO.find(idCateg);
                Boolean      check    = uneDAO.delete(uneCateg);
                if (check == true)
                {
                    MessageBox.Show("Catégorie supprimée.");
                }
                else
                {
                    MessageBox.Show("Incident dans la suppression de la catégorie.");
                }
            }
            else
            {
                MessageBox.Show("Suppression annulée.");
            }
            cbAffCateg.DataSource    = CategorieDAO.findAll();
            cbAffCateg.DisplayMember = "Infos";
            cbAffCateg.ValueMember   = "Id";
        }
Esempio n. 4
0
        private void formResponsable_Load(object sender, EventArgs e)
        {
            cbEmployes.DataSource    = UtilisateurDAO.findAllEmployes();
            cbEmployes.DisplayMember = "Infos";
            cbEmployes.ValueMember   = "Id";

            cbEnfants.DataSource    = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue);
            cbEnfants.DisplayMember = "Infos";
            cbEnfants.ValueMember   = "Id";

            cbEmployeAff.DataSource    = UtilisateurDAO.findAllEmployes();
            cbEmployeAff.DisplayMember = "Infos";
            cbEmployeAff.ValueMember   = "Id";

            cbAffCateg.DataSource    = CategorieDAO.findAll();
            cbAffCateg.DisplayMember = "Infos";
            cbAffCateg.ValueMember   = "Id";

            cbCategJouet.DataSource    = CategorieDAO.findAll();
            cbCategJouet.DisplayMember = "Infos";
            cbCategJouet.ValueMember   = "Id";

            List <Jouet> lesJouets   = new List <Jouet>();
            CategorieDAO uneCategDAO = new CategorieDAO();
            Categorie    uneCateg    = uneCategDAO.find((int)cbCategJouet.SelectedValue);

            try { lesJouets = JouetDAO.findByCateg(uneCateg); }
            catch { MessageBox.Show("Problème avec la fonction pour trouver les jouets."); }
            try
            {
                Int32 i = 0;
                foreach (Jouet j in lesJouets)
                {
                    dGVJouets.Rows.Insert(i, j.getLibelle());
                    i++;
                }
            }
            catch
            {
                MessageBox.Show("Impossible d'afficher les jouets des enfants");
            }
        }
Esempio n. 5
0
        public static Jouet findByNom(String pNom)
        {
            String        requete    = "SELECT * FROM Jouet WHERE libelle = '" + pNom + "'";
            SqlCommand    maCommande = new SqlCommand(requete, seConnecter());
            SqlDataReader resultat   = maCommande.ExecuteReader();

            Jouet unJouet = null;

            if (resultat.Read())
            {
                int          id              = (int)resultat["id"];
                int          idCategorie     = (int)resultat["idCategorie"];
                int          idTranche       = (int)resultat["idTranche"];
                CategorieDAO uneCategorieDAO = new CategorieDAO();
                Categorie    uneCategorie    = uneCategorieDAO.find(idCategorie);
                TrancheDAO   uneTrancheDAO   = new TrancheDAO();
                TrancheAge   uneTranche      = uneTrancheDAO.find(idTranche);
                unJouet = new Jouet(id, pNom, uneCategorie, uneTranche);
            }
            resultat.Close();
            return(unJouet);
        }
Esempio n. 6
0
        private void cbCategJouet_SelectedIndexChanged(object sender, EventArgs e)
        {
            dGVJouets.Rows.Clear();
            List <Jouet> lesJouets   = new List <Jouet>();
            CategorieDAO uneCategDAO = new CategorieDAO();
            Categorie    uneCateg    = uneCategDAO.find((int)cbCategJouet.SelectedValue);

            try { lesJouets = JouetDAO.findByCateg(uneCateg); }
            catch { MessageBox.Show("Problème avec la fonction pour trouver les jouets."); }
            try
            {
                Int32 i = 0;
                foreach (Jouet j in lesJouets)
                {
                    dGVJouets.Rows.Insert(i, j.getLibelle());
                    i++;
                }
            }
            catch
            {
                MessageBox.Show("Impossible d'afficher les jouets des enfants");
            }
        }
Esempio n. 7
0
 private void btnModifCateg_Click(object sender, EventArgs e)
 {
     if (tbModifCateg.Text != "")
     {
         int          id          = (int)cbAffCateg.SelectedValue;
         string       libelle     = tbModifCateg.Text;
         CategorieDAO uneCategDAO = new CategorieDAO();
         Categorie    uneCateg    = uneCategDAO.find(id);
         uneCateg.setLibelle(libelle);
         Boolean check = uneCategDAO.update(uneCateg);
         if (check == true)
         {
             MessageBox.Show("Catégorie modifié.");
         }
         else
         {
             MessageBox.Show("Incident dans la modification de la catégorie.");
         }
     }
     cbAffCateg.DataSource    = CategorieDAO.findAll();
     cbAffCateg.DisplayMember = "Infos";
     cbAffCateg.ValueMember   = "Id";
 }
Esempio n. 8
0
        private void btnAddCateg_Click(object sender, EventArgs e)
        {
            if (tbAddCateg.Text != "")
            {
                int id = DAO <Categorie> .NumMax("Catégorie", "id");

                string       libelle     = tbAddCateg.Text;
                CategorieDAO uneCategDAO = new CategorieDAO();
                Categorie    uneCateg    = new Categorie(id, libelle);
                Boolean      check       = uneCategDAO.create(uneCateg);
                if (check == true)
                {
                    MessageBox.Show("Catégorie ajouté.");
                }
                else
                {
                    MessageBox.Show("Incident dans l'ajout de la catégorie.");
                }
            }
            cbAffCateg.DataSource    = CategorieDAO.findAll();
            cbAffCateg.DisplayMember = "Infos";
            cbAffCateg.ValueMember   = "Id";
        }
Esempio n. 9
0
        private void cbAEnfants_SelectedIndexChanged(object sender, EventArgs e)
        {
            dGVJouet.Rows.Clear();
            //Enfant
            Int32     idEnfant = (int)cbAEnfants.SelectedValue;
            Enfant    unEnfant;
            EnfantDAO unEnfantDAO = new EnfantDAO();

            try
            {
                unEnfant = unEnfantDAO.find(idEnfant);
            }
            catch (Exception ex)
            {
                unEnfant = null;
                throw new Exception("Oups: " + ex);
            }
            Int32        idCateg     = (Int32)cbCateg.SelectedValue;
            TrancheAge   uneTranche  = null;
            CategorieDAO uneCategDAO = new CategorieDAO();
            Categorie    uneCateg;

            try
            {
                uneCateg = uneCategDAO.find(idCateg);
            }
            catch
            {
                MessageBox.Show("catégorie inexistante");
                uneCateg = null;
            }

            Int32 ageValeur = unEnfant.getAge();

            if (ageValeur >= 1 && ageValeur <= 2)
            {
                uneTranche = new TrancheAge(1, 1, 2);
            }
            else if (ageValeur >= 3 && ageValeur <= 5)
            {
                uneTranche = new TrancheAge(2, 3, 5);
            }
            else if (ageValeur >= 6 && ageValeur <= 10)
            {
                uneTranche = new TrancheAge(3, 6, 10);
            }
            else if (ageValeur >= 11 && ageValeur <= 13)
            {
                uneTranche = new TrancheAge(4, 11, 13);
            }
            else if (ageValeur >= 14 && ageValeur <= 17)
            {
                uneTranche = new TrancheAge(5, 14, 17);
            }
            else
            {
                MessageBox.Show("Cet enfant est trop âgé");
            }

            //Categorie uneCateg = new Categorie(1, "Action");

            if (uneTranche != null)
            {
                List <Jouet> lesJouets = JouetDAO.findByTrancheCateg(uneTranche, uneCateg);

                Int32 i = 0;
                foreach (Jouet leJouet in lesJouets)
                {
                    dGVJouet.Rows.Insert(i, leJouet.getLibelle(), uneCateg.getLibelle());
                    i++;
                }
            }
        }