Ejemplo n.º 1
0
        public bool DeleteSale(Sales sale)
        {
            try
            {
                SalesDAO     dao      = new SalesDAO();
                SaleItemsDAO itemsDAO = new SaleItemsDAO();
                UserDAO      userDAO  = new UserDAO();
                User         u;

                if (sale != null)
                {
                    u = userDAO.CheckLogin(sale.User);
                    if (u == null)
                    {
                        return(false);
                    }
                    if (u.Permission != User.admin)
                    {
                        if (!dao.CheckUserPermission(sale))
                        {
                            return(false);
                        }
                    }
                    itemsDAO.DeleteSaleItem(sale);
                    dao.DeleteSale(sale);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        public Sales SelectCompleteSale(Sales sale)
        {
            try
            {
                SalesDAO     dao      = new SalesDAO();
                SaleItemsDAO itemsDAO = new SaleItemsDAO();
                UserDAO      userDAO  = new UserDAO();
                User         u;

                if (sale != null)
                {
                    u = userDAO.CheckLogin(sale.User);
                    if (u == null)
                    {
                        return(null);
                    }
                    if (u.Permission != User.admin)
                    {
                        if (!dao.CheckUserPermission(sale))
                        {
                            return(null);
                        }
                    }
                    sale               = dao.SelectSale(sale);
                    sale.User          = u;
                    sale.ListSaleItems = ListSaleItems(sale);
                    return(sale);
                }
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        // SaleItem

        public bool SaveSaleItem(SaleItems item)
        {
            try
            {
                SalesDAO     salesDAO    = new SalesDAO();
                SaleItemsDAO itemsDAO    = new SaleItemsDAO();
                ProductsDAO  productsDAO = new ProductsDAO();
                UserDAO      userDAO     = new UserDAO();
                Products     p;

                if (item != null)
                {
                    if (userDAO.CheckLogin(item.Sale.User) == null)
                    {
                        return(false);
                    }
                    if (!salesDAO.CheckUserPermission(item.Sale))
                    {
                        return(false);
                    }
                    p = productsDAO.SelectProduct(item.Product);
                    if (p == null)
                    {
                        return(false);
                    }
                    if (item.Qtd < 1)
                    {
                        item.Qtd = 1;
                    }
                    if (itemsDAO.ChangeQtdSaleItem(item, item.Qtd) == 0)
                    {
                        item.UnitPrice = p.Price;
                        itemsDAO.InsertSaleItem(item);
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 5
0
        public List <SaleItems> ListSaleItems(Sales sale)
        {
            SalesDAO     salesDAO = new SalesDAO();
            SaleItemsDAO itemsDAO = new SaleItemsDAO();
            UserDAO      userDAO  = new UserDAO();

            if (sale != null)
            {
                if (userDAO.CheckLogin(sale.User) == null)
                {
                    return(null);
                }
                if (!salesDAO.CheckUserPermission(sale))
                {
                    return(null);
                }
                return(itemsDAO.ListSaleItems(sale));
            }
            return(null);
        }
Ejemplo n.º 6
0
        public bool IncreaseQtdSaleItem(SaleItems item)
        {
            try
            {
                SalesDAO     salesDAO    = new SalesDAO();
                SaleItemsDAO itemsDAO    = new SaleItemsDAO();
                ProductsDAO  productsDAO = new ProductsDAO();
                UserDAO      userDAO     = new UserDAO();
                Products     p;

                if (item != null)
                {
                    if (userDAO.CheckLogin(item.Sale.User) == null)
                    {
                        return(false);
                    }
                    if (!salesDAO.CheckUserPermission(item.Sale))
                    {
                        return(false);
                    }
                    p = productsDAO.SelectProduct(item.Product);
                    if (p == null)
                    {
                        return(false);
                    }
                    if (itemsDAO.IncreaseQtdSaleItem(item) > 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 7
0
        public bool ChangeOpenedSale(Sales sale, bool open)
        {
            try
            {
                SalesDAO dao     = new SalesDAO();
                UserDAO  userDAO = new UserDAO();
                User     u;

                if (sale != null)
                {
                    u = userDAO.CheckLogin(sale.User);
                    if (u == null)
                    {
                        return(false);
                    }
                    if (u.Permission != User.admin)
                    {
                        if (!dao.CheckUserPermission(sale))
                        {
                            return(false);
                        }
                    }
                    if (!open)
                    {
                        sale.ClosedDateTime = DateTime.Now;
                    }
                    dao.ChangeOpenedSale(sale, open);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }