コード例 #1
0
        static void Main(string[] args)
        {
            var all = new OrderDetail(0);

            all.ShowGoods();

            try
            {
                Order order1 = new Order(2, 1, "CC");
                Order order2 = new Order(1, 100, "PP");
                Order order3 = new Order(3, 1, "TuHao");
                Order order4 = new Order(1, 1, "A");

                OrderService service = new OrderService();
                service.AddOrder(order1);
                service.AddOrder(order2);
                service.AddOrder(order3);
                service.AddOrder(order4);

                service.ShowGouWuChe();
                Console.WriteLine("");

                service.ShowOrder(service.SearchOrderLinQByGoodsName("Gold"));
                service.ShowOrder(service.SearchOrderLinQByClient("Gold"));
                service.ShowOrder(service.SearchOrderLinQByClient("PP"));

                Console.ReadLine();

                System.Threading.Thread.Sleep(2000);
                service.DeleteOrder(order4.ID);
                service.ShowGouWuChe();
                Console.WriteLine("");

                System.Threading.Thread.Sleep(2000);
                service.ChangeOrder(order2.ID, 2, 9);
                service.ShowGouWuChe();
                Console.WriteLine("");

                System.Threading.Thread.Sleep(2000);
                service.DeleteOrder("123456");
            }
            catch (DefaultInfluenceOrder e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GudaozhishangYz/C-homework
        public void OrderS(int x)
        {
            switch (x)
            {
            case 1:
                orderservice.AddOrder();
                break;

            case 2:
                orderservice.DeleteOrder();
                break;

            case 3:
                orderservice.ChangeOrder();
                break;

            case 4:
                orderservice.SearchOrder();
                break;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: taohong1999/CSharpHomework
        public static void DoOrder(string s, OrderService orderService)
        {
            if (s == "添加订单")
            {
                Console.WriteLine("请按顺序输入客户姓名,订单号(例:张三 123456789(每输入一个信息请按下回车键)):");
                string customer    = "";
                string ordernumber = "";
                customer    = Console.ReadLine();
                ordernumber = Console.ReadLine();

                Console.WriteLine("该订单有几种商品:");
                string sNum = Console.ReadLine();
                int    num  = 0;
                try
                {
                    num = Int32.Parse(sNum);
                }
                catch
                {
                    Console.WriteLine("输入的件数存在问题");
                }
                if (num <= 0)
                {
                    Console.WriteLine("商品件数应该大于0");
                }
                else
                {
                    orderService.AddOrder(ordernumber, customer, num);
                }
            }

            else if (s == "查询订单")
            {
                Console.WriteLine("请输入需要查询的订单的一项信息(姓名或订单号):");
                string s1 = "";
                s1 = Console.ReadLine();
                Console.WriteLine("您的订单信息为:");
                orderService.OutOrder(s1);
            }

            else if (s == "修改订单")
            {
                Console.WriteLine("请输入需要查询的订单的一项信息(姓名或订单号):");
                string s1 = "";
                s1 = Console.ReadLine();
                Orders order;
                order = orderService.SearchOrder(s1);
                orderService.OutOrder(s1);
                if (order != null)
                {
                    string str;
                    Console.WriteLine("是否修改订单号和客户名称(是或否)");
                    str = Console.ReadLine();
                    if (str == "是")
                    {
                        Console.WriteLine("请按顺序输入新的订单信息(客户姓名,订单号):");
                        string customer    = "";
                        string ordernumber = "";
                        customer    = Console.ReadLine();
                        ordernumber = Console.ReadLine();
                        orderService.ChangeOrder(order, customer, ordernumber);
                    }

                    Console.WriteLine("是否增加商品");
                    str = Console.ReadLine();
                    if (str == "是")
                    {
                        bool isContinue = true;
                        do
                        {
                            Console.WriteLine("输入添加的商品的信息(名称,单价,数量)");
                            string str2 = "";
                            str2 = Console.ReadLine();
                            string name = str2;

                            str2 = Console.ReadLine();
                            double price = 0;
                            try { price = double.Parse(str2); }
                            catch { Console.WriteLine("输入单价格式错误"); }

                            str2 = Console.ReadLine();
                            int number = 0;
                            try { number = Int32.Parse(str2); }
                            catch { Console.WriteLine("输入数量格式错误"); }
                            orderService.ChangeGoods(order, true, name, price, number);
                            Console.WriteLine("是否继续增加");
                            str2 = Console.ReadLine();
                            if (str2 == "是")
                            {
                                isContinue = true;
                            }
                            else if (str2 == "否")
                            {
                                isContinue = false;
                            }
                            else
                            {
                                Console.WriteLine("输入的指令有误");
                            }
                        } while (isContinue == true);
                    }

                    Console.WriteLine("是否删除商品");
                    str = Console.ReadLine();
                    if (str == "是")
                    {
                        bool isContinue = true;
                        do
                        {
                            Console.WriteLine("输入删除的商品的名称");
                            string str2 = "";
                            str2 = Console.ReadLine();
                            string name = str2;
                            orderService.ChangeGoods(order, false, name);
                            Console.WriteLine("是否继续删除");
                            str2 = Console.ReadLine();
                            if (str2 == "是")
                            {
                                isContinue = true;
                            }
                            else if (str2 == "否")
                            {
                                isContinue = false;
                            }
                            else
                            {
                                Console.WriteLine("输入的指令有误");
                            }
                        } while (isContinue == true);
                    }
                }
            }

            else if (s == "删除订单")
            {
                Console.WriteLine("请输入需要删除的订单的一项信息(姓名或订单号):");
                string s1 = "";
                s1 = Console.ReadLine();
                orderService.DeleteOrder(s1);
            }

            else
            {
                Console.WriteLine("没有该项服务");
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            //订单1
            List <OrderDetail> orderDetails1 = new List <OrderDetail>();
            OrderDetail        od1_1         = new OrderDetail("笔", 1, "北京");

            orderDetails1.Add(od1_1);
            OrderDetail od1_2 = new OrderDetail("纸", 0.5, "上海");

            orderDetails1.Add(od1_2);
            Order order1 = new Order("123456", "张三", orderDetails1);

            //订单2
            List <OrderDetail> orderDetails2 = new List <OrderDetail>();
            OrderDetail        od2_1         = new OrderDetail("书包", 100, "北京");

            orderDetails2.Add(od2_1);
            OrderDetail od2_2 = new OrderDetail("笔记本", 4000, "上海");

            orderDetails2.Add(od2_2);
            Order order2 = new Order("234567", "张四", orderDetails2);

            List <Order> orders = new List <Order>();

            orders.Add(order1);
            orders.Add(order2);

            //订单服务
            OrderService orderService = new OrderService(orders);

            orderService.ShowAllOrders();

            //订单3
            List <OrderDetail> orderDetails3 = new List <OrderDetail>();
            OrderDetail        od3_1         = new OrderDetail("书包", 100, "北京");

            orderDetails3.Add(od3_1);
            OrderDetail od3_2 = new OrderDetail("笔记本", 4000, "上海");

            orderDetails3.Add(od3_2);
            Order order3 = new Order("345678", "张五", orderDetails3);


            //对订单的操作
            int n = 1;

            while (n > 0)
            {
                Console.WriteLine("请输入整数表示操作 1.添加订单 2.删除订单(订单号) 3.修改订单 4.查询订单(订单号) 5.查询订单(购买人) 6.查询订单(订单内的商品)0退出");
                n = int.Parse(Console.ReadLine());
                Order find = new Order();
                switch (n)
                {
                //1.添加订单
                case 1:
                {
                    string s1, s2;
                    Console.WriteLine("请输入一个新的订单");
                    Order newOrder;

                    Console.WriteLine("请输入订单号");
                    s1 = Console.ReadLine();
                    Console.WriteLine("请输入购买人");
                    s2 = Console.ReadLine();
                    Console.WriteLine("请输入购买商品的数量");
                    int goodCount = 0;
                    goodCount = int.Parse(Console.ReadLine());
                    List <OrderDetail> ods = new List <OrderDetail>();
                    string             s3, s4;
                    double             d1;
                    for (int i = 0; i < goodCount; i++)
                    {
                        Console.WriteLine("请输入商品名");
                        s3 = Console.ReadLine();
                        Console.WriteLine("请输入价格");
                        d1 = double.Parse(Console.ReadLine());
                        Console.WriteLine("请输入产地");
                        s4 = Console.ReadLine();
                        OrderDetail AOd = new OrderDetail(s3, d1, s4);
                        ods.Add(AOd);
                    }
                    newOrder = new Order(s1, s2, ods);


                    Console.WriteLine("添加第这个订单后");
                    orderService.AddOrder(newOrder);
                    Console.WriteLine();
                    orderService.ShowAllOrders();
                    Console.WriteLine();
                    break;
                }

                //2.删除订单(订单号)
                case 2:
                {
                    string s = "";

                    Console.WriteLine("请输入想删除的订单号的订单");
                    s = Console.ReadLine();

                    try
                    {
                        orderService.DelOrder(orderService.SearchByOrdNum(s));
                        orderService.ShowAllOrders();
                        Console.WriteLine("删除一个订单之后");
                        Console.WriteLine();
                    }
                    catch (CanNotFindOrder e)
                    {
                        Console.WriteLine(e.Message);
                    }

                    break;
                }

                //3.修改订单(订单名)
                case 3:
                {
                    Console.WriteLine("把订单名张三改成李四");
                    orderService.ChangeOrder("张三", "李四");
                    orderService.ShowAllOrders();
                    Console.WriteLine();
                }
                break;

                //4.查询订单(订单号)
                case 4:
                {
                    Console.WriteLine("请输入想查询的订单号的订单");
                    string sNum = "";
                    sNum = Console.ReadLine();
                    try
                    {
                        find = orderService.SearchByOrdNum(sNum);
                        find.ShowOrder();
                    }
                    catch (CanNotFindOrder e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    Console.WriteLine();
                    break;
                }

                //5.查询订单(购买人)
                case 5:
                {
                    Console.WriteLine("请输入想查询的订单号的购买人");
                    string sName = "";
                    sName = Console.ReadLine();
                    try
                    {
                        find = orderService.SearchByBuyerName(sName);
                        find.ShowOrder();
                    }
                    catch (CanNotFindOrder e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    Console.WriteLine();
                    break;
                }

                //6.查询订单(商品名)
                case 6:
                {
                    Console.WriteLine("请输入想查询的订单号的商品名");
                    string gName = "";
                    gName = Console.ReadLine();
                    try
                    {
                        find = orderService.SearchByGoodsName(gName);
                        find.ShowOrder();
                    }
                    catch (CanNotFindOrder e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    Console.WriteLine();
                    break;
                }
                }
            }

            Console.ReadKey();
        }