示例#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);
            }
        }
示例#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);
            }
        }
示例#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();
        }
示例#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);
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }
示例#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);

                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);
            }
        }