コード例 #1
0
ファイル: MainClass.cs プロジェクト: yangwenqing/GithubKU
        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, 800);
                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);
                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                order3.AddDetails(orderDetails3);

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

                os.Export("s.xml");
                OrderService ws = new OrderService();
                ws.Import("s.xml");
                foreach (Order od in ws.QueryAllOrders())
                {
                    Console.WriteLine(od.ToString());
                }
                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=2) and qurey all");
                os.RemoveOrder(2);
                os.QueryAllOrders().ForEach(
                    od => Console.WriteLine(od));
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: WQywy/C-sharework
        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.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));



                Console.WriteLine("\n export and import orders");
                orderService.Export(@".\order.xml");
                List <Order> importedOrders = orderService.Import(@".\order.xml");
                importedOrders.ForEach(o => Console.WriteLine(o));
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Loryng/CSharpHomework
        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);
            }
        }
コード例 #5
0
ファイル: MainClass.cs プロジェクト: TWLX/2017302580163
        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);
            }
        }
コード例 #6
0
ファイル: MainClass.cs プロジェクト: lightofTC/WHUHomework
        static void Main(string[] args)
        {
            try
            {
                Customer customer1 = new Customer(1, "Customer1");
                Customer customer2 = new Customer(2, "Customer2");

                Goods Computer = new Goods(1, "Computer", 5999);
                Goods Phone    = new Goods(2, "Phone", 2399);
                Goods PSP      = new Goods(3, "PSP", 1500);

                OrderDetails orderDetails1 = new OrderDetails(1, Computer, 1);
                OrderDetails orderDetails2 = new OrderDetails(2, Phone, 2);
                OrderDetails orderDetails3 = new OrderDetails(3, PSP, 2);

                Order order1 = new Order(1, customer1);
                Order order2 = new Order(2, customer2);
                Order order3 = new Order(3, customer1);

                order1.AddDetails(orderDetails1);
                order1.AddDetails(orderDetails2);

                order2.AddDetails(orderDetails3);
                order2.AddDetails(orderDetails1);

                order3.AddDetails(orderDetails2);
                order3.AddDetails(orderDetails1);

                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("SearchOrdersByPrice");
                orders = os.SearchOrdersByPrice(10000);
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("SearchOrdersByGoodsName");
                orders = os.SearchOrderByGoodsName("PSP");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("XMLSerialize");
                os.Export(os);
                os.Import();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }