public bool SaveProduct(Products product)
        {
            try
            {
                ProductsDAO dao   = new ProductsDAO();
                bool        error = false;

                if (product != null)
                {
                    if (product.Name.Equals(""))
                    {
                        error = true;
                    }
                    if (!error)
                    {
                        if (dao.CountProductName(product) == 0)
                        {
                            dao.InsertProduct(product);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao inserir o produto no banco de dados! " + e.Message);
            }
        }
        public bool DeleteProduct(Products product)
        {
            ProductsDAO dao   = new ProductsDAO();
            bool        error = false;

            if (product != null)
            {
                if (dao.CountProductOrder(product) > 0)
                {
                    error = true;
                }
                if (dao.CountProductSales(product) > 0)
                {
                    error = true;
                }

                if (!error)
                {
                    dao.DeleteProduct(product);
                }
                else
                {
                    dao.ChangeProductActivated(product, false);
                }
                return(true);
            }
            return(false);
        }
        public bool UpdateProduct(Products product)
        {
            ProductsDAO dao = new ProductsDAO();
            Products    p;
            bool        error = false;

            if (product != null)
            {
                p = dao.SelectProduct(product);
                if (p != null)
                {
                    if (!product.Name.Equals(""))
                    {
                        if (!product.Name.Equals(p.Name))
                        {
                            if (dao.CountProductName(product) != 0)
                            {
                                error = true;
                            }
                        }
                    }

                    if (!error)
                    {
                        dao.UpdateProduct(product);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public void dataEvent(object sender, FormClosedEventArgs e)
        {
            List <ProductsPOJO> productsList = ProductsDAO.Select();

            dtgProducts.DataSource = null;
            dtgProducts.DataSource = productsList;
        }
        public IActionResult Search(string searchTerm)
        {
            ProductsDAO         products    = new ProductsDAO();
            List <ProductModel> productList = products.SearchProducts(searchTerm);

            return(View("index", productList));
        }
        public ActionResult <int> ProcessInsert(ProductModel product)
        {
            ProductsDAO products = new ProductsDAO();
            int         newId    = products.Insert(product);

            return(newId);
        }
Exemplo n.º 7
0
        public JsonResult InsertRegister(Customer item, Account ac)
        {
            ProductsDAO dao = new ProductsDAO();

            if (item == null || ac == null)
            {
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
            var old   = dao.Model.Customers.FirstOrDefault(f => f.ID == item.ID);
            var oldAc = dao.Model.Accounts.FirstOrDefault(f => f.id == ac.id);

            if (old != null && oldAc != null)
            {
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var oldAcName = dao.Model.Accounts.FirstOrDefault(f => f.UserName == ac.UserName);
                if (oldAcName != null)
                {
                    return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    dao.Model.Customers.Add(item);
                    dao.Model.SaveChanges();
                    ac.RoleID     = 1;
                    ac.CustomerID = dao.Model.Customers.OrderByDescending(y => y.ID).Select(y => y.ID).FirstOrDefault();
                    ac.Pwd        = MD5Hash(ac.Pwd);
                    dao.Model.Accounts.Add(ac);
                    dao.Model.SaveChanges();
                    return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Displays product information by supplier id to the user.
        /// </summary>
        /// <param name="productInfo"></param>
        static void DisplayProducts(List <ProductsDO> items)
        {
            string currentMethod = "DisplayProducts";

            try
            {
                //Prints all rows.
                if (items.Count > 0)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        Console.WriteLine(new string('-', 80));
                        Console.WriteLine($"ProductID: { items[i].ProductId}---| Product Name: {items[i].ProductName}\n | Quanity Per Unit: " +
                                          $"{  items[i].QuantityPerUnit} | Price per unit: ${items[i].UnitPrice.ToString("#.##")} | Units in stock: { items[i].UnitsInStock}\n | Units on order: " +
                                          $"{items[i].UnitsOnOrder} | Reorder Level: {items[i].ReorderLevel}");
                    }
                }
                Console.WriteLine("\n\t\t\tPress any key to continue.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                string      currentClass = "Program";
                ProductsDAO productsDAO  = new ProductsDAO();

                //Prints error to console, logs, and restarts the menu.
                productsDAO.ProductsErrorHandler(ex, currentClass, currentMethod, ex.StackTrace);
                throw ex;
            }
        }
Exemplo n.º 9
0
        public void data()
        {
            List <ProductsPOJO> productsList = ProductsDAO.Select();

            dtgProducts.DataSource = null;
            dtgProducts.DataSource = productsList;
        }
        public ActionResult <IEnumerable <ProductModel> > SearchResults(string searchTerm)
        {
            ProductsDAO         products    = new ProductsDAO();
            List <ProductModel> productList = products.SearchProducts(searchTerm);

            return(productList);
        }
        public ActionResult <ProductModelDTO> ShowOneProduct(int id)
        {
            ProductsDAO     products = new ProductsDAO();
            ProductModelDTO pdto     = new ProductModelDTO(products.GetProductById(id));

            return(pdto);
        }
        public ActionResult <ProductModel> ProcessEdit(ProductModel product)
        {
            ProductsDAO products = new ProductsDAO();

            products.Update(product);
            return(products.GetProductById(product.Id));
        }
Exemplo n.º 13
0
        public string ImageDetail(int id)
        {
            //List<String> lst = new List<string>();
            ProductsDAO dao = new ProductsDAO();
            //var lstImg = dao.GetAllImgProduct();
            //foreach (var item in lstImg)
            //{
            //    if (item.ProductID == id)
            //        lst.Add(item.ImgLink);
            //    else
            //  s
            var    lstImg  = dao.ListImg(id);
            string tempStr = "";

            for (int i = 0; i < lstImg.Count; i++)
            {
                var s = "\"item_" + i + "\":{\"orig\":\"../../Images/ThePicture" + lstImg[i].ImgLink + "\",\"main\":\"../../Images/ThePicture//" + lstImg[i].ImgLink + "\",\"thumb\":\"../../Images/ThePicture/" + lstImg[i].ImgLink + "\",\"label\":\"\"}";
                tempStr += s.ToString();
                if (i != (lstImg.Count - 1))
                {
                    tempStr += ",";
                }
            }
            return(tempStr.Replace("\"", ""));;
        }
Exemplo n.º 14
0
        public ActionResult GetCategoryList()
        {
            ProductsDAO dao   = new ProductsDAO();
            var         lstCt = dao.GetAllCategory();

            return(PartialView(lstCt));
        }
        public static List <InventoryItem> getNext10Products(int from)
        {
            ProductsDAO          datalayer = new ProductsDAO();
            List <InventoryItem> items     = datalayer.getNextTenItems(from);

            return(items);
        }
        public static InventoryItem getSingleItem(int viewItem)
        {
            ProductsDAO   datalayer = new ProductsDAO();
            InventoryItem item      = datalayer.getSingleItem(viewItem);

            return(item);
        }
Exemplo n.º 17
0
        public bool DeleteSaleItem(SaleItems item)
        {
            try
            {
                SalesDAO     salesDAO    = new SalesDAO();
                SaleItemsDAO itemsDAO    = new SaleItemsDAO();
                ProductsDAO  productsDAO = new ProductsDAO();
                UserDAO      userDAO     = new UserDAO();

                if (item != null)
                {
                    if (userDAO.CheckLogin(item.Sale.User) == null)
                    {
                        return(false);
                    }
                    if (!salesDAO.CheckUserPermission(item.Sale))
                    {
                        return(false);
                    }
                    itemsDAO.DeleteSaleItem(item);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!DataIsValid())
            {
                return;
            }

            Prod = new ProductsPOJO(
                EditMode ? Prod.ProductID : -1,
                txtProductName.Text,
                (int)cmbSupplier.SelectedValue,
                (int)cmbCategory.SelectedValue,
                txtQuantityPerUnit.Text,
                (double)nmUnitPrice.Value,
                (int)nmUnitsInStock.Value,
                (int)nmUnitsOnOrder.Value,
                (int)nmReorderLevel.Value,
                chkDescontinued.Checked ? 1 : 0
                );


            bool success = EditMode ? ProductsDAO.Update(Prod) : ProductsDAO.Insert(Prod);

            if (!success)
            {
                MessageBox.Show(null, "Ocurrió un error.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show(null, "Cambios guardados correctamente.", "Info",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Exemplo n.º 19
0
    public void UpdateProduct(int id, string name, int brandId, string shortDescription, string longDescription, string price, int colorId)
    {
        try
        {
            name             = name.TrimEnd().TrimStart();
            shortDescription = shortDescription.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible actualizar el Producto");
        }

        ProductsDAO dao            = new ProductsDAO();
        Product     updatedProduct = dao.GetProduct(id);

        if (updatedProduct != null)
        {
            updatedProduct.name             = name;
            updatedProduct.brandId          = brandId;
            updatedProduct.shortDescription = shortDescription;
            updatedProduct.longDescription  = longDescription;
            updatedProduct.price            = price;
            updatedProduct.colorId          = colorId;
            int result = dao.UpdateProduct(updatedProduct);
            if (result < 1)
            {
                throw new Exception("No es posible actualizar el Producto");
            }
        }
    }
Exemplo n.º 20
0
        private void EliminarBtn_Click(object sender, EventArgs e)
        {
            bool result = false;

            try {
                DialogResult res = MessageBox.Show("¿Desea eliminar el proveedor?",
                                                   "My Store Desktop", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    int fila = dgvDatos.CurrentRow.Index;
                    producto = productos.ElementAt(fila);
                    ProductsDAO pDAO = new ProductsDAO();
                    result = pDAO.Delete(producto.ProductID);
                    if (result)
                    {
                        GetProductos();
                    }
                    else
                    {
                        MessageBox.Show("Error al eliminar el producto",
                                        "My Store Desktop", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("Error al eliminar el producto: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 21
0
        public JsonResult Insert(Product item)
        {
            ProductsDAO dao = new ProductsDAO();

            if (item == null)
            {
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
            var old = dao.Model.Products.FirstOrDefault(f => f.ID == item.ID);

            if (old != null)
            {
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var oldName = dao.Model.Products.FirstOrDefault(f => f.ProductName == item.ProductName);
                if (oldName != null)
                {
                    return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
                }
                dao.Model.Products.Add(item);
                dao.Model.SaveChanges();
                return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
            }
        }
        public static bool insertNewItem(InventoryItem updateItem)
        {
            ProductsDAO datalayer = new ProductsDAO();
            bool        success   = datalayer.insertNewItem(updateItem);

            return(success);
        }
        public static List <InventoryItem> getAllItems()
        {
            ProductsDAO          datalayer         = new ProductsDAO();
            List <InventoryItem> completeInventory = datalayer.getAllInventory();

            return(completeInventory);
        }
        public static bool updateInventoryItem(InventoryItem item)
        {
            ProductsDAO datalayer = new ProductsDAO();
            bool        success   = datalayer.updateInventoryItem(item);

            return(success);
        }
        public IActionResult Index()
        {
            //HardCodedSampleDataRepo hardCodedSampleDataRepo = new HardCodedSampleDataRepo();

            ProductsDAO products = new ProductsDAO();

            return(View(products.GetAllProducts()));
        }
Exemplo n.º 26
0
    public Product GetProduct(int id)
    {
        Product     product = new Product();
        ProductsDAO dao     = new ProductsDAO();

        product = dao.GetProduct(id);
        return(product);
    }
Exemplo n.º 27
0
    public List <Product> GetAllProducts()
    {
        List <Product> products = new List <Product>();
        ProductsDAO    dao      = new ProductsDAO();

        products = dao.GetAllProducts();
        return(products);
    }
Exemplo n.º 28
0
        //
        // GET: /Products/
        public ActionResult Category(int id)
        {
            ProductsDAO dao            = new ProductsDAO();
            var         lstProductCate = dao.ListProductCate(id);

            this.ViewBag.lstProductCate = lstProductCate;
            return(View());
        }
 public static List <Product> Register(this Product p)
 {
     using (var contextProd = new ProductsDAO())
     {
         contextProd.Add(p);
         return(contextProd.Products());
     }
 }
        public ActionResult <int> DeleteOne(int Id)
        {
            ProductsDAO  products = new ProductsDAO();
            ProductModel product  = products.GetProductById(Id);
            int          success  = products.Delete(product);

            return(success);
        }