Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            MController.Init();

            MViewer.MainView();

            MController.Stop();
        }
Exemplo n.º 2
0
        public static void SignUp()
        {
            string username;
            string password;
            string passAgain;
            int    idenKey;
            bool   isBuyer;
            int    autoId;

            Console.Write("请输入用户名\n>>");
            username = Console.ReadLine();
            Console.Write("请输入密码\n>>");
            password = ReadPassword();
            Console.Write("再输入一次密码\n>>");
            passAgain = ReadPassword();
            idenKey   = ChoiceGuide("1、买家 2、卖家", 1, 2);
            isBuyer   = (1 == idenKey ? true : false);

            Console.WriteLine();

            if (!passAgain.Equals(password))
            {
                Console.WriteLine("两次密码不一致");
                SignUp();
                return;
            }
            if (!StringRegular.RegularChecker(password, StringRegular.PASSWORD))
            {
                Console.WriteLine("密码格式不正确");
                SignUp();
                return;
            }
            if (MController.UsernameVerify(username, isBuyer))
            {
                Console.WriteLine("用户名已存在");
                SignUp();
                return;
            }

            MySQLDemo.InsertUser(username, password, isBuyer, out autoId);
            Mostone.user = MySQLDemo.FindUserById(autoId, isBuyer);
        }
Exemplo n.º 3
0
        public static void SignIn()
        {
            string username;
            string password;
            User   curUser;
            bool   isBuyer = (1 == ChoiceGuide("1、买家登录 2、卖家登录", 1, 2)?true:false);

            Console.Write("输入用户名\n>>");
            username = Console.ReadLine();
            Console.Write("输入密码\n>>");
            password = ReadPassword();

            curUser = MController.CheckUser(username, password, isBuyer);
            if (null == curUser)
            {
                Console.WriteLine("无此用户或密码错误");
                SignIn();
                return;
            }

            Mostone.user = curUser;
        }
Exemplo n.º 4
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;
                }
            }
        }
Exemplo n.º 5
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;
                }
            }
        }