public void InsertCategory(string name, string description)
    {
        try
        {
            name        = name.TrimEnd().TrimStart();
            description = description.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Categoría");
        }

        CategoriesDAO   dao        = new CategoriesDAO();
        List <Category> categories = GetAllCategories();

        if (categories.FindAll(c => (c.name.ToUpperInvariant().Equals(name.ToUpperInvariant()))).Count > 0)
        {
            throw new Exception("Ya existe una Categoría con este nombre");
        }

        Category newCategory = new Category();

        newCategory.name        = name;
        newCategory.description = description;
        int result = dao.CreateCategory(newCategory);

        if (result < 1)
        {
            throw new Exception("No es posible registrar la Categoría");
        }
    }
Example #2
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            bool result = false;

            try
            {
                DialogResult res = MessageBox.Show("¿Desea eliminar la categoria?",
                                                   "My Store Desktop", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    int fila = dgvDatos.CurrentRow.Index;
                    categoria = categorias.ElementAt(fila);
                    CategoriesDAO cDAO = new CategoriesDAO();
                    result = cDAO.Delete(categoria.CategoryID);
                    if (result)
                    {
                        GetCategorias();
                    }
                    else
                    {
                        MessageBox.Show("Error al eliminar la categoria",
                                        "My Store Desktop", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al eliminar la categoria: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try {
                Regex match = new Regex(@"^[A-Z]+[a-zA-Z0-9''-'\s]*$");
                if (categoriaTxt.MaxLength <= 15 && match.IsMatch(categoriaTxt.Text))
                {
                    bool          band;
                    CategoriesDAO oDAO = new CategoriesDAO();
                    if (AgregarBtn.Text.Equals("Agregar"))
                    {
                        categoria = new Categories();
                        PasarObjeto();
                        band = oDAO.Create(categoria);
                    }
                    else
                    {
                        PasarObjeto();
                        band = oDAO.Update(categoria);
                    }

                    if (band)
                    {
                        GetCategorias();
                        LimpiarControles();
                    }
                }
                else
                {
                    MessageBox.Show("No se permiten los siguientes aspectos:\n" + "Categoría" + " vacío,\nCapitalización,\nNo empezar con un número,\nMáximo a 15 caracteres.");
                }
            } catch (Exception ex) {
                MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        public void InitWindow()
        {
            // Configuración de los combos
            cmbSupplier.DataSource    = SuppliersDAO.Select();
            cmbSupplier.DisplayMember = "CompanyName";
            cmbSupplier.ValueMember   = "SupplierId";

            cmbCategory.DataSource    = CategoriesDAO.Select();
            cmbCategory.DisplayMember = "CategoryName";
            cmbCategory.ValueMember   = "CategoryId";

            txtProductName.Focus();

            if (Prod == null)
            {
                return;
            }

            // Modo edición
            lblTitle.Text = "Editar producto";

            txtProductName.Text       = Prod.ProductName;
            cmbSupplier.SelectedValue = Prod.SupplierID;
            cmbCategory.SelectedValue = Prod.CategoryID;
            txtQuantityPerUnit.Text   = Prod.QuantityPerUnit;
            nmUnitPrice.Value         = (decimal)Prod.UnitPrice;
            nmUnitsInStock.Value      = Prod.UnitsInStock;
            nmUnitsOnOrder.Value      = Prod.UnitsOnOrder;
            nmReorderLevel.Value      = Prod.ReorderLevel;
            chkDescontinued.Checked   = Prod.Discontinued != 0;
        }
Example #5
0
        public JsonResult Restore(int?id)
        {
            var dao = new CategoriesDAO();

            if (dao.ChangeBin(id))
            {
                List <Category>    categories = db.Categories.Where(n => n.category_bin == true).OrderByDescending(n => n.category_datecreate).ToList();
                List <jCategories> list       = categories.Select(n => new jCategories
                {
                    category_active     = n.category_active,
                    category_bin        = n.category_bin,
                    category_datecreate = n.category_datecreate.Value.ToString("dd/MM/yyyy"),
                    category_dateupdate = n.category_dateupdate.Value.ToString("dd/MM/yyyy"),
                    category_id         = n.category_id,
                    category_img        = n.category_img,
                    category_name       = n.category_name,
                    category_note       = n.category_note,
                    category_view       = n.category_view,
                }).ToList();
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(null));
            }
        }
Example #6
0
        //Hàm xoá
        public JsonResult DeleteCate(int?id)
        {
            var dao = new CategoriesDAO();
            var j   = new JsonAdminController();

            if (dao.Delete(id))
            {
                List <Category>    categories = db.Categories.Where(n => n.category_bin == true).OrderBy(n => n.category_name).ToList();
                List <jCategories> list       = categories.Select(n => new jCategories
                {
                    category_active     = n.category_active,
                    category_bin        = n.category_bin,
                    category_id         = n.category_id,
                    category_name       = n.category_name,
                    category_note       = n.category_note,
                    category_view       = n.category_view,
                    user_id             = n.user_id,
                    category_datecreate = n.category_datecreate.Value.ToString("dd/MM/yyyy"),
                    category_dateupdate = n.category_dateupdate.Value.ToString("dd/MM/yyyy"),
                    category_img        = n.category_img,
                    category_option     = n.category_option
                }).ToList();
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(null));
            }
        }
Example #7
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                bool          band;
                CategoriesDAO oDAO = new CategoriesDAO();
                if (btnAgregar.Text.Equals("Agregar"))
                {
                    categoria = new Categories();
                    PasarObjeto();
                    band = oDAO.Create(categoria);
                }
                else
                {
                    PasarObjeto();
                    band = oDAO.Update(categoria);
                }

                if (band)
                {
                    GetCategorias();
                    LimpiarControles();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    public List <Category> GetAllCategories()
    {
        List <Category> categories = new List <Category>();
        CategoriesDAO   dao        = new CategoriesDAO();

        categories = dao.GetAllCategories();
        return(categories);
    }
        public void GetTest()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);
            var result    = categoria.Get();


            Assert.AreEqual(2, categoria.Get().Count());
            Assert.AreEqual(10, categoria.Get().First().Id);
        }
        public void DeleteTest()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);
            var result    = categoria.Delete(11);

            Assert.IsTrue(result);
            Assert.AreEqual(1, categoria.Get().Count());
            Assert.AreNotEqual(11, categoria.Get().First().Id);
        }
        private void AddSample()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);

            categoria.Insert(new Category()
            {
                Id = 10
            });
            categoria.Insert(new Category()
            {
                Id = 11
            });
        }
