Example #1
0
        public List <CategoriaProduct> getAllCategoryProducts()
        {
            List <CategoriaProduct> ListCategory = new List <CategoriaProduct>();

            string Query = "SELECT id, name  FROM categoriaproducto;";

            MySqlCommand Cmm = new MySqlCommand(Query, ConectDB.getConection());

            MySqlDataReader reader;

            reader = Cmm.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    newCategory      = new CategoriaProduct();
                    newCategory.Id   = (int)reader["id"];
                    newCategory.Name = (string)reader["name"];

                    ListCategory.Add(newCategory);
                }
            }

            Cmm.Connection.Close();

            return(ListCategory);
        }
Example #2
0
        public void insertCatproduct(CategoriaProduct _CatProduct)
        {
            try
            {
                if (ExistCatProduct(_CatProduct.Id))
                {
                    Query = "UPDATE categoriaproducto SET name='" + _CatProduct.Name.Trim() + "' WHERE id='" + _CatProduct.Id + "';";
                }
                else
                {
                    Query = "INSERT INTO categoriaproducto(name) values('" + _CatProduct.Name.Trim() + "');";
                }

                MySqlCommand Cmm = new MySqlCommand(Query, ConectDB.getConection());
                Cmm.ExecuteNonQuery();

                Cmm.Connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\ninsertCatProducto", "Error del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }