protected void Btn_search_Click(object sender, EventArgs e)
        {
            var productBLL = new ProductBLL();

            GridProducts.DataSource = productBLL.Search(Txb_search_name.Text, Txb_search_sku.Text, Txb_search_brand.Text);
            GridProducts.DataBind();
        }
        private void SeeGrid()
        {
            var productBll = new ProductBll();

            GridProducts.DataSource = productBll.GetProducts();
            GridProducts.DataBind();
        }
        private void LoadProducts()
        {
            var productBLL  = new ProductBLL();
            var productList = productBLL.LoadProducts(0);

            GridProducts.DataSource = productList;
            GridProducts.DataBind();
        }
        protected void search_OnClick(object sender, EventArgs e)
        {
            var productBll = new ProductBll();

            try
            {
                GridProducts.DataSource = productBll.SearchProducts(searchTerm.Text);
                GridProducts.DataBind();
            }
            catch (Exception exception)
            {
                error.InnerText = exception.Message;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _dbcontext = new NorthwindEntities();

            var allProducts = _dbcontext.Products.Select(x => new
            {
                x.ProductID,
                x.ProductName,
                x.Category.CategoryName,
                x.QuantityPerUnit,
                x.UnitPrice,
                x.UnitsInStock
            }).ToList();

            GridProducts.DataSource = allProducts;
            GridProducts.DataBind();
        }
        protected void DropOptionList_OnChange(object sender, EventArgs e)
        {
            var user       = (User)Session["UserEntity"];
            var productBLL = new ProductBLL();

            if (user.ProfileType == EProfile.Administrator || user.ProfileType == EProfile.Operator)
            {
                switch (DropOptionList.SelectedItem.Value)
                {
                case "NewProduct.aspx":
                    if (user.ProfileType == EProfile.Administrator && DropOptionList.SelectedItem.Selected)
                    {
                        Response.Redirect("NewProduct.aspx");
                    }
                    else
                    {
                        Session["ErrorId"]      = 1;
                        Session["ErrorMessage"] = "You do not have permission to execute this action.";
                        Response.Redirect("ErrorPage.aspx");
                    }
                    break;

                case "ordId1":
                    GridProducts.DataSource = productBLL.LoadProducts(1);
                    GridProducts.DataBind();
                    break;

                case "ordId2":
                    GridProducts.DataSource = productBLL.LoadProducts(2);
                    GridProducts.DataBind();
                    break;
                }
            }
            else
            {
                Session["ErrorId"]      = 1;
                Session["ErrorMessage"] = "You do not have permission to execute this action.";
                Response.Redirect("ErrorPage.aspx");
            }
        }
示例#7
0
        protected void DrpCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedID = int.Parse(DrpCategory.SelectedValue);

            if (selectedID == -1)
            {
                GridProducts.DataSource = null;
            }
            else
            {
                //filter the products belonging to the selected category
                var products = from product in entities.Products
                               where product.CategoryID == selectedID
                               select new
                {
                    Name          = product.ProductName,
                    Quantity_unit = product.QuantityPerUnit,
                    Stock         = product.UnitsInStock
                };
                GridProducts.DataSource = products.ToArray();
            }
            GridProducts.DataBind();
        }
        protected void orderByName_OnClick(object sender, EventArgs e)
        {
            var productBll = new ProductBll();

            var orderName = (string)Session["orderName"];
            var products  = productBll.SearchProducts(searchTerm.Text);

            if (orderName == "desc")
            {
                orderName = "asc";
                products  = products.OrderBy(p => p.Name).ToList();
            }
            else
            {
                orderName = "desc";
                products  = products.OrderByDescending(p => p.Name).ToList();
            }

            Session["orderPrice"] = null;
            Session["orderName"]  = orderName;

            GridProducts.DataSource = products;
            GridProducts.DataBind();
        }