예제 #1
0
        public static void BuyerView()
        {
            int    choice;
            int    temp = 0;
            int    key;
            string input;
            Goods  good;

            Console.WriteLine("欢迎顾客{0}", Mostone.user.Name);
            while (true)
            {
                choice = ChoiceGuide("1、浏览商品 2、购买商品 3、管理购物车 4、充值 5、查看余额 6、购买记录 7、退出", 1, 7);
                switch (choice)
                {
                case 1:
                    DisplayList(MySQLDemo.FindAllGoods());
                    break;

                case 2:
                    good = null;

                    while (true)
                    {
                        Console.Write("输入欲购买商品编号\n>>");
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM))
                        {
                            continue;
                        }
                        good = MySQLDemo.FindGoodsById(int.Parse(input));
                        if (null == good)
                        {
                            continue;
                        }
                        break;
                    }
                    while (true)
                    {
                        Console.Write("输入购买数量\n>>");
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM))
                        {
                            continue;
                        }
                        if (int.Parse(input) < 0 || int.Parse(input) > good.Nums)
                        {
                            continue;
                        }
                        break;
                    }
                    key = MController.IsContain(good);
                    if (key != -1)
                    {
                        temp = MController.GetTrolleyGoodsNums(good);
                        Mostone.trolley.Remove(key);
                    }
                    good.Nums = int.Parse(input) + temp;
                    Mostone.trolley.Add(Mostone.trolley.Count, good);
                    break;

                case 3:
                    TrolleyHandleView();
                    break;

                case 4:
                    Console.Write("输入要充值的金额\n>>");
                    while (true)
                    {
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM) ||
                            !StringRegular.RegularChecker(input, StringRegular.ISFLOAT))
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }

                        Mostone.user.Saves += double.Parse(input);
                        MySQLDemo.UpdateUser(Mostone.user);
                        break;
                    }
                    break;

                case 5:
                    Console.WriteLine("余额为:{0}", Mostone.user.Saves);
                    break;

                case 6:
                    DisplayList(MySQLDemo.FindPurMessByBuyer((Buyer)Mostone.user));
                    break;

                case 7:
                    Mostone.user = null;
                    return;
                }
            }
        }
예제 #2
0
        public static void SellerView()
        {
            int          choice;
            string       input;
            Goods        good;
            List <Goods> lgs = null;

            Console.WriteLine("欢迎店长{0}", Mostone.user.Name);
            while (true)
            {
                choice = ChoiceGuide("1、查看自属商品 2、查看所有商品 3、新增商品 4、修改商品信息 5、订单消息 6、查看账户 7、退出", 1, 7);

                switch (choice)
                {
                case 1:
                    lgs = MySQLDemo.FindGoodsByOwner(Mostone.user);
                    if (null != lgs)
                    {
                        foreach (Goods gd in lgs)
                        {
                            if (0 == gd.Nums)
                            {
                                gd.IsSale = false;
                                MySQLDemo.UpdateGoods(gd);
                            }
                        }
                    }
                    DisplayList(lgs);
                    break;

                case 2:
                    DisplayList(MySQLDemo.FindAllGoods());
                    break;

                case 3:
                    good = InputGoodsMess(new Goods(Mostone.user.Id));
                    MySQLDemo.InserGoods(good);
                    break;

                case 4:
                    while (true)
                    {
                        Console.Write("输入欲操作商品编号\n>>");
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM))
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }
                        good = MySQLDemo.FindGoodsById(int.Parse(input));
                        if (null == good)
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }
                        break;
                    }
                    good = InputGoodsMess(good);
                    MySQLDemo.UpdateGoods(good);
                    break;

                case 5:
                    OrderView();
                    break;

                case 6:
                    Console.WriteLine("余额为:{0}", Mostone.user.Saves);
                    break;

                case 7:
                    Mostone.user = null;
                    return;
                }
            }
        }
예제 #3
0
        public static void TrolleyHandleView()
        {
            int    choice;
            string input;

            while (true)
            {
                choice = ChoiceGuide("1、查看购物车 2、删除商品 3、提交订单 4、返回", 1, 4);
                switch (choice)
                {
                case 1:
                    DisplayTrolley();
                    break;

                case 2:
                    while (true)
                    {
                        Console.Write("输入要删除的商品序号\n>>");
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM) ||
                            !Mostone.trolley.ContainsKey(int.Parse(input)))
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }

                        Mostone.trolley.Remove(int.Parse(input));
                        break;
                    }
                    break;

                case 3:
                    int                 oid;
                    bool                flag    = true;
                    OrderList           order   = new OrderList(DateTime.Now);
                    List <PurchaseMess> purMess = new List <PurchaseMess>();

                    foreach (Goods good in Mostone.trolley.Values)
                    {
                        order.Summary += good.Price * good.Nums;
                        purMess.Add(MController.GeneratePurchase(good));

                        if (good.Nums > MySQLDemo.FindGoodsById(good.Id).Nums)
                        {
                            flag = false;
                            Console.WriteLine("{0}的商品{1}库存不足", good.S_id, good.Id);
                        }
                    }

                    if (Mostone.user.Saves < order.Summary)
                    {
                        Console.WriteLine("余额不足,请充值");
                        break;
                    }

                    if (!flag)
                    {
                        break;
                    }

                    Mostone.user.Saves -= order.Summary;

                    MySQLDemo.UpdateUser(Mostone.user);
                    MySQLDemo.InsertOrderList(order, out oid);

                    foreach (PurchaseMess pm in purMess)
                    {
                        pm.O_id = oid;
                        MySQLDemo.InsertPurchaseMess(pm);
                        Goods good = MySQLDemo.FindGoodsById(pm.G_id);
                        good.Nums -= pm.Nums;
                        MySQLDemo.UpdateGoods(good);
                    }
                    Mostone.trolley.Clear();
                    break;

                case 4:
                    return;
                }
            }
        }