Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                OrderItem apple = new OrderItem(1, "apple", 10.0, 80);
                OrderItem egg   = new OrderItem(2, "eggs", 1.2, 200);
                OrderItem milk  = new OrderItem(3, "milk", 50, 10);

                Order order1 = new Order(1, "Customer1", new List <OrderItem> {
                    apple, egg, milk
                });
                Order order2 = new Order(2, "Customer2", new List <OrderItem> {
                    egg, milk
                });
                Order order3 = new Order(3, "Customer2", new List <OrderItem> {
                    apple, milk
                });

                OrderService os = new OrderService();
                os.AddOrder(order1);
                os.AddOrder(order2);
                os.AddOrder(order3);

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.orders;
                orders.ForEach(o => Console.WriteLine(o));
                Console.WriteLine("");

                os.Sort((o1, o2) => o1.TotalPrice.CompareTo(o2.TotalPrice));
                Console.WriteLine("GetAllOrders After sort");
                orders = os.orders;
                orders.ForEach(o => Console.WriteLine(o));
                Console.WriteLine("");

                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                orders = os.QuaryByCustomer("Customer2");
                orders.ForEach(o => Console.WriteLine(o));
                Console.WriteLine("");

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = os.QuaryByName("apple");
                orders.ForEach(o => Console.WriteLine(o));
                Console.WriteLine("");

                Console.WriteLine("Remove order(id=2) and qurey all");
                os.ReMove(2);
                orders.ForEach(o => Console.WriteLine(o));
                Console.WriteLine("");

                //os.Export(@"./orders.xml");

                //Console.WriteLine("Import from ./orders.xml");
                //OrderService os2 = new OrderService();
                //os2.Import("./orders.xml");
                //os2.Orders.ForEach(order => Console.WriteLine(order));
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }