Exemplo n.º 1
0
        public List <CartItem> UpdateCartItems()
        {
            using (var shoppingCartActions = new ShoppingCartActions())
            {
                var cartId = shoppingCartActions.GetCartId();


                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new
                                                                        ShoppingCartActions.ShoppingCartUpdates[CartGridView.Rows.Count];

                for (int i = 0; i < CartGridView.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartGridView.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    var cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartGridView.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    var quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartGridView.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text);
                }

                shoppingCartActions.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartGridView.DataBind();
                lblTotal.Text = string.Format("{0:c}", shoppingCartActions.GetTotal());

                return(shoppingCartActions.GetCartItems());
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionFacade.USERNAME == null)
            {
                SessionFacade.PAGEREQUESTED = Request.ServerVariables["SCRIPT_NAME"];
                Response.Redirect("Login.aspx");
            }
            else
            {
                IBusinessDataAccount _IBusinessDataAccount = GenericFactory <BusinessLayer, IBusinessDataAccount> .CreateInstance();

                cartDataSet = _IBusinessDataAccount.ViewCart(SessionFacade.USERNAME);
                // Not working - ask doubt
                if (cartDataSet.Tables.Count == 0)
                {
                    Message.Text = "You haven't added items to the cart";
                }
                else
                {
                    Message.Text = null;
                    foreach (DataTable tables in cartDataSet.Tables)
                    {
                        foreach (DataRow dataRow in tables.Rows)
                        {
                            totalPriceToPay += Convert.ToDecimal(dataRow["Price"]);
                            totalItems      += (dataRow["ProductSmallDescription"] + " ");
                        }
                    }
                    //Message.Text = "Total amount to pay : " + totalPriceToPay + " and the products bought are : " + totalItems;
                    CartGridView.DataSource = cartDataSet;
                    CartGridView.DataBind();
                }
            }
        }
        protected void DeleteItem_Click(object sender, EventArgs e)
        {
            SalesController controller = new SalesController();
            var             userName   = User.Identity.Name;

            MessageUserControl.TryRun(() =>
            {
                var gridView   = (GridViewRow)((Button)sender).NamingContainer;
                int cartItemId = int.Parse((gridView.FindControl("CartItemId") as HiddenField).Value);
                controller.DeleteCartItem(cartItemId);

                var shoppingCartId = controller.RetriveShoppingCartId(userName);
                List <ProductInCart> partsIncart = controller.ListProductsinCart(shoppingCartId);

                CartGridView.Visible    = true;
                CartGridView.DataSource = partsIncart;
                CartGridView.DataBind();

                //calculate total price
                decimal totalPrice = controller.CalculateTotal(shoppingCartId);
                TotalPrice.Text    = string.Format("{0:C}", totalPrice);

                //show amount of items in cart and lastUpdated date
                DateTime updatedOn = controller.UpdateDate(shoppingCartId);
                var partAmount     = controller.CartPartCount().ToString();
                InfoRow.Text       = ($"{partAmount} items in your cart(last updated on {String.Format("{0:MM/d/yyyy}", updatedOn)})");
            }, "Successfuly deleted", $"Item have been deleted from your cart");
        }
        protected void UpdateItemQty_Click(object sender, EventArgs e)
        {
            SalesController controller = new SalesController();
            var             userName   = User.Identity.Name;
            var             gridView   = (GridViewRow)((Button)sender).NamingContainer;
            int             cartItemId = int.Parse((gridView.FindControl("CartItemId") as HiddenField).Value);
            int             qty        = int.Parse((gridView.FindControl("QtyTextBox") as TextBox).Text);

            MessageUserControl.TryRun(() =>
            {
                if (qty <= 0)
                {
                    throw new Exception("Quantity must be positive value");
                }
                else
                {
                    controller.UpdateCartItemQty(cartItemId, qty);
                    var shoppingCartId = controller.RetriveShoppingCartId(userName);
                    List <ProductInCart> partsIncart = controller.ListProductsinCart(shoppingCartId);

                    CartGridView.Visible    = true;
                    CartGridView.DataSource = partsIncart;
                    CartGridView.DataBind();
                    //calculate total price
                    decimal totalPrice = controller.CalculateTotal(shoppingCartId);
                    TotalPrice.Text    = string.Format("{0:C}", totalPrice);

                    //show amount of items in cart and lastUpdated date
                    DateTime updatedOn = controller.UpdateDate(shoppingCartId);
                    var partAmount     = controller.CartPartCount().ToString();
                    InfoRow.Text       = ($"{partAmount} items in your cart(last updated on {String.Format("{0:MM/d/yyyy}", updatedOn)})");
                }
            }, "Successfuly updateted", $"Quntity updated to {qty} ");
        }
