Beispiel #1
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                orders = os.QueryByCustomerName("Customer2");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = os.QueryByGoodsName("apple");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order);
                }

                Console.WriteLine("Remove order(id=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
        public static void Main()
        {
            try
            {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);//add details for order1
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                order2.AddDetails(orderDetails2); //add details for order2
                order2.AddDetails(orderDetails3); //add details for order3
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\nSort orders by Id");
                orders.Sort();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\nSort orders by Price");
                List <Order> sortorders = orders.OrderByDescending(s => s.money).ToList <Order>();
                foreach (Order order in sortorders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\nGetOrdersByCustomerName:'Customer2'");
                orders = os.QueryByCustomerName("Customer2");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\nGetOrdersByGoodsName:'eggs'");
                orders = os.QueryByGoodsName("eggs");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order);
                }

                Console.WriteLine("\nRemove order(id=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));

                Console.WriteLine("订单序列化");
                os.Export("order.xml");

                Console.WriteLine("xml反序列化");
                os.Import("order.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        public static void Main()
        {
            try
            {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk     = new Goods(1, "Milk", 69.9);
                Goods eggs     = new Goods(2, "eggs", 4.99);
                Goods apple    = new Goods(3, "apple", 5.59);
                Goods computer = new Goods(4, "computer", 1599.9);

                OrderDetail orderDetails1   = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails1_2 = new OrderDetail(1, apple, 8);
                //检验contains方法能否检查非引用的相同对象

                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                OrderDetail orderDetails4 = new OrderDetail(4, computer, 2);
                OrderDetail orderDetails5 = new OrderDetail(5, apple, 6);
                OrderDetail orderDetails6 = new OrderDetail(6, apple, 1);
                /*用于排序的实例*/
                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                Order order4 = new Order(4, customer1);
                Order order5 = new Order(5, customer2);
                Order order6 = new Order(6, customer1);


                order1.AddDetails(orderDetails1);

                /*测试contain方法可检测的类型*/

                Console.WriteLine("try to add orderdetail again");

                try
                {
                    order1.AddDetails(orderDetails1);
                }catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine("try to add a orderdetail that has the same value to orderdetail1");

                try
                {
                    order1.AddDetails(orderDetails1_2);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                //使用contains方法能够检查出并非相同引用的相同对象,因为重写了equal方法



                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);

                //order1.AddOrderDetails(orderDetails3);

                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

                order4.AddDetails(orderDetails5);
                order4.AddDetails(orderDetails2);

                order5.AddDetails(orderDetails4);
                order5.AddDetails(orderDetails5);

                order6.AddDetails(orderDetails6);

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


                Console.WriteLine("GetAllOrdersWithoutSorting");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }
                Console.WriteLine("\n\n\nSortingByOrderId");
                os.sort();
                orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\n\n\nSortingByTotalMoney");
                os.sortmoney();
                orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                //-------------------------------------------


                Console.WriteLine("\n\nGetOrdersByCustomerName:'Customer2'");
                orders = os.QueryByCustomerName("Customer2");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = os.QueryByGoodsName("apple");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order);
                }

                Console.WriteLine("\n\n\nGetOrderById=2");
                Order o = os.GetById(2);
                Console.WriteLine(o);

                Console.WriteLine("\n\n\nRemove order(id=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));

                os.Export();                                                    //将原始数据保存到orderlist.temp中
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            try
            {
                OrderService os2 = new OrderService();
                os2.import();                                                   //从orderlist.temp中读取数据
                Console.WriteLine("\n\n\nShow the imported imformation\n");
                List <Order> orderlist2 = os2.QueryAllOrders();
                foreach (Order o in orderlist2)
                {
                    Console.WriteLine(o);
                }
            }
            catch (Exception e2)
            {
                Console.WriteLine(e2.Message);
            }
            Console.ReadLine();
        }
Beispiel #4
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9f);
                Goods eggs  = new Goods(2, "eggs", 4.99f);
                Goods apple = new Goods(3, "apple", 5.59f);

                Order order1 = new Order(1, customer1);
                order1.AddDetails(new OrderDetail(apple, 8));
                order1.AddDetails(new OrderDetail(eggs, 10));
                //order1.AddDetails(new OrderDetail(eggs, 8));
                //order1.AddDetails(new OrderDetail(milk, 10));

                Order order2 = new Order(2, customer2);
                order2.AddDetails(new OrderDetail(eggs, 10));
                order2.AddDetails(new OrderDetail(milk, 10));

                Order order3 = new Order(3, customer2);
                order3.AddDetails(new OrderDetail(milk, 100));

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

                Console.WriteLine("\n GetById");
                Console.WriteLine(orderService.GetById(1));
                Console.WriteLine(orderService.GetById(5) == null);

                Console.WriteLine("\nGetAllOrders");
                List <Order> orders = orderService.QueryAll();
                orders.ForEach(o => Console.WriteLine(o));

                Console.WriteLine("\nGetOrdersByCustomerName:'Customer2'");
                orders = orderService.QueryByCustomerName("Customer2");
                orders.ForEach(o => Console.WriteLine(o));

                Console.WriteLine("\nGetOrdersByGoodsName:'eggs'");
                orders = orderService.QueryByGoodsName("eggs");
                orders.ForEach(o => Console.WriteLine(o));

                Console.WriteLine("\nGetOrdersTotalAmount:1000");
                orders = orderService.QueryByTotalAmount(1000);
                orders.ForEach(o => Console.WriteLine(o));

                Console.WriteLine("\nRemove order(id=2) and qurey all");
                orderService.RemoveOrder(2);
                orderService.QueryAll().ForEach(
                    o => Console.WriteLine(o));

                Console.WriteLine("\n order by Amount");
                orderService.Sort(
                    (o1, o2) => o2.TotalAmount.CompareTo(o1.TotalAmount));
                orderService.QueryAll().ForEach(
                    o => Console.WriteLine(o));
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #5
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                var m = from order in orders where order.Customer.Name == "Customer2" select order;
                foreach (var n in m)
                {
                    Console.WriteLine(n.ToString());
                }

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                foreach (Order order in orders)
                {
                    var mm = from orderDetail in order.Details
                             where orderDetail.Goods.Name == "apple"
                             select orderDetail;
                    foreach (var n in mm)
                    {
                        if (n != null)
                        {
                            Console.WriteLine(order.ToString());
                        }
                    }
                }

                //查询订单金额大于1万元的订单
                Console.WriteLine("GetOrdersWithPriceMoreThan'10000'");
                m = from order in orders where order.getPrice() >= 10000 select order;
                foreach (var n in m)
                {
                    Console.WriteLine(n.ToString());
                }

                Console.WriteLine("Remove order(id=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #6
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1", "13512345678");
                Customer customer2 = new Customer(2, "Customer2", "15912345678");

                //Goods milk = new Goods(1, "Milk", 69.9);
                //Goods eggs = new Goods(2, "eggs", 4.99);
                //Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail("1", "apple", 800, 5.59);
                OrderDetail orderDetails2 = new OrderDetail("2", "eggs", 2, 4.99);
                OrderDetail orderDetails3 = new OrderDetail("3", "milk", 1, 69.9);

                Order order1 = new Order("20180728001", customer1);
                Order order2 = new Order("20180501007", customer2);
                Order order3 = new Order("20181111213", customer2);
                order1.AddDetails(orderDetails1);
                //order1.AddDetails(orderDetails2);
                //order1.AddDetails(orderDetails3);

                //order1.AddOrderDetails(orderDetails3);

                order2.AddDetails(orderDetails2);
                //order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                orders = os.QueryByCustomerName("Customer2");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = os.QueryByGoodsName("apple");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                //Console.WriteLine("GetOrdersByPrice:1000");
                //orders = os.QueryByPrice(1000);
                //foreach (Order od in orders)
                //    Console.WriteLine(od.ToString());

                Console.WriteLine("Remove order(id=20180501007) and qurey all");
                os.RemoveOrder("20180501007");
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #7
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                /*OrderDetail orderDetails4 = new OrderDetail(1, apple, 8);
                 *
                 * Console.WriteLine(orderDetails1.Equals(orderDetails4));*/

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine(" \nGetOrdersByCustomerName:'Customer2'");
                orders = os.QueryByCustomerName("Customer2");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("\nGetOrdersByGoodsName:'apple'");
                orders = os.QueryByGoodsName("apple");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order);
                }

                Console.WriteLine("\nRemove order(id=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));

                //XML序列化
                XmlSerializer xmlser      = new XmlSerializer(typeof(OrderService[]));
                String        xmlFileName = "s.xml";
                OrderService.XmlSerialize(xmlser, xmlFileName, os);

                //显示XML文本
                string xml = File.ReadAllText(xmlFileName);
                Console.WriteLine(xml);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            try
            {
                Customer customer1 = new Customer(1, "张三");
                Customer customer2 = new Customer(2, "赵四");

                Goods milk  = new Goods(1, "牛奶", 6.9);
                Goods eggs  = new Goods(2, "鸡蛋", 4.99);
                Goods apple = new Goods(3, "苹果", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddOrderDetail(orderDetails1);
                order1.AddOrderDetail(orderDetails2);
                order1.AddOrderDetail(orderDetails3);
                order2.AddOrderDetail(orderDetails2);
                order2.AddOrderDetail(orderDetails3);
                order3.AddOrderDetail(orderDetails3);

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

                Console.WriteLine("得到所有订单");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("按照顾客姓名查询:赵四");
                orders = os.GetOrdersByCustomerName("赵四");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("按照商品查询:'苹果'");
                orders = os.QueryOrdersByGoodsName("苹果");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("移除订单(2号)并查询订单");
                os.RemoveOrder(2);
                orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                os.Export();
                os.Import();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #9
0
        public static void Main()
        {
            try
            {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddOrderDetail(orderDetails1);
                order1.AddOrderDetail(orderDetails2);
                order1.AddOrderDetail(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddOrderDetail(orderDetails2);
                order2.AddOrderDetail(orderDetails3);
                order3.AddOrderDetail(orderDetails3);

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

                Order[] Myorders = { order1, order2, order3 };

                var query = from BigOrder in Myorders
                            where BigOrder.OrderId > 10000
                            select BigOrder;

                foreach (var m in query)
                {
                    Console.WriteLine(m);
                }


                Console.WriteLine("GetAllOrders");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                orders = os.GetOrdersByCustomerName("Customer2");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = os.QueryOrdersByGoodsName("apple");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");

                Console.WriteLine("Remove order(id=2) and qurey all");
                os.RemoveOrder(2);
                orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                Console.WriteLine("");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #10
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, apple, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3, milk, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                //order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order3.AddDetails(orderDetails2);
                //order3.AddDetails(orderDetails3);
                order2.AddDetails(orderDetails3);


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

                OrderService osnew = XmlImport2Order(); //Read data of order system from existing Xml configuration file
                //OrderService osnew = os;              //Use the data created manually

                Console.WriteLine("GetAllOrdersInIDAscendingOrder");
                List <Order> orders = osnew.QueryAllOrders();
                orders.Sort();
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }


                Console.WriteLine("GetAllOrdersInSumDecendingOrder");
                foreach (Order order in orders)
                {
                    order.CalculateSum();
                }

                foreach (Order order in orders.OrderByDescending(i => i.sum))
                {
                    Console.WriteLine(order.ToString());
                    Console.WriteLine("\tsum = " + order.sum.ToString());
                }


                Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                orders = osnew.QueryByCustomerName("Customer2");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order.ToString());
                }

                Console.WriteLine("GetOrdersByGoodsName:'apple'");
                orders = osnew.QueryByGoodsName("apple");
                foreach (Order order in orders)
                {
                    Console.WriteLine(order);
                }

                Console.WriteLine("Remove order(id=2) and qurey all");
                osnew.RemoveOrder(2);
                osnew.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #11
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer(1, "宝多六花");
                Customer customer2 = new Customer(2, "新条茜");

                Goods milk  = new Goods(1, "牛奶", 69.9);
                Goods eggs  = new Goods(2, "鸡蛋", 4.99);
                Goods apple = new Goods(3, "苹果", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1, milk, 8);
                OrderDetail orderDetails2 = new OrderDetail(2, eggs, 2333);
                OrderDetail orderDetails3 = new OrderDetail(3, apple, 1);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                Console.WriteLine("获取所有订单:" + "\n");
                List <Order> orders = os.QueryAllOrders();
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString() + "\n");
                }

                string name1 = "宝多六花";
                Console.WriteLine("通过客户姓名查询订单:'宝多六花'");
                //orders = os.QueryByCustomerName("宝多六花");
                var m = from n1 in orders where n1.Customer.Name == name1 select n1;
                foreach (var od in m)
                {
                    Console.WriteLine(od.ToString() + "\n");
                }

                List <OrderDetail> detail = new List <OrderDetail> {
                    orderDetails1, orderDetails2, orderDetails3
                };
                string good1 = "牛奶";
                Console.WriteLine("通过商品查询订单:'牛奶'");
                //orders = os.QueryByGoodsName("牛奶");
                var n = from n2 in detail where n2.Goods.Name == good1 select n2;
                foreach (var od in n)
                {
                    Console.WriteLine(od.ToString() + "\n");
                }

                Console.WriteLine("查询订单金额大于1w元的订单:");
                var w = from x in detail where x.Goods.Price * x.Quantity > 10000 select x;
                foreach (var od in w)
                {
                    Console.WriteLine(od.ToString() + "\n");
                }


                Console.WriteLine("删除订单(ID=2)和Query全部:");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));

                Console.WriteLine();
                bool b1 = os.Export(orders);
                bool b2 = os.Import("serialiable.xml");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #12