Example #12
0
        private void ListCategories()
        {
            CategoriesDAO         categoriesDAO  = new CategoriesDAO();
            var                   categories     = categoriesDAO.Listagem();
            List <SelectListItem> categoriesList = new List <SelectListItem>();

            categoriesList.Add(new SelectListItem("Selecione uma marca", "0"));

            foreach (var category in categories)
            {
                SelectListItem item = new SelectListItem(category.Name, category.Id.ToString());
                categoriesList.Add(item);
            }
            ViewBag.Categories = categoriesList;
        }
        public void UpdateTest()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);
            var cat       = new Category()
            {
                Id          = 10,
                Description = "categoria com id 2"
            };
            var result = categoria.Update(cat);


            Assert.AreEqual(2, categoria.Get().Count());
            Assert.AreEqual("categoria com id 2", categoria.Get().First(x => x.Id == 10).Description);
        }
Example #14
0
 private void GetCategorias()
 {
     try {
         CategoriesDAO oDAO = new CategoriesDAO();
         categorias = oDAO.RetrieveAll();
         var tmpCategorias = (from c in categorias
                              select new {
             Categoria = c.CategoryName,
             Descripcion = c.Description,
         }).ToList();
         dgvDatos.DataSource = null;
         dgvDatos.DataSource = tmpCategorias;
     } catch (Exception e) {
         MessageBox.Show(e.Message, "MyStoreDesktop");
     }
 }
        public void InsertTest()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);
            var cat       = new Category()
            {
                Id          = 2,
                Description = "categoria com id 2"
            };
            var result = categoria.Insert(cat);


            Assert.AreEqual(3, categoria.Get().Count());
            Assert.IsTrue(categoria.Get().Any(x => x.Id == 2));
            Assert.AreEqual(cat, categoria.Get().First(x => x.Id == 2));
            Assert.AreEqual(cat, result);
        }