Exemplo n.º 5
0
        private void SelectTube(int tubeId, string name, Decimal price)
        {
            if (Session[Session_CurrentUser] == null)
            {
                Response.Redirect("LogIn.aspx");
                return;
            }

            if (Session[Session_OrderNum] == null)
            {
                NewOrder();
            }

            if (!CheckOrderItem(tubeId))
            {
                NewOrderItem(tubeId);
            }
            else
            {
                IncrementOrderItem(tubeId);
            }

            CartGridView.DataBind();
            TotalGridView.DataBind();
        }
Exemplo n.º 6
0
        protected void RefreshButton_Click(object sender, EventArgs e)
        {
            List <CartDisplay> cartList = new List <CartDisplay>();

            refreshSalesGridView(cartList);

            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
        }
Exemplo n.º 7
0
        protected void ProductRowQuantity_TextChanged(object sender, EventArgs e)
        {
            List <CartDisplay> cartList = new List <CartDisplay>();

            refreshSalesGridView(cartList);

            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
        }
        protected void CartGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            int EmpID = (int)HttpContext.Current.Session["EmpID"];

            CartGridView.DataSource = RequestBizLogic.ViewNotSubmittedRequestDetail(EmpID);//employeeId

            CartGridView.PageIndex = e.NewPageIndex;
            CartGridView.DataBind();
            //BindGrid();
        }
Exemplo n.º 9
0
        protected void ClearForm_Click(object sender, EventArgs e)
        {
            List <CartDisplay> cartList = new List <CartDisplay>();

            clearTotals();
            resetInputs();
            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
            AddProductButton.Enabled = true;
        }
Exemplo n.º 10
0
        private void GridViewCartBindGrid()
        {
            int EmpID = (int)HttpContext.Current.Session["EmpID"];

            CartGridView.DataSource = RequestBizLogic.ViewNotSubmittedRequestDetail(EmpID);//employeeId
            CartGridView.DataBind();
            CartGridView.Visible = true;

            ButtonSubmitRequest.Visible = true;
            ButtonDeleteRequest.Visible = true;
        }
Exemplo n.º 11
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            cartList = Session["cart"] as List <Book>;
            int Index = e.RowIndex;

            cartList.RemoveAt(Index);
            Session["cart"]         = cartList;
            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
            PopulateTotalPrice();
            DisableConfirmButton();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var userName       = User.Identity.Name;
            var controller     = new SalesController();
            var shoppingCartId = controller.RetriveShoppingCartId(userName);

            if (shoppingCartId == 0)
            {
                Response.Redirect("~/Sales/OnlineShoppingAndCheckout.aspx", true);
            }
            else
            {
                List <ProductInCart> partsIncart = controller.ListProductsinCart(shoppingCartId);

                //check if items in stock and change accordingly the place order button text
                List <ProductInCart> unavailableParts = new List <ProductInCart>();
                string unavalableMessage = "";
                foreach (var part in partsIncart)
                {
                    if (part.StockAvailabillty != "")
                    {
                        PlaceOrder.Text = "Order In-Stock Items Only";
                        unavailableParts.Add(part);
                        unavalableMessage += $" {part.PartDesc} {part.Qty.ToString()} ";
                    }
                }
                if (unavailableParts.Count > 0)
                {
                    ExcludedPanle.Visible = true;
                    EcludedLabel.Text     = "This parts would be excluded from your order price and placed as backorder:" + unavalableMessage + " pcs";
                }
                CartGridView.Visible    = true;
                CartGridView.DataSource = partsIncart;
                CartGridView.DataBind();

                //calculate total price
                decimal subPrice   = controller.CalculateTotal(shoppingCartId);
                decimal gst        = subPrice * (decimal)0.05;
                decimal totalPrice = subPrice * (decimal)1.05;
                SubTotal.Text   = string.Format("{0:C}", subPrice);
                TotalGST.Text   = string.Format("{0:C}", gst);
                TotalPrice.Text = string.Format("{0:C}", totalPrice);


                //show amount of items in cart and lastUpdated date
                DateTime updatedOn  = controller.UpdateDate(shoppingCartId);
                var      partAmount = controller.CartPartCount().ToString();
                InfoRow.Text = ($"{partAmount} items in your cart(last updated on {String.Format("{0:MM/d/yyyy}", updatedOn)})");
            }
        }
Exemplo n.º 13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         cartList = Session["cart"] as List <Book>;
         if (cartList != null)
         {
             CartGridView.DataSource = cartList;
             CartGridView.DataBind();
         }
         PopulateTotalPrice();
         DisableConfirmButton();
     }
 }
        private void RenderGrid()
        {
            var itemlist = ServicesShoppingCart.GetShoopingCart().BookList;

            CartGridView.DataSource = ServicesShoppingCart.GetItemDetails(itemlist);
            CartGridView.DataBind();

            var WishList = (from p in ServicesShoppingCart.GetWishList()
                            select new BookItem {
                ISBN = p
            }).ToList();

            WishGridView.DataSource = ServicesShoppingCart.GetItemDetails(WishList);
            WishGridView.DataBind();
        }
Exemplo n.º 15
0
        protected void DeleteItemButton_Click(object sender, EventArgs e)
        {
            List <CartDisplay> cartList = new List <CartDisplay>();
            int         index;
            GridViewRow gvr;
            LinkButton  button = (LinkButton)sender;

            gvr   = (GridViewRow)button.Parent.Parent;
            index = gvr.RowIndex;

            refreshSalesGridView(cartList);
            cartList.Remove(cartList[index]);

            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
        }
Exemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            decimal deposit = 0;

            objBAL = new BusinessLayer();

            // Populates the GridView with Session Cart information or displays the error that the cart is empty
            if (!this.IsPostBack)
            {
                if (Session["Cart"] != null)
                {
                    Order oCart = new Order();
                    oCart = Session["Cart"] as Order;

                    CartGridView.DataSource = oCart.OrderItems;
                    CartGridView.DataBind();
                }
                else
                {
                    lblError.Visible = true;
                }

                // Calculates the Deposit Amount and Populates txtDeposit
                foreach (GridViewRow row in CartGridView.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        deposit = deposit + decimal.Parse(row.Cells[5].Text);
                    }
                }

                deposit         = deposit * 10 / 100;
                txtDeposit.Text = deposit.ToString("c");

                // Populates the Label (lblTotal) with the Total Amount of the Order
                foreach (GridViewRow row in CartGridView.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        grdTotal = grdTotal + decimal.Parse(row.Cells[5].Text);
                    }
                }

                lblTotal.Text = "Total: " + grdTotal.ToString("c");
            }
        }
Exemplo n.º 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     CheckTimeStamps();
     if (Session["cart"] == null)
     {
         cart            = new ShoppingCart();
         Session["cart"] = cart;
     }
     else
     {
         cart = (ShoppingCart)Session["cart"];
     }
     CartGridView.DataSource = cart.GetItems();
     if (!IsPostBack)
     {
         CartGridView.DataBind();
     }
 }
Exemplo n.º 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Populates the GridView with Session Cart information or displays the error that the cart is empty
            if (!this.IsPostBack)
            {
                objBAL = new BusinessLayer();

                //Get CatalogItems
                lCatalogItem = objBAL.GetCatalogItems();

                // Populate Grid View if Cart is not Empty, if cart is empty display error.
                if (Session["Cart"] != null)
                {
                    Order oCart = new Order();
                    oCart = Session["Cart"] as Order;

                    //Bind Catalog Info to the OrderItems
                    AddCatalogInfoToOrderItems(ref lCatalogItem, ref oCart);

                    CartGridView.DataSource = oCart.OrderItems;
                    CartGridView.DataBind();

                    // Populates the Label (lblTotal) with the Total Amount of the Order
                    foreach (GridViewRow row in CartGridView.Rows)
                    {
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            grdTotal = grdTotal + decimal.Parse(row.Cells[6].Text);
                        }
                    }

                    lblTotal.Text = "Total: " + grdTotal.ToString("c");
                }
                else
                {
                    // displayes error and removed buttons.
                    lblError.Visible           = true;
                    btnRemoveFromCart.Visible  = false;
                    btnConfirmPurchase.Visible = false;
                    lblTotal.Visible           = false;
                }
            }
        }
