Exemple #1
0
        public static bool UsernameVerify(string username, bool isBuyer)
        {
            User user = MySQLDemo.FindUserByName(username, isBuyer);

            if (user == null)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public static User CheckUser(string name, string pass, bool isBuyer)
        {
            User user = MySQLDemo.FindUserByName(name, isBuyer);

            if (null == user)
            {
                return(null);
            }

            if (pass.Equals(user.Pass))
            {
                return(user);
            }
            return(null);
        }
Exemple #3
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);
        }
Exemple #4
0
        public static void OrderHandleView(PurchaseMess pmess)
        {
            int choice;

            choice = ChoiceGuide("1、发货 2、返回", 1, 2);

            switch (choice)
            {
            case 1:
                Seller seller = (Seller)Mostone.user;
                seller.Saves += pmess.Nums * pmess.Price;
                MySQLDemo.UpdateUser(seller);
                pmess.PurState = "1";
                MySQLDemo.UpdatePurMess(pmess);
                break;

            case 2:
                return;
            }
        }
Exemple #5
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;
                }
            }
        }
Exemple #6
0
        public static void OrderView()
        {
            int                 choice;
            int                 temp;
            string              input;
            bool                flag  = false;
            PurchaseMess        pmess = null;
            List <PurchaseMess> lp;

            lp = MySQLDemo.FindPurMessBySellerAndState((Seller)Mostone.user, "0");

            while (true)
            {
                choice = ChoiceGuide("1、显示购买信息 2、查找购买信息 3、返回", 1, 3);
                switch (choice)
                {
                case 1:
                    DisplayList(lp);
                    break;

                case 2:
                    while (true)
                    {
                        Console.Write("输入商品编号\n>>");
                        input = Console.ReadLine();
                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM))
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }
                        foreach (PurchaseMess p in lp)
                        {
                            if (int.Parse(input) == p.G_id)
                            {
                                flag = true;
                            }
                        }
                        if (!flag)
                        {
                            Console.WriteLine("无此在售商品编号");
                            continue;
                        }
                        temp = int.Parse(input);
                        break;
                    }
                    while (true)
                    {
                        Console.Write("输入指定信息的订单编号\n>>");
                        input = Console.ReadLine();
                        pmess = null;

                        if (!StringRegular.RegularChecker(input, StringRegular.ALLNUM))
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }
                        foreach (PurchaseMess p in lp)
                        {
                            if (temp == p.G_id && int.Parse(input) == p.O_id)
                            {
                                pmess = p;
                            }
                        }

                        if (null == pmess)
                        {
                            Console.WriteLine("输入有误");
                            continue;
                        }
                        break;
                    }
                    OrderHandleView(pmess);
                    lp = MySQLDemo.FindPurMessBySellerAndState((Seller)Mostone.user, "0");
                    break;

                case 3:
                    return;
                }
            }
        }
Exemple #7
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;
                }
            }
        }
Exemple #8
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;
                }
            }
        }