Ejemplo n.º 1
0
        public Cadeau findByEnfant(Int32 idE)
        {
            Cadeau unCadeau = null;

            try
            {
                String        requete    = "SELECT * FROM Cadeau WHERE idEnfant = " + idE;
                SqlCommand    maCommande = new SqlCommand(requete, seConnecter());
                SqlDataReader resultat   = maCommande.ExecuteReader();
                if (resultat.Read())
                {
                    int       idEnfant    = (int)resultat["idEnfant"];
                    int       idJouet     = (int)resultat["idJouet"];
                    DateTime  date        = (DateTime)resultat["date"];
                    EnfantDAO unEnfantDAO = new EnfantDAO();
                    JouetDAO  unJouetDAO  = new JouetDAO();
                    Enfant    unEnfant    = unEnfantDAO.find(idEnfant);
                    Jouet     unJouet     = unJouetDAO.find(idJouet);
                    unCadeau = new Cadeau(unEnfant, unJouet, date);
                }
                else
                {
                }
                resultat.Close();
            }
            catch
            {
            }
            return(unCadeau);
        }
Ejemplo n.º 2
0
        //Read
        public override Cadeau find(int pIdE)
        {
            Cadeau    unCadeau    = null;
            EnfantDAO unEnfantDAO = new EnfantDAO();
            JouetDAO  unJouetDAO  = new JouetDAO();

            try
            {
                String        requete    = "SELECT * FROM Cadeau WHERE idEnfant = " + pIdE;
                SqlCommand    maCommande = new SqlCommand(requete, seConnecter());
                SqlDataReader resultat   = maCommande.ExecuteReader();
                if (resultat.Read())
                {
                    int      idEnfant = (int)resultat["idEnfant"];
                    int      idJouet  = (int)resultat["idJouet"];
                    DateTime date     = (DateTime)resultat["date"];
                    Enfant   unEnfant = unEnfantDAO.find(idEnfant);
                    Jouet    unJouet  = unJouetDAO.find(idJouet);
                    unCadeau = new Cadeau(unEnfant, unJouet, date);
                }
                resultat.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Oups: " + ex);
            }
            return(unCadeau);
        }
Ejemplo n.º 3
0
        //Delete
        public override bool delete(Utilisateur unUtilisateur)
        {
            List <Enfant> sesEnfants = EnfantDAO.findByEmploye(unUtilisateur.getId());

            if (sesEnfants.Count() != 0)
            {
                try
                {
                    EnfantDAO unDAO = new EnfantDAO();
                    foreach (Enfant e in sesEnfants)
                    {
                        unDAO.delete(e);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Oups: " + ex);
                }
            }
            Boolean retour = false;

            try
            {
                String     requete    = "DELETE FROM Utilisateur WHERE id=" + unUtilisateur.getId();
                SqlCommand maCommande = new SqlCommand(requete, seConnecter());
                Int32      resultat   = maCommande.ExecuteNonQuery();
                retour = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Oups: " + ex);
            }
            return(retour);
        }
Ejemplo n.º 4
0
        //AFFICHAGE CADEAUX ENFANTS DE L'EMPLOYE CONNECTE
        public static List <Cadeau> findEnfants(int pIdEmploye)
        {
            List <Cadeau> lesCadeaux = new List <Cadeau>();

            try
            {
                String        requete    = "SELECT * FROM Cadeau WHERE idEnfant IN (SELECT id FROM Enfant WHERE idUtilisateur = " + pIdEmploye + ")";
                SqlCommand    maCommande = new SqlCommand(requete, seConnecter());
                SqlDataReader resultat   = maCommande.ExecuteReader();

                while (resultat.Read())
                {
                    int       idEnfant    = (int)resultat["idEnfant"];
                    int       idJouet     = (int)resultat["idJouet"];
                    DateTime  date        = (DateTime)resultat["date"];
                    EnfantDAO unEnfantDAO = new EnfantDAO();
                    JouetDAO  unJouetDAO  = new JouetDAO();
                    Enfant    unEnfant    = unEnfantDAO.find(idEnfant);
                    Jouet     unJouet     = unJouetDAO.find(idJouet);
                    Cadeau    unCadeau    = new Cadeau(unEnfant, unJouet, date);
                    lesCadeaux.Add(unCadeau);
                }
                resultat.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Oups: " + ex);
            }
            return(lesCadeaux);
        }
Ejemplo n.º 5
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");
            }
        }
Ejemplo n.º 6
0
        private void button4_Click(object sender, EventArgs e)
        {
            int id = DAO <Enfant> .NumMax("Enfant", "id");

            int idEmploye = (Int32)cbEmployes.SelectedValue;

            if (txtBxAge.Text != "" && txtBxPrenom.Text != "")
            {
                string prenom = txtBxPrenom.Text;
                Int32  age    = 0;
                if (Int32.TryParse(txtBxAge.Text, out age))
                {
                    UtilisateurDAO unUtilisateurDAO = new UtilisateurDAO();
                    Enfant         unEnfant         = new Enfant(id, age, prenom, unUtilisateurDAO.find(idEmploye));
                    EnfantDAO      enfantDao        = new EnfantDAO();
                    Boolean        check            = enfantDao.create(unEnfant);
                    if (check == true)
                    {
                        MessageBox.Show("Enfant ajouté.");
                    }
                    else
                    {
                        MessageBox.Show("Incident dans l'ajout de l'enfant.");
                    }
                }
            }
            else
            {
                MessageBox.Show("Veuillez remplir tous les champs.");
            }
            cbEnfants.DataSource    = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue);
            cbEnfants.DisplayMember = "Infos";
            cbEnfants.ValueMember   = "Id";
        }
