Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BtnInsertProduct.Visible     = false;
            GridView1.Columns[7].Visible = false;
            GridView1.Columns[6].Visible = false;
            GridView1.Columns[5].Visible = false;
            GridView1.DataSource         = ViewProductController.FetchDataProduct();
            GridView1.DataBind();

            if (Session["LoginSession"] != null)
            {
                String ID   = Session["LoginSession"].ToString();
                MsUser user = HomeController.FetchDataForHome(ID);
                if (user.RoleID == "RL1")
                {
                    GridView1.Columns[6].Visible = true;
                    GridView1.Columns[5].Visible = true;
                    BtnInsertProduct.Visible     = true;
                    GridView1.DataSource         = ViewProductController.FetchDataProductForAdmin();
                    GridView1.DataBind();
                }
                else if (user.RoleID == "RL2")
                {
                    GridView1.Columns[7].Visible = true;
                }
            }
        }
Exemplo n.º 2
0
        private void load_data()
        {
            List <vProduct> productList = ViewProductController.getProductList();

            productGrid.DataSource = productList;
            productGrid.DataBind();
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User us = (User)Session["user"];

            if (Session["user"] != null)
            {
                if (us.RoleID == 1)
                {
                    if (!IsPostBack)
                    {
                        DropDownListType.DataSource = InsertProductController.getAllProductType().Select(p => p.Name).ToList();
                        DropDownListType.DataBind();
                    }

                    GridViewInsertProduct.DataSource = ViewProductController.getAllProduct();
                    GridViewInsertProduct.DataBind();
                }
                else
                {
                    Response.Redirect("Home.aspx");
                }
            }
            else
            {
                Response.Redirect("Home.aspx");
            }
        }
Exemplo n.º 4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         GridViewProduct.Columns[0].Visible = false;
         GridViewProduct.Columns[1].Visible = false;
         GridViewProduct.Columns[2].Visible = false;
         GridViewProduct.Columns[3].Visible = false;
         User us = (User)Session["user"];
         if (Session["user"] != null)
         {
             if (us.RoleID == 1)
             {
                 GridViewProduct.Columns[1].Visible = true;
                 GridViewProduct.Columns[2].Visible = true;
                 GridViewProduct.Columns[3].Visible = true;
             }
             else if (us.RoleID == 2)
             {
                 GridViewProduct.Columns[0].Visible = true;
             }
         }
         GridViewProduct.DataSource = ViewProductController.getAllProduct();
         GridViewProduct.DataBind();
     }
 }
        protected void BtnDeleteProduct_Click(object product, EventArgs e)
        {
            int    productId    = Int32.Parse((product as LinkButton).CommandArgument);
            string errorMessage = "";

            if (ViewProductController.DeleteValidation(productId, out errorMessage) == true)
            {
                Response.Redirect("ViewProduct.aspx");
            }
            else
            {
                LblError.Text = errorMessage;
            }
        }
Exemplo n.º 6
0
        protected void DeleteProduct_Click(object send, EventArgs e)
        {
            int    ProductID = Int32.Parse((send as LinkButton).CommandArgument);
            string errorMsg  = "";
            bool   success   = ViewProductController.validateDelete(ProductID, out errorMsg);

            if (success)
            {
                ViewProductController.deleteProduct(ProductID);
                Response.Redirect("ViewProduct.aspx");
            }
            else
            {
                lblDelete.Visible = true;
                lblDelete.Text    = errorMsg;
            }
        }
        private void ShowAllItem()
        {
            List <Product> product = ViewProductController.GetAllProductController();

            var filtered = product.Select(i => new {
                Id          = i.ID,
                Name        = i.Name,
                ProductType = i.ProductType.Name,
                Stock       = i.Stock,
                Price       = i.Price
            });

            if (filtered.Count() > 0)
            {
                GridAllItem.DataSource = filtered;
                GridAllItem.DataBind();
            }
        }
Exemplo n.º 8
0
        private void random()
        {
            int count = ViewProductController.countProduct();

            if (count < 6)
            {
                var less = ViewProductController.getAllProduct();
                GridViewCart.DataSource = less.ToList();
                GridViewCart.DataBind();
            }
            else
            {
                var pr = ViewProductController.generateRandom();

                GridViewCart.DataSource = pr.ToList();
                GridViewCart.DataBind();
            }
        }
Exemplo n.º 9
0
        protected void deleteBtn_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(idLbl.Text);

            if (ViewProductController.checkProductInCart(id))
            {
                warningLbl.Text = "Cannot delete current product. Still referenced by cart";
            }
            else
            {
                if (ViewProductController.requestDeleteProduct(id))
                {
                    Response.Redirect("./ViewProduct.aspx");
                }
                else
                {
                    warningLbl.Text = "Cannot delete current product. Still referenced by Transaction";
                }
            }
        }
Exemplo n.º 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["LoginSession"] == null)
     {
         Response.Redirect("../HomeView/Home.aspx");
     }
     else
     {
         String ID   = Session["LoginSession"].ToString();
         MsUser user = HomeController.FetchDataForHome(ID);
         if (user.RoleID != "RL1")
         {
             Response.Redirect("../HomeView/Home.aspx");
         }
         else
         {
             GridView1.DataSource = ViewProductController.FetchDataProductForAdmin();
             GridView1.DataBind();
         }
     }
 }
Exemplo n.º 11
0
        protected void selectLinkBtn_Click(object sender, EventArgs e)
        {
            if (Request.Cookies["user_email"] == null)
            {
            }                                              //Do nothing
            else if (ViewProductController.isUserAnAdmin(Request.Cookies["user_email"].Value))
            {
                updateBtn.Visible    = true;
                deleteBtn.Visible    = true;
                addToCartBtn.Visible = false;
            }
            else
            {
                addToCartBtn.Visible = true;
            }
            int     productId       = Convert.ToInt32((sender as LinkButton).CommandArgument);
            Product selectedProduct = ViewProductController.getProductObject(productId);

            idLbl.Text    = selectedProduct.ProductID.ToString();
            nameLbl.Text  = selectedProduct.ProductName;
            priceLbl.Text = selectedProduct.ProductPrice.ToString();
        }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TokobediaEntities dbEntity = new TokobediaEntities();
            User us = (User)Session["user"];

            if (Session["user"] != null)
            {
                if (us.RoleID == 1)
                {
                    GridViewUpdateP.DataSource = ViewProductController.getAllProduct();
                    GridViewUpdateP.DataBind();
                }
                else
                {
                    Response.Redirect("Home.aspx");
                }
            }
            else
            {
                Response.Redirect("Home.aspx");
            }
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!ViewProductController.isUserLoggedIn())
            {
                logOutBtn.Visible = false;
                insertBtn.Visible = false;
                deleteBtn.Visible = false;
                updateBtn.Visible = false;

                loginBtn.Visible = true;
            }
            else
            {
                if (!ViewProductController.isUserAnAdmin(Request.Cookies["user_email"].Value))
                {
                    insertBtn.Visible    = false;
                    deleteBtn.Visible    = false;
                    updateBtn.Visible    = false;
                    addToCartBtn.Visible = false;
                }
            }
            load_data();
        }
Exemplo n.º 14
0
        protected void btnInsertP_Click(object sender, EventArgs e)
        {
            LabelInvalid.Visible = true;
            string errorMsg = "";

            try
            {
                string name    = productName.Text.ToString();
                int    stock   = Int32.Parse(productStock.Text.ToString());
                int    price   = Int32.Parse(productPrice.Text.ToString());
                string type    = DropDownListType.Text.ToString();
                bool   success = InsertProductController.Insert(name, stock, price, type, out errorMsg);
                if (!success)
                {
                    LabelInvalid.Text = errorMsg;
                }
                else
                {
                    var pt = InsertProductController.SearchByName(type);
                    if (success)
                    {
                        LabelInvalid.Text = errorMsg;
                        InsertProductController.doInsert(pt.ProductTypeID, name, price, stock);
                        GridViewInsertProduct.DataSource = ViewProductController.getAllProduct();
                        GridViewInsertProduct.DataBind();
                        Response.Redirect("InsertProduct.aspx");
                    }
                    else
                    {
                        LabelInvalid.Text = errorMsg;
                    }
                }
            }catch
            {
                LabelInvalid.Text = "Cannot be empty!";
            }
        }