示例#1
0
        static void Main(string[] args)
        {
            OrderService orderService = new OrderService();

            orderService.AddOrder("001");
            orderService.AddOrder("002");
            orderService.AddOrder("003");
            orderService.AddOrder("004");
            orderService.AddOrder("005");
            //删除订单
            try
            {
                orderService.DelOrder("002");
                orderService.DelOrder("004");
                orderService.DelOrder("003");
                orderService.DelOrder("006");  //出现异常
            }
            catch (MyException e)
            {
                Console.WriteLine("删除订单失败,出错种类" + e.getId());
            }

            //修改订单
            try
            {
                orderService.ModOrder("003");
                orderService.ModOrder("005");
                orderService.ModOrder("006");   //出现异常
            }
            catch (MyException e)
            {
                Console.WriteLine("修改订单失败,出错种类" + e.getId());
            }

            orderService.FindOrderByNums("005");
            orderService.FindOrderByName("Vermouth");
            orderService.FindOrderByGoods("goodsA");

            Console.ReadKey();
        }
示例#2
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();
        }