示例#1
0
        /*
         * Adds a product to the Data Base
         * Paramaters: product to create
         * Returns: true if the product could be created, false on the contrary
         */
        public bool CreateProduct(ENProduct product)
        {
            bool          created   = false;
            SqlConnection conection = new SqlConnection(constring);

            try{
                conection.Open();

                using (SqlCommand cmd = new SqlCommand("", conection)){
                    cmd.CommandText = "INSERT INTO Product(name, pvp, stock, brand, type, description, urlImage) values ('"
                                      + product.name + "'," + product.price + ", " + product.stock + ", '" + product.brand + "', '"
                                      + product.@type + "', '" + product.description + "', '" + product.url + "');";

                    cmd.ExecuteNonQuery();
                }

                created = true;
            }catch (SqlException ex) {
                Console.WriteLine("Error al crear product. ", ex.Message);
            }finally{
                conection.Close();
            }


            return(created);
        }
示例#2
0
        /*
         * Updates the product in the DataBase
         * Parameters: product to update
         * Return: true in case that the product could be updated
         */
        public bool UpdateProduct(ENProduct product)
        {
            bool updated = true;

            SqlConnection conection = new SqlConnection(constring);

            try
            {
                conection.Open();
                using (SqlCommand cmd = new SqlCommand("", conection))
                {
                    cmd.CommandText = "UPDATE Product set stock=" + product.stock + " where cod='" + product.id + "';";
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException Ex)
            {
                Console.WriteLine("No se ha podido recuperar el producto de la base de datos.", Ex.Message);
                updated = false;
            }
            finally
            {
                conection.Close();
            }


            return(updated);
        }
示例#3
0
        public DataTable ReadProductCat(ENProduct product)
        {
            SqlConnection con = new SqlConnection(constring);

            DataSet set = new DataSet();

            SqlDataAdapter ad = new SqlDataAdapter("Select * from Product;", con);

            ad.Fill(set, "Product");

            DataTable tb = new DataTable();

            tb = set.Tables["Product"];
            return(tb);
        }
示例#4
0
        //Read product form data base when you click on the catalog
        public bool ReadProductFromCatalog(ENProduct product)
        {
            bool read = false;

            SqlConnection conection = new SqlConnection(constring);

            try{
                conection.Open();

                using (SqlCommand cmd = new SqlCommand("", conection)){
                    cmd.CommandText = "SELECT * FROM Product where cod = '" + product.id + "';";

                    SqlDataReader productRead = cmd.ExecuteReader();

                    while (productRead.Read())
                    {
                        product.id          = Convert.ToInt32(productRead[0]);
                        product.name        = Convert.ToString(productRead[1]);
                        product.price       = float.Parse(Convert.ToString(productRead[2]));
                        product.stock       = Convert.ToInt32(productRead[3]);
                        product.brand       = Convert.ToString(productRead[4]);
                        product.type        = Convert.ToString(productRead[5]);
                        product.description = Convert.ToString(productRead[6]);
                        product.url         = Convert.ToString(productRead[7]);
                    }

                    productRead.Close();
                }

                read = true;
            }
            catch (SqlException Ex)
            {
                Console.WriteLine("No se ha podido recuperar el producto de la base de datos.", Ex.Message);
            }
            finally
            {
                conection.Close();
            }



            return(read);
        }
示例#5
0
        /*
         * Deletes the product in the Data Base
         * Parameters: product to delete
         * Return: true in case that the product could be deleted, false on the contrary
         */
        public bool DeleteProduct(ENProduct product)
        {
            bool deleted = false;

            return(deleted);
        }