コード例 #1
0
        public choix UpdateChoix(int id, string unChoix)
        {
            choix choix = db.choixes.Find(id);

            choix.contenu = unChoix;

            db.SaveChanges();
            return(choix);
        }
コード例 #2
0
        public choix AddChoix(question q, string c)
        {
            choix choix = new choix(c, q);

            db.choixes.Add(choix);
            db.SaveChanges();

            question qu = db.questions.Find(q.Id);

            qu.choixes.Add(choix);
            choix.Id_Question     = qu.Id;
            db.Entry(qu).State    = System.Data.Entity.EntityState.Modified;
            db.Entry(choix).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(choix);
        }
コード例 #3
0
 public void AjouterModifierProduit(Product p, choix c)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
    public void AjouterModifierProduit(Product p, choix c)
    {
        if (c == choix.creer)
        {
            var cmd = new SqlCommand();

            cmd.CommandText = @"insert product (categoryid, Name, supplierID, unitprice, unitsinstock) 
values (@categoryid, @Name, @supplierID, @unitprice, @unitsinstock)

";
            var param1 = new SqlParameter
            {
                SqlDbType     = SqlDbType.UniqueIdentifier,
                ParameterName = "@categoryid",
                Value         = p.Categoryid
            };
            cmd.Parameters.Add(param1);
            var param2 = new SqlParameter
            {
                SqlDbType     = SqlDbType.NVarChar,
                ParameterName = "@Name",
                Value         = p.Name
            };
            cmd.Parameters.Add(param2);

            var param3 = new SqlParameter
            {
                SqlDbType     = SqlDbType.Int,
                ParameterName = "@supplierID",
                Value         = p.Supplierid
            };
            cmd.Parameters.Add(param3);

            var param4 = new SqlParameter
            {
                SqlDbType     = SqlDbType.Money,
                ParameterName = "@unitprice",
                Value         = p.UnitPrice
            };
            cmd.Parameters.Add(param4);

            var param5 = new SqlParameter
            {
                SqlDbType     = SqlDbType.SmallInt,
                ParameterName = "@unitsinstock",
                Value         = p.UnitsInStock
            };
            cmd.Parameters.Add(param5);


            using (var cnx = new SqlConnection(Settings1.Default.Northwind2Connect))
            {
                cmd.Connection = cnx;
                cnx.Open();

                cmd.ExecuteNonQuery();
            }
        }

        else if (c == choix.modifier)
        {
            var cmd = new SqlCommand();

            cmd.CommandText = @"update product set categoryid=@categoryid,
                                Name=@Name, supplierID=@supplierID, 
                                unitprice=@unitprice, unitsinstock=@unitsinstock 
                                  where productid=@id1
                                ";
            cmd.Parameters.Add(new SqlParameter {
                SqlDbType = SqlDbType.Int, ParameterName = "@id1", Value = p.Productid
            });

            var param1 = new SqlParameter
            {
                SqlDbType     = SqlDbType.UniqueIdentifier,
                ParameterName = "@categoryid",
                Value         = p.Categoryid
            };
            cmd.Parameters.Add(param1);
            var param2 = new SqlParameter
            {
                SqlDbType     = SqlDbType.NVarChar,
                ParameterName = "@Name",
                Value         = p.Name
            };
            cmd.Parameters.Add(param2);

            var param3 = new SqlParameter
            {
                SqlDbType     = SqlDbType.Int,
                ParameterName = "@supplierID",
                Value         = p.Supplierid
            };
            cmd.Parameters.Add(param3);

            var param4 = new SqlParameter
            {
                SqlDbType     = SqlDbType.Money,
                ParameterName = "@unitprice",
                Value         = p.UnitPrice
            };
            cmd.Parameters.Add(param4);

            var param5 = new SqlParameter
            {
                SqlDbType     = SqlDbType.SmallInt,
                ParameterName = "@unitsinstock",
                Value         = p.UnitsInStock
            };
            cmd.Parameters.Add(param5);


            using (var cnx = new SqlConnection(Settings1.Default.Northwind2Connect))
            {
                cmd.Connection = cnx;
                cnx.Open();

                cmd.ExecuteNonQuery();
            }
        }
    }