예제 #1
0
        protected void CartSalesGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Refresh"))
            {
                PanelPaymentButtons.Visible = true;
                int productid = int.Parse(e.CommandArgument.ToString());
                int qty       = 0;
                for (int rowindex = 0; rowindex < CartSalesGridView.Rows.Count; rowindex++)
                {
                    if ((CartSalesGridView.Rows[rowindex].FindControl("ProductID") as Label).Text == e.CommandArgument.ToString())
                    {
                        qty = int.Parse((CartSalesGridView.Rows[rowindex].FindControl("Quantity") as TextBox).Text);
                    }
                }
                if (qty <= 0)
                {
                    MessageUserControl.ShowInfo("Quantity Cannot be negative number or zero, Please add quantity or remove the item from your Cart.");
                }
                else
                {
                    var username = User.Identity.Name;
                    SecurityController securitymgr = new SecurityController();
                    int?employeeid             = securitymgr.GetCurrentUserEmployeeId(username);
                    EmployeeController sysmgrs = new EmployeeController();
                    Employee           info    = sysmgrs.Employee_Get(employeeid.Value);

                    int employeeID = info.EmployeeID;

                    MessageUserControl.TryRun(() =>
                    {
                        ShoppingCartController sysmgr = new ShoppingCartController();

                        //Call for adjusting quantity
                        sysmgr.Quantity_Refresh(employeeID, productid, qty);

                        List <ShoppingCart> datainfo = sysmgr.ShoppingCart_OrderList();
                        CartSalesGridView.DataSource = datainfo;
                        CartSalesGridView.DataBind();
                    }, "Refreshing", "Item Quantity Updated");
                    var controller = new ShoppingCartController();
                    var countTotal = controller.ShoppingCart_OrderList();
                    SubtotalText.Text = countTotal.Sum(x => x.Quantity * x.Price).ToString();
                    TaxText.Text      = countTotal.Sum(t => t.Quantity * t.Price * decimal.Parse(0.05.ToString())).ToString();
                    TotalText.Text    = countTotal.Sum(tos => tos.Quantity * tos.Price * decimal.Parse(0.05.ToString()) + (tos.Quantity * tos.Price)).ToString();
                }
            }
            else
            {
                PanelPaymentButtons.Visible = true;
                int productid = int.Parse(e.CommandArgument.ToString());


                var username = User.Identity.Name;
                SecurityController securitymgr = new SecurityController();
                int?employeeid             = securitymgr.GetCurrentUserEmployeeId(username);
                EmployeeController sysmgrs = new EmployeeController();
                Employee           info    = sysmgrs.Employee_Get(employeeid.Value);

                int employeeID = info.EmployeeID;

                MessageUserControl.TryRun(() =>
                {
                    ShoppingCartController sysmgr = new ShoppingCartController();

                    sysmgr.Delete_ProductItem(employeeID, productid);

                    List <ShoppingCart> datainfo = sysmgr.ShoppingCart_OrderList();
                    CartSalesGridView.DataSource = datainfo;
                    CartSalesGridView.DataBind();
                }, "Deleting Product", "Item Has been Removed from the Cart");
                var controller = new ShoppingCartController();
                var countTotal = controller.ShoppingCart_OrderList();
                SubtotalText.Text = countTotal.Sum(x => x.Quantity * x.Price).ToString("C");
                TaxText.Text      = countTotal.Sum(t => t.Quantity * t.Price * decimal.Parse(0.05.ToString())).ToString("C");
                TotalText.Text    = countTotal.Sum(tos => tos.Quantity * tos.Price * decimal.Parse(0.05.ToString()) + (tos.Quantity * tos.Price)).ToString("C");
            }
        }