Example #16
0
        private void AgregarBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(categoriaTxt.Text))
            {
                MessageBox.Show("Inserte una categoria",
                                "ALERTA",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);

                return;
            }
            else
            {
                try {
                    bool          band;
                    CategoriesDAO oDAO = new CategoriesDAO();
                    if (AgregarBtn.Text.Equals("Agregar"))
                    {
                        EliminarBtn.Enabled = true;
                        categoria           = new Categories();
                        PasarObjeto();
                        band = oDAO.Create(categoria);
                    }
                    else
                    {
                        EliminarBtn.Enabled = true;
                        dgvDatos.Enabled    = true;
                        CancelarBtn.Enabled = false;
                        PasarObjeto();
                        band            = oDAO.Update(categoria);
                        AgregarBtn.Text = "Agregar";
                    }

                    if (band)
                    {
                        GetCategorias();
                        LimpiarControles();
                    }
                } catch (Exception ex) {
                    MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    public void DeleteCategory(int id)
    {
        CategoriesDAO dao            = new CategoriesDAO();
        Category      deleteCategory = dao.GetCategory(id);

        if (deleteCategory != null)
        {
            int result = dao.DeleteCategory(deleteCategory);
            if (result < 1)
            {
                throw new Exception("No es posible eliminar la Categoría, por favor verificar que no existan Tipos de Productos asociados a la Categoría");
            }
        }
        else
        {
            throw new Exception("El id de la Categoría a eliminar no es válido");
        }
    }
Example #18
0
        public List <ProductDTO> GetProductList()
        {
            CategoriesDAO        cateDAO  = new CategoriesDAO();
            List <CategoriesDTO> listCate = cateDAO.GetAll();
            List <ProductDTO>    list     = productDAO.GetAll();

            foreach (CategoriesDTO cateDto in listCate)
            {
                foreach (ProductDTO dto in list)
                {
                    if (dto.cateId == cateDto.cateId)
                    {
                        dto.cateName = cateDto.cateName;
                    }
                }
            }
            return(list);
        }
Example #19
0
        private void GetCategorias()
        {
            CategoriesDAO oDAO = new CategoriesDAO();

            categorias = oDAO.RetrieveAll();
            if (categorias != null)
            {
                if (categorias.Count != 0)
                {
                    categoriaCmBox.DisplayMember = "CategoryName";
                    categoriaCmBox.ValueMember   = "CategoryID";
                    categoriaCmBox.DataSource    = (from c in categorias
                                                    select new {
                        c.CategoryID,
                        c.CategoryName
                    }).ToList();
                }
            }
        }
        private void DisplayRevenueByCategory()
        {
            SeriesCollection series     = new SeriesCollection();
            List <Category>  categories = CategoriesDAO.GetCategories();

            categories = categories.Skip(1).ToList();

            List <CartItem> cartItems = new List <CartItem>();

            foreach (var order in orders)
            {
                cartItems.AddRange(order.CartItems);
            }


            foreach (var category in categories)
            {
                long value = 0;

                foreach (var cartItem in cartItems)
                {
                    if (cartItem.Cake.Category.Id == category.Id)
                    {
                        value += cartItem.TotalPrice;
                    }
                }

                PieSeries pieSeries = new PieSeries
                {
                    Title  = category.Name,
                    Values = new ChartValues <long> {
                        value
                    },
                    DataLabels = true,
                    LabelPoint = PointLabel
                };
                series.Add(pieSeries);
            }

            revenueByCategoryPie.Series = series;
        }
        private void DisplayDetail()
        {
            cake = CakesDAO.GetById(idCake);

            var folder            = AppDomain.CurrentDomain.BaseDirectory;
            var pathImageAbsolute = $"{folder}\\Assets\\Images\\Uploads\\{cake.Image_Main}";

            imageUploadImage.Source = new BitmapImage(new Uri(pathImageAbsolute, UriKind.Absolute));

            categories = CategoriesDAO.GetCategories();

            categoryComboBox.ItemsSource = categories;

            categoryComboBox.SelectedIndex = categories.FindIndex(item => item.Id == cake.Category.Id);

            imageUploadImage.Tag = cake.Image_Main;

            nameImage = cake.Image_Main;

            this.DataContext = cake;
        }
Example #22
0
        public ActionResult Edit(Category category, HttpPostedFileBase IMG)
        {
            Category cate = db.Categories.Find(category.category_id);

            category.category_active     = cate.category_active;
            category.category_datecreate = cate.category_datecreate;
            category.category_dateupdate = DateTime.Now;
            category.category_bin        = cate.category_bin;
            category.category_option     = cate.category_option;
            category.category_view       = cate.category_view;
            category.user_id             = cate.user_id;

            var i = new ImagesController();

            if (IMG != null)
            {
                var code = Guid.NewGuid().ToString();
                var img  = new ImagesController();
                img.AddImages(IMG, Common.Link.IMG_CATEGORY, code);
                category.category_img = code + IMG.FileName;
            }
            else
            {
                category.category_img = cate.category_img;
            }


            var dao = new CategoriesDAO();

            if (dao.Edit(category))
            {
                return(Redirect("/Admin/CategoriesAdmin"));
            }
            else
            {
                return(Redirect(Common.Link.NOT_404));
            }
        }
Example #23
0
        public ActionResult Add(Category category, HttpPostedFileBase IMG, string del)
        {
            //Cập nhật có thay đổi
            category.category_option = true;
            category.category_bin    = false;

            //Kiem tra thay đổi value

            if (category.category_active != true && category.category_active != false)
            {
                category.category_active = false;
            }

            //Hinh ảnh
            if (IMG != null)
            {
                var code = Guid.NewGuid().ToString();
                var img  = new ImagesController();
                img.AddImages(IMG, Common.Link.IMG_CATEGORY, code);
                category.category_img = code + IMG.FileName;
            }
            else
            {
                category.category_img = "notImg.png";
            }

            var dao = new CategoriesDAO();
            var j   = new JsonAdminController();

            if (dao.ADD(category))
            {
                return(Redirect("/Admin/CategoriesAdmin"));
            }
            else
            {
                return(Redirect(Common.Link.NOT_404));
            }
        }
    public void UpdateCategory(int id, string name, string description)
    {
        try
        {
            name        = name.TrimEnd().TrimStart();
            description = description.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Categoría");
        }

        CategoriesDAO   dao        = new CategoriesDAO();
        List <Category> categories = GetAllCategories();
        //Category updateCategory = dao.GetCategory(id);
        Category updateCategory = categories.Find(c => c.id.Equals(id));

        if (updateCategory != null)
        {
            if (categories.FindAll(c => (c.name.ToUpperInvariant().Equals(name.ToUpperInvariant())) && (c.id != id)).Count > 0)
            {
                throw new Exception("Ya existe una Categoría con este nombre");
            }

            updateCategory.name        = name;
            updateCategory.description = description;
            int result = dao.UpdateCategory(updateCategory);
            if (result < 1)
            {
                throw new Exception("No es posible actualizar la Categoría");
            }
        }
        else
        {
            throw new Exception("El id de la Categoría a actualizar no es válido");
        }
    }
Example #25
0
 public CategoryController()
 {
     DAO           = new CategoriesDAO();
     GeraProximoId = true;
 }
Example #26
0
 public CategoriesBLL()
 {
     categoriesDAO = new CategoriesDAO();
 }
Example #27
0
    private void LoadMainProducts(int order, int productypeId = 0)
    {
        CategoriesDAO   categoriesDAO     = new CategoriesDAO();
        List <Category> allCategoriesList = categoriesDAO.GetAllCategories();

        Category manCategory = allCategoriesList.Find(c => c.name.ToUpper().Equals("MUJER"));

        ProductTypesDAO    productTypesDAO  = new ProductTypesDAO();
        List <ProductType> productTypesList = productTypesDAO.GetAllProductTypes();

        productTypesList = productTypesList.FindAll(pt => pt.categoryId.Equals(manCategory.id)).ToList();

        ulProductTypesMan.Controls.Clear();

        HtmlGenericControl liAll      = new HtmlGenericControl("li");
        HtmlGenericControl ianchorAll = new HtmlGenericControl("a");

        liAll      = new HtmlGenericControl("li");
        ianchorAll = new HtmlGenericControl("a");
        ianchorAll.Attributes.Add("href", "?productTypeId=-1#main");
        ianchorAll.Attributes.Add("class", "active");
        ianchorAll.InnerText = "Todas";
        liAll.Controls.Add(ianchorAll);
        ulProductTypesMan.Controls.Add(liAll);

        foreach (ProductType productType in productTypesList)
        {
            HtmlGenericControl li      = new HtmlGenericControl("li");
            HtmlGenericControl ianchor = new HtmlGenericControl("a");
            li      = new HtmlGenericControl("li");
            ianchor = new HtmlGenericControl("a");
            ianchor.Attributes.Add("href", "?productTypeId=" + productType.id + "#main");
            ianchor.Attributes.Add("class", "active");
            ianchor.InnerText = productType.name;
            li.Controls.Add(ianchor);
            ulProductTypesMan.Controls.Add(li);
        }

        ProductsDAO      productsDAO      = new ProductsDAO();
        ProductImagesDAO productImagesDAO = new ProductImagesDAO();

        List <Product>      allProductsList  = productsDAO.GetAllProducts();
        List <ProductImage> productImageList = productImagesDAO.GetAllProductImages();

        List <Product> productsList = allProductsList.Where(p => productTypesList.Any(pl => pl.id.Equals(p.productTypeId))).ToList();

        if (productypeId > 0)
        {
            productsList = allProductsList.FindAll(p => p.productTypeId.Equals(productypeId));
        }

        //default order
        productsList = productsList.OrderBy(p => p.name).ToList();

        switch (order)
        {
        //NOMBRE (A -Z)
        case 0:
            productsList = productsList.OrderBy(p => p.name).ToList();
            break;

        //NOMBRE (Z -A)
        case 1:
            productsList = productsList.OrderByDescending(p => p.name).ToList();
            break;

        //MENOR PRECIO
        case 2:
            productsList = productsList.OrderBy(p => Double.Parse(p.price)).ToList();
            break;

        //MAYOR PRECIO
        case 3:
            productsList = productsList.OrderByDescending(p => Double.Parse(p.price)).ToList();
            break;

        default:
            productsList = productsList.OrderBy(p => p.name).ToList();
            break;
        }

        pnlProducts.Controls.Clear();

        if (productsList.Count > 0)
        {
            foreach (Product product in productsList)
            {
                //P1
                ProductImage productImage = productImagesDAO.GetAllProductImages()
                                            .FindAll(pi => pi.productId.Equals(product.id)).FirstOrDefault();
                string url                = "http://*****:*****@"<div class=""col-xs-12 col-sm-4"">
                        <div class=""product-display product-description"">
                            <figure class=""product-image"">
                                <img id=""imgProduct1"" src=""" + ImageSrc + @""" alt=""image"" />
			                    <div class=""overlay"">
                                    <div class=""product-view-block"">
                                        <div class=""product-view clearfix"">
						                    <a id=""hlProductZoom1"" href="""                         + ImageSrc + @""" class=""zoom icon_zoom-in_alt single_image""></a>
					                    </div>
                                        <a id=""hlBuyProduct1"" href=""/Products.aspx?productId=" + product.id + @"#main"" class=""btn add-cart"">COMPRAR</a>
                                    </div>
                                </div>
		                    </figure>
		                    <div class=""about-product"">
			                    <h4><a id=""hlProduct1"" href=""/Products.aspx?productId="             + product.id + @"#main"" class=""item-name"">" + product.name + @"</a></h4>
			                    <span class=""price"">
				                    <span id=""lblPrice1"">$ "                 + product.price + @"</span></span>
                                    </div>
	                            </div>
                            </div>";

                HtmlGenericControl div = new HtmlGenericControl("div");
                div.InnerHtml = productDescription;
                pnlProducts.Controls.Add(div);
            }
            ////P8
            //LoadProductInfo(hlProduct8, imgProduct8, productsList[7], productImage, lblPrice8, hlProductZoom8, hlBuyProduct8);

            //productImage = productImagesDAO.GetAllProductImages()
            //    .FindAll(pi => pi.productId.Equals(productsList[8].id))
            //    .FirstOrDefault();

            ////P9
            //LoadProductInfo(hlProduct9, imgProduct9, productsList[8], productImage, lblPrice9, hlProductZoom9, hlBuyProduct9);
        }
    }