Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the GroceryCo Shopping App:");

            ShowOptions();

            string selection = Console.ReadLine().ToUpper();

            while (!selection.Equals("Q"))
            {
                switch (selection)
                {
                case "L":
                    IProductReport productReport = new ProductReport();
                    productReport.DisplayProducts();
                    break;

                case "C":
                    IShoppingCartHandler shoppingCartHandler = new ShoppingCartHandler();
                    shoppingCartHandler.CheckoutShoppingCart();
                    break;

                case "Q":
                    break;

                default:
                    Console.WriteLine("Invalid option selected");
                    break;
                }

                ShowOptions();

                selection = Console.ReadLine().ToUpper();
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["ShoppingCart"] != null)
        {
            Dictionary <int, int> shoppingCart = Session["ShoppingCart"] as Dictionary <int, int>;

            string         idString = string.Join(",", shoppingCart.Keys);
            ProductHandler ph       = new ProductHandler();
            List <Product> prodList = ph.GetProductsByIDs(idString);

            ShoppingCartHandler sch   = new ShoppingCartHandler();
            List <ShoppingCart> sList = sch.GetShoppingCartList(shoppingCart, prodList);



            Repeater1.DataSource = sList;
            Repeater1.DataBind();

            int total = 0;
            foreach (var item in sList)
            {
                total += item.Totalprice;
            }

            Label1.Text = $"NT${total.ToString()}";
        }
    }
Пример #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            ProductHandler ph  = new ProductHandler();
            string         str = "請先登入會員在進行購物車功能!";
            ph.strMsg(str);
        }

        if (Session["ShoppingCart"] != null)
        {
            Dictionary <int, int> shoppingCart = Session["ShoppingCart"] as Dictionary <int, int>;

            string         idString = string.Join(",", shoppingCart.Keys);
            ProductHandler ph       = new ProductHandler();
            List <Product> prodList = ph.GetProductsByIDs(idString);

            ShoppingCartHandler sch   = new ShoppingCartHandler();
            List <ShoppingCart> sList = sch.GetShoppingCartList(shoppingCart, prodList);

            Repeater1.DataSource = sList;
            Repeater1.DataBind();

            int total = 0;
            foreach (var item in sList)
            {
                total += item.Totalprice;
            }

            Label1.Text = total.ToString();
        }
        else
        {
            //Repeater1.DataSource = "購物車內無任何商品";
            //Repeater1.DataBind();
            ProductHandler ph  = new ProductHandler();
            string         str = "購物車內無任何商品";
            ph.strMsg(str);
        }
    }