Example #1
0
        public void AjouterModifierProduit(Product produit, typeOperation operation)
        {
            var cmd = new SqlCommand();

            if (operation == typeOperation.Ajout)
            {
                cmd.CommandText = @"Insert  Product ( CategoryId, SupplierId, Name, UnitPrice, UnitsInStock)
                                Values ( @IdCat, @IdFour, @nom, @prix, @stock)
                                    ";
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.UniqueIdentifier,
                    ParameterName = "@IdCat",
                    Value         = produit.CategoryId
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.Int,
                    ParameterName = "@IdFour",
                    Value         = produit.SupplierId
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.NVarChar,
                    ParameterName = "@nom",
                    Value         = produit.Name
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.Money,
                    ParameterName = "@prix",
                    Value         = produit.UnitPrice
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.SmallInt,
                    ParameterName = "@stock",
                    Value         = produit.UnitsInStock
                });
            }

            else if (operation == typeOperation.Modification)
            {
                cmd.CommandText = @"Update Product set Name = @nom, CategoryId =  @IdCat, SupplierId = @IdFour, UnitPrice = @prix, UnitsInStock = @stock
                                     where ProductId =  @Id
                                   ";
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.Int,
                    ParameterName = "@Id",
                    Value         = produit.ProductId,
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.NVarChar,
                    ParameterName = "@nom",
                    Value         = produit.Name
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.UniqueIdentifier,
                    ParameterName = "@IdCat",
                    Value         = produit.CategoryId
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.Int,
                    ParameterName = "@IdFour",
                    Value         = produit.SupplierId
                });

                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.Money,
                    ParameterName = "@prix",
                    Value         = produit.UnitPrice
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    SqlDbType     = SqlDbType.SmallInt,
                    ParameterName = "@stock",
                    Value         = produit.UnitsInStock
                });
            }

            using (var cnx = new SqlConnection(Settings.Default.Northwind2Connect))
            {
                cmd.Connection = cnx;
                cnx.Open();
                cmd.ExecuteNonQuery();
            }
        }
Example #2
0
 public void AjouterModifierProduit(Product produit, typeOperation operation)
 {
     throw new NotImplementedException();
 }