Exemple #1
0
        protected void AddButtonn_Click(object sender, EventArgs e)
        {
            CartSalesGridView.Enabled   = true;
            PanelPaymentButtons.Visible = true;
            Product products = new Product();

            products.QuantityOnOrder = int.Parse(QuantityTextBox.Text);

            if (string.IsNullOrEmpty(CategoryDDL.SelectedValue) || string.IsNullOrEmpty(ProductDDL.SelectedValue))
            {
                MessageUserControl.ShowInfo("Required Data", "Please Select Category and Product");
            }
            else if (CategoryDDL.SelectedIndex == 0)
            {
                MessageUserControl.ShowInfo("Please Select a Category");
            }
            //else if(ProductDDL.SelectedIndex == 0)
            //{
            //    MessageUserControl.ShowInfo("Please Select a Product");
            //}
            else if (products.QuantityOnOrder <= 0)
            {
                MessageUserControl.ShowInfo("Required Data", "Please Enter Quantity, Should be greater or equal 1");
                PanelPaymentButtons.Visible = false;
            }
            else
            {
                string category = CategoryDDL.SelectedValue;

                int qty       = int.Parse(QuantityTextBox.Text);
                int productid = int.Parse(ProductDDL.SelectedValue);

                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.Add_ItemToCart(employeeID, productid, qty);

                    List <ShoppingCart> datainfo = sysmgr.ShoppingCart_OrderList();
                    CartSalesGridView.DataSource = datainfo;
                    CartSalesGridView.DataBind();
                }, "Adding Item", "Item has been added to 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");
            }
        }