0
        public static void Main()
        {
            try {
                Customer customer1 = new Customer("13288654452", "Customer1");
                Customer customer2 = new Customer("15644832267", "Customer2");

                Goods milk  = new Goods(1, "Milk", 69.9);
                Goods eggs  = new Goods(2, "eggs", 4.99);
                Goods apple = new Goods(3, "apple", 5.59);

                OrderDetail orderDetails1 = new OrderDetail(1.ToString(), apple, 800);
                OrderDetail orderDetails2 = new OrderDetail(2.ToString(), eggs, 2);
                OrderDetail orderDetails3 = new OrderDetail(3.ToString(), milk, 1);

                Order order1 = new Order(customer1);
                Order order2 = new Order(customer2);
                Order order3 = new Order(customer2);
                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);
                order1.AddDetails(orderDetails3);
                //order1.AddOrderDetails(orderDetails3);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                //Console.WriteLine("GetAllOrders");
                //List<Order> orders = os.QueryAllOrders();
                //foreach (Order od in orders)
                //    Console.WriteLine(od.ToString());

                //Console.WriteLine("GetOrdersByCustomerName:'Customer2'");
                //orders = os.QueryByCustomerName("Customer2");
                //foreach (Order od in orders)
                //    Console.WriteLine(od.ToString());

                //Console.WriteLine("GetOrdersByGoodsName:'apple'");
                ////orders = os.QueryByGoodsName("apple");
                ////foreach (Order od in orders)
                ////    Console.WriteLine(od.ToString());
                //os.QueryByGoodsName("apple").ForEach(
                //    od => Console.WriteLine(od));

                //Console.WriteLine("GetOrdersByPrice:1000");
                //orders = os.QueryByPrice(1000);
                //foreach (Order od in orders)
                //    Console.WriteLine(od.ToString());

                //Console.WriteLine("Remove order(id=2) and qurey all");
                os.RemoveOrder(2.ToString());
                //os.QueryAllOrders().ForEach(
                //    od => Console.WriteLine(od));

                //XML序列化
                XmlSerializer xmlser      = new XmlSerializer(typeof(List <Order>));
                string        xmlFileName = "s.xml";
                os.XmlSerializeExport(xmlser, xmlFileName);

                //XML反序列化
                os.XmlSerializeImport(xmlser, xmlFileName);
                Console.WriteLine("GetAllOrders");
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));

                Console.ReadKey();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }