Exemplo n.º 1
0
 public OrderItem(Goods Good, int Count)
 {
     this.Good  = Good;
     this.Count = Count;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //五种货物
            Goods apple  = new Goods("apple", 10.8);
            Goods banana = new Goods("banana", 22.8);
            Goods water  = new Goods("water", 9.8);
            Goods cake   = new Goods("cake", 49.99);
            Goods pencil = new Goods("pencil", 5.0);
            //四位顾客
            Customer Mike  = new Customer("Mike", "New York");
            Customer Ammy  = new Customer("Ammy", "London");
            Customer LiHua = new Customer("LiHua", "Shanghai");
            Customer Koya  = new Customer("Koya", "Tokyo");

            OrderService os = new OrderService();

            Order order1 = new Order(1, Mike);

            order1.AddGoods(apple, 5);
            order1.AddGoods(banana, 3);
            order1.AddGoods(cake, 1);
            os.AddOrder(order1);

            Order order2 = new Order(2, Koya);

            order2.AddGoods(apple, 5);
            order2.AddGoods(pencil, 6);
            order2.AddGoods(water, 8);
            os.AddOrder(order2);

            Order order3 = new Order(3, LiHua);

            order3.AddGoods(pencil, 3);
            // order3.AddGoods(pencil, 4);     会抛异常:“货品添加重复”
            order3.AddGoods(cake, 1);
            order3.AddGoods(water, 2);
            os.AddOrder(order3);

            Order order4 = new Order(4, Ammy);

            order4.AddGoods(apple, 7);
            order4.AddGoods(pencil, 8);
            order4.AddGoods(water, 3);
            os.AddOrder(order4);

            Order order5 = new Order(5, Ammy);

            order5.AddGoods(cake, 2);
            order5.AddGoods(pencil, 15);
            order5.AddGoods(water, 3);
            os.AddOrder(order5);

            Console.WriteLine("---查询所有账单,按照消费金额排序---\n");
            os.QueryOrders();
            Console.WriteLine("---查询Ammy的所有订单---\n");
            os.QueryOrderByCustomer(Ammy);
            Console.WriteLine("---将账单按照账单号排序---\n");
            os.Sort((a, b) => a.ID - b.ID);
            os.display();
            Console.WriteLine("---将账单1的收件人改为李华---\n");
            os.ChangeOrderCustomerAndAddress(1, LiHua);
            os.QueryOrder(1);
            Console.WriteLine("---删除所有李华的订单---\n");
            os.DeleteCustomerOrder(LiHua);
            os.display();
            Console.WriteLine("---四号订单现在的货物是---\n");
            os.QueryOrder(4);
            Console.WriteLine("---货物更改成100个苹果后---\n");
            List <OrderItem> list = new List <OrderItem>();
            OrderItem        oi   = new OrderItem(apple, 100);

            list.Add(oi);
            os.ChangeOrderItem(4, list);
            os.QueryOrder(4);
            Console.ReadKey();
        }