Ejemplo n.º 7
0
        private void btnSupprEnfant_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Vous êtes sûr de vouloir supprimer cet enfant?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                int            idEnfant         = (Int32)cbEnfants.SelectedValue;
                UtilisateurDAO unUtilisateurDAO = new UtilisateurDAO();
                EnfantDAO      enfantDao        = new EnfantDAO();
                Enfant         unEnfant         = enfantDao.find(idEnfant);
                Boolean        check            = enfantDao.delete(unEnfant);
                if (check == true)
                {
                    MessageBox.Show("Enfant supprimé.");
                }
                else
                {
                    MessageBox.Show("Incident dans la suppression de l'enfant.");
                }
            }
            else
            {
                MessageBox.Show("Suppression annulée");
            }
            cbEnfants.DataSource    = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue);
            cbEnfants.DisplayMember = "Infos";
            cbEnfants.ValueMember   = "Id";
        }
Ejemplo n.º 8
0
        private void button4_Click(object sender, EventArgs e)
        {
            String nom     = (string)dGVJouet.CurrentRow.Cells["Nom"].Value;
            Jouet  unJouet = JouetDAO.findByNom(nom);

            DateTime localDate = DateTime.Now;

            Int32     idEnfant    = (int)cbAEnfants.SelectedValue;
            EnfantDAO unEnfantDAO = new EnfantDAO();
            Enfant    unEnfant    = unEnfantDAO.find(idEnfant);

            Cadeau    unCadeau    = new Cadeau(unEnfant, unJouet, localDate);
            CadeauDAO unCadeauDAO = new CadeauDAO();

            if (unCadeauDAO.findByEnfant(idEnfant) == null)
            {
                unCadeauDAO.create(unCadeau);
                MessageBox.Show("Cadeau ajouté...");
            }
            else
            {
                unCadeauDAO.update(unCadeau);
                MessageBox.Show("Cadeau modifié...");
            }

            dataGridView1.Rows.Clear();


            //Affichage cadeaux
            List <Cadeau> lesCadeaux = new List <Cadeau>();

            try { lesCadeaux = CadeauDAO.findEnfants(id); }
            catch { MessageBox.Show("Problème avec la fonction 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");
            }
        }
Ejemplo n.º 9
0
        public override string ToString()
        {
            string retour = "";

            if (TypeU == 2)
            {
                List <Enfant> lesEnfants = new List <Enfant>(EnfantDAO.findByEmploye(id));
                foreach (Enfant unEnfant in lesEnfants)
                {
                    retour += unEnfant.getPrenom() + "\t" + unEnfant.getAge() + "ans \n";
                }
            }
            else if (TypeU == 1)
            {
                retour = "id = " + id + "  mdp = " + mdp + "  type = " + TypeU;
            }
            return(retour);
        }
Ejemplo n.º 10
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");
            }
        }
Ejemplo n.º 11
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++;
                }
            }
        }
Ejemplo n.º 12
0
 private void cbEmployes_SelectedIndexChanged(object sender, EventArgs e)
 {
     cbEnfants.DataSource    = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue);
     cbEnfants.DisplayMember = "Infos";
     cbEnfants.ValueMember   = "Id";
 }
Ejemplo n.º 13
0
        private void button6_Click(object sender, EventArgs e)
        {
            int       id          = (Int32)cbEnfants.SelectedValue;
            int       idEmploye   = (Int32)cbEmployes.SelectedValue;
            EnfantDAO unEnfantDAO = new EnfantDAO();
            Enfant    unEnfant    = unEnfantDAO.find(id);

            if (tbModifAge.Text != "" && tbModifPrenom.Text != "")
            {
                string prenom = tbModifPrenom.Text;
                Int32  age    = 0;
                if (Int32.TryParse(tbModifAge.Text, out age))
                {
                    unEnfant.setAge(age);
                    unEnfant.setPrenom(prenom);
                    Boolean check = unEnfantDAO.update(unEnfant);
                    if (check == true)
                    {
                        MessageBox.Show("Enfant modifié.");
                    }
                    else
                    {
                        MessageBox.Show("Incident dans la modification de l'enfant.");
                    }
                }
            }
            else if (tbModifAge.Text != "")
            {
                Int32 age = 0;
                if (Int32.TryParse(tbModifAge.Text, out age))
                {
                    unEnfant.setAge(age);
                    Boolean check = unEnfantDAO.update(unEnfant);
                    if (check == true)
                    {
                        MessageBox.Show("Enfant modifié.");
                    }
                    else
                    {
                        MessageBox.Show("Incident dans la modification de l'enfant.");
                    }
                }
            }
            else if (tbModifPrenom.Text != "")
            {
                string prenom = tbModifPrenom.Text;
                unEnfant.setPrenom(prenom);
                Boolean check = unEnfantDAO.update(unEnfant);
                if (check == true)
                {
                    MessageBox.Show("Enfant modifié.");
                }
                else
                {
                    MessageBox.Show("Incident dans la modification de l'enfant.");
                }
            }
            else
            {
                MessageBox.Show("Veuillez remplir au moins un des champs ci-dessus.");
            }
            cbEnfants.DataSource    = EnfantDAO.findByEmploye((Int32)cbEmployes.SelectedValue);
            cbEnfants.DisplayMember = "Infos";
            cbEnfants.ValueMember   = "Id";
        }