예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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");
            }
        }
예제 #5
0
 //Construct
 public Cadeau(Enfant pUnEnfant, Jouet pUnJouet, DateTime pDate)
 {
     unEnfant = pUnEnfant;
     unJouet  = pUnJouet;
     date     = pDate;
 }