Ejemplo n.º 1
0
        private void btnajouterjouet_Click(object sender, EventArgs e)
        {
            Int32  prix;
            string libelle = txtnomjouet.Text;

            prix = Int32.Parse(txtprix.Text);



            //Int32 idcat = Int32.Parse(cbcat.Text);
            //Int32 idtranche = Int32.Parse(cbtrancheage.Text);
            Jouet unjouet = new Jouet(libelle, prix, (Categorie)cbcat.SelectedValue, (Trancheage)cbtrancheage.SelectedValue);

            try
            {
                JouetDAO jouetaadd = new JouetDAO();
                jouetaadd.create(unjouet);
                //Passerelle.Ajouterjouet(unjouet);
                MessageBox.Show("Votre jouet a ete ajouté !");
                txtnomjouet.Clear();
                txtprix.Clear();
            }
            catch
            {
                MessageBox.Show("erreur de saisie !");
            }
        }
Ejemplo n.º 2
0
        public static bool Ajouterjouet(Jouet unjouet)
        {
            seConnecter();
            Int32      num;
            SqlCommand maCommande, maCommande2;
            string     requete1 = "SELECT max(id) FROM Jouet";

            maCommande2 = new SqlCommand(requete1, laConnection);
            num         = (int)maCommande2.ExecuteScalar();
            num        += 1;
            string requete2 = "insert into dbo.Jouet values(" + num + ",'" + unjouet.getLibelle() + "','" + unjouet.getPrix() + "','" + unjouet.getcategorie().getId() + "'," + unjouet.gettrancheage().getCode() + ")";

            maCommande = new SqlCommand(requete2, laConnection);
            int nb = maCommande.ExecuteNonQuery();

            return(true);
        }