Exemplo n.º 19
0
    private void AssignDataSource(ShoppingCartService.ShoppingCartInfo cartInfo, OrderService.CreditCardInfo cardInfo)
    {
        OrderLiteral.Text = OrderNoLiteral.Text = Request.QueryString["orderId"];

        OrderDateLiteral.Text      = DateTime.Now.ToShortDateString();
        PaymentDetailsLiteral.Text = cardInfo.Type.Name + " ," + "XXXX-XXXX-XXXX-" + cardInfo.Number.Substring(cardInfo.Number.Length - 4);
        BillingAddressLiteral.Text = cardInfo.Address.Address1 + ", ";
        if (cardInfo.Address.Address2 != string.Empty && cardInfo.Address.Address2 != null)
        {
            BillingAddressLiteral.Text += cardInfo.Address.Address2 + ", ";
        }
        BillingAddressLiteral.Text += cardInfo.Address.City + ", " + cardInfo.Address.State.Name + "-" + cardInfo.Address.Zip;
        if (cartInfo.CartItems.Length > 0)
        {
            CartGridView.DataSource = cartInfo.CartItems;
            CartGridView.DataBind();
            SubTotalLiteral.Text   = cartInfo.SubTotal.ToString();
            ShippingLiteral.Text   = cartInfo.ShippingAndHandling.ToString();
            TaxLiteral.Text        = cartInfo.Tax.ToString();
            GrandTotalLiteral.Text = cartInfo.GrandTotal.ToString();
            DiscountLiteral.Text   = cartInfo.Discount.ToString();
        }
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            //populate with products in cart
            var userName       = User.Identity.Name;
            var controller     = new SalesController();
            var shoppingCartId = controller.RetriveShoppingCartId(userName);
            List <ProductInCart> partsIncart = controller.ListProductsinCart(shoppingCartId);

            CartGridView.Visible    = true;
            CartGridView.DataSource = partsIncart;
            CartGridView.DataBind();

            //calculate total price
            decimal totalPrice = controller.CalculateTotal(shoppingCartId);

            TotalPrice.Text = string.Format("{0:C}", totalPrice);

            //show amount of items in cart and lastUpdated date
            DateTime updatedOn  = controller.UpdateDate(shoppingCartId);
            var      partAmount = controller.CartPartCount().ToString();

            InfoRow.Text = ($"{partAmount} items in your cart(last updated on {String.Format("{0:MM/d/yyyy}", updatedOn)})");
        }
Exemplo n.º 21
0
 private void UpdateGridData()
 {
     CartGridView.DataSource = getCartBook();
     CartGridView.DataBind();
 }
Exemplo n.º 22
0
 private void AssignDataSource(OrderService.OrderInfo orderInfo, OrderService.CreditCardInfo cardInfo)
 {
     OrderNoLiteral.Text        = orderInfo.OrderId.ToString();
     OrderDateLiteral.Text      = orderInfo.Date.ToShortDateString();
     PaymentDetailsLiteral.Text = cardInfo.Type.Name + " ," + "XXXX-XXXX-XXXX-" + cardInfo.Number.Substring(cardInfo.Number.Length - 4);
     BillingAddressLiteral.Text = cardInfo.Address.Address1 + ", ";
     if (cardInfo.Address.Address2 != string.Empty && cardInfo.Address.Address2 != null)
     {
         BillingAddressLiteral.Text += cardInfo.Address.Address2 + ", ";
     }
     BillingAddressLiteral.Text += cardInfo.Address.City + ", " + cardInfo.Address.State.Name + "-" + cardInfo.Address.Zip;
     if (orderInfo.RefundAmount != null && orderInfo.RefundAmount != 0)
     {
         RefundAmountLiteral.Text = orderInfo.RefundAmount.ToString();
         RefundPanel.Visible      = true;
     }
     else
     {
         RefundPanel.Visible = false;
     }
     if (orderInfo.Items.Length > 0)
     {
         ShoppingCartInfo            cartInfo1    = new ShoppingCartInfo();
         ShoppingCartItemInfo        cartItemInfo = new ShoppingCartItemInfo();
         List <ShoppingCartItemInfo> cartItems    = new List <ShoppingCartItemInfo>();
         foreach (OrderService.OrderItemInfo orderItem in orderInfo.Items)
         {
             cartItemInfo             = new ShoppingCartItemInfo();
             cartItemInfo.Description = orderItem.Title;
             cartItemInfo.Price       = orderItem.Rate;
             cartItemInfo.Quantity    = orderItem.Quantity;
             cartItemInfo.ProductId   = orderItem.ItemId;
             cartItemInfo.TotalPrice  = cartItemInfo.Quantity * cartItemInfo.Price;
             cartInfo1.SubTotal      += cartItemInfo.TotalPrice;
             cartInfo1.SubTotal       = Math.Round(cartInfo1.SubTotal, 2);
             cartItems.Add(cartItemInfo);
         }
         cartInfo1.CartItems = cartItems.ToArray();
         if (cardInfo.Address.State.Name.ToLower() == "colorado")
         {
             CommonService commonService = ServiceAccess.GetInstance().GetCommon();
             if (commonService.GetProperty("Tax") != null)
             {
                 cartInfo1.Tax = Convert.ToDecimal(commonService.GetProperty("Tax").Value);
             }
         }
         else
         {
             cartInfo1.Tax = 0;
         }
         ShoppingCartService cartService = ServiceAccess.GetInstance().GetShoppingCart();
         ShoppingCartInfo    cartInfo    = cartService.CalculateGrandTotal(cartInfo1);
         CartGridView.DataSource = cartInfo.CartItems;
         CartGridView.DataBind();
         SubTotalLiteral.Text   = cartInfo.SubTotal.ToString();
         ShippingLiteral.Text   = cartInfo.ShippingAndHandling.ToString();
         TaxLiteral.Text        = cartInfo.Tax.ToString();
         GrandTotalLiteral.Text = cartInfo.GrandTotal.ToString();
         DiscountLiteral.Text   = cartInfo.Discount.ToString();
     }
     else
     {
         ProductsPanel.Visible = false;
     }
 }
Exemplo n.º 23
0
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            // all local vars
            int                categoryId, productId, productQuantity;
            CartDisplay        cartItem;
            bool               isNewItem = true;
            List <CartDisplay> cartList  = new List <CartDisplay>();

            // Make sure we have numbers
            refreshSalesGridView(cartList);

            // Run BLL
            MessageUserControl.TryRun(() =>
            {
                if (int.TryParse(CategorySelectDDL.SelectedValue, out categoryId) && int.TryParse(ProductSelectDDL.SelectedValue, out productId))
                {
                    foreach (CartDisplay item in cartList)
                    {
                        if (item.ProductID == productId && item.CategoryID == categoryId)
                        {
                            isNewItem = false;
                            int.TryParse(NumberOfProductsTextBox.Text, out productQuantity);
                            if (productQuantity > 0)
                            {
                                item.ProductQuantity += productQuantity;
                                updateTotals(item);
                            }
                        }
                    }
                    if (int.TryParse(NumberOfProductsTextBox.Text, out productQuantity) && productQuantity > 0)
                    {
                        if (isNewItem)
                        {
                            SalesController sc = new SalesController();
                            cartItem           = sc.Get_CartDisplayItem(productId, categoryId);
                            if (productQuantity > 0)
                            {
                                cartItem.ProductQuantity = productQuantity;
                                cartList.Add(cartItem);
                                updateTotals(cartItem);
                            }
                        }
                    }
                    else
                    {
                        throw new BusinessRuleException("Add Product Error", new List <String> {
                            "Quantity must be greater then 0"
                        });
                    }
                }
                else
                {
                    throw new BusinessRuleException("Selected Value Error", new List <String> {
                        "Values where not numbers"
                    });
                }
            });
            resetInputs();
            CartGridView.DataSource = cartList;
            CartGridView.DataBind();
        }