static void Main(string[] args)
        {
            try
            {
                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, 1000);


                Order order1 = new Order(1, "张三");
                Order order2 = new Order(2, "李四");
                Order order3 = new Order(3, "王五");

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

                order2.AddDetails(orderDetails2);
                order2.AddDetails(orderDetails3);
                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("GetOrdersByCustomerName:'李四'");
                orders = os.QueryByCustomerName("李四");
                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("GetOrdersByOrderID:' order2'");
                orders = os.QueryByOrderID("2");
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }
                //查询订单进而超过某一个值的订单
                Console.WriteLine("GetOrdersByAmount:'over 10000'");
                orders = os.QueryByAmount(10000);
                foreach (Order od in orders)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("___________序列化___和____反序列化__________");

                os.Export(@"D:\orderService.xml");
                List <Order> ods = OrderService.Import(@"D:\orderService.xml").QueryAllOrders();
                foreach (Order od in ods)
                {
                    Console.WriteLine(od.ToString());
                }

                Console.WriteLine("END");
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Order order1 = new Order("2018100601", "陈1", "陈志鹏", "月饼", 2100, 100);

            //在控制台输出订单 1 的所有信息
            Console.WriteLine(order1.ToString());
            Console.WriteLine();

            Order order2 = new Order("2018100602", "陈2", "陈志鹏", "方便面", 1000, 1000);
            Order order3 = new Order("2018100603", "陈3", "陈志鹏", "苹果", 1000, 2530);
            Order order4 = new Order("2018100604", "陈4", "陈志鹏", "草莓", 2045, 400);

            OrderService orderService = new OrderService();

            orderService.Export();       //将所有订单(此时还未添加订单)序列化为XML文件,并在控制台输出
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            orderService.Import(order1);            //从XML文件中载入订单1
            Console.WriteLine();

            orderService.AddOrder(order2);          //添加订单
            orderService.AddOrder(order3);
            orderService.AddOrder(order4);

            Console.WriteLine(orderService.GetOrderCounts());             //输出现在订单表中订单的个数
            Console.WriteLine();

            orderService.Export();       //将所有订单序列化为XML文件,并在控制台输出
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Order order5 = new Order("2018102205", "陈5", "陈志鹏", "iPhone", 3999, 400);

            orderService.Import(order5);                 //从XML文件中载入订单5
            Console.WriteLine();

            orderService.AlterOrderNumber(order1, "2018100701"); //修改订单 1 的订单号
            orderService.AlterOrderGoodsName(order1, "香肠", 10);  //修改订单 1 的商品名称及商品单价
            orderService.AlterOrderClient(order1, "陈一");         //修改订单 1 的客户名称
            orderService.AlterOrderGoodsCounts(order1, 20);      //修改订单 1 的订购的商品数量
            Console.WriteLine();

            //在控制台输出现在订单 1 的所有信息
            Console.WriteLine(order1.ToString());
            Console.WriteLine();

            orderService.SearchOrderByOrderNumber("2018100603");  //通过商品名称查询订单信息,并在控制台输出所查询订单的所有信息
            Console.WriteLine();

            orderService.SearchOrderByGoodsName("草莓");  //通过商品名称查询订单信息,并在控制台输出所查询订单的所有信息
            Console.WriteLine();

            orderService.SearchOrderByOrderClient("陈2"); //通过商品名称查询订单信息,并在控制台输出所查询订单的所有信息
            Console.WriteLine();

            Console.WriteLine("查询订单金额大于一万的订单,并按金额升序排列");
            orderService.SearchOrderByOrderTotalPriceA(10000);
            Console.WriteLine();

            Console.WriteLine("查询订单金额大于一万的订单,并按金额降序排列");
            orderService.SearchOrderByOrderTotalPriceD(10000);
            Console.WriteLine();

            orderService.DeleteOrder(order3);                 //删除订单 3
            Console.WriteLine(orderService.GetOrderCounts()); //输出现在订单表中订单的个数
            Console.WriteLine();

            orderService.DeleteOrder(order1);                 //删除订单 1
            Console.WriteLine(orderService.GetOrderCounts()); //输出现在订单表中订单的个数
            Console.WriteLine();

            Console.WriteLine(orderService.SearchOrderByOrderNumber("2018100603"));
            Console.WriteLine();
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     OrderService.CreateOrderFromXml("../../Orders.xml");
     Menu.OrderMenu();
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            #region //示例(订单明细)条目,四个测试条目
            //OrderDetails od1 = new OrderDetails
            //{
            //    Brand = Products.Apple,
            //    ProductsNum = 2,
            //    Price=8800,
            //};
            //OrderDetails od2 = new OrderDetails
            //{
            //    Brand = Products.HUAWEI,
            //    ProductsNum = 1,
            //    Price=3200,
            //};
            //OrderDetails od3 = new OrderDetails
            //{
            //    Brand = Products.OPPO,
            //    ProductsNum = 3,
            //    Price=3500,
            //};
            //OrderDetails od4 = new OrderDetails
            //{
            //    Brand = Products.SAMSUNG,
            //    ProductsNum = 2,
            //    Price=3800,
            //};
            #endregion

            #region //示例订单
            Order order1 = new Order
            {
                ClientName = "Bob",
                PhoneNum   = "+86-10-87654321",
            };
            Order order2 = new Order
            {
                ClientName = "Tom",
                PhoneNum   = "+86-10-87654321",
            };
            Order order3 = new Order
            {
                ClientName = "Alice",
                PhoneNum   = "+86-10-87654321",
            }; Order order4 = new Order
            {
                ClientName = "Alex",
                PhoneNum   = "+86-10-87654321",
            };
            #endregion

            #region//添加订单明细
            //直接add时创建对象
            //order1.orderDetails = new List<OrderDetails>();
            order1.AddOrderDetails(new OrderDetail(Products.Apple, 3, 8800));
            order1.AddOrderDetails(new OrderDetail(Products.HUAWEI, 2, 2800));

            // order2.orderDetails = new List<OrderDetails>();
            order2.AddOrderDetails(new OrderDetail(Products.OPPO, 1, 3200));
            order2.AddOrderDetails(new OrderDetail(Products.SAMSUNG, 4, 4800));

            //order3.orderDetails = new List<OrderDetails>();
            order3.AddOrderDetails(new OrderDetail(Products.vivo, 1, 3000));

            //order4.orderDetails = new List<OrderDetails>();
            order4.AddOrderDetails(new OrderDetail(Products.XIAOMI, 10, 2500));
            #endregion

            //订单服务,添加了两个订单
            // OrderService.orders = new List<Order>();
            OrderService orderService = new OrderService();
            orderService.AddOrder(order1);
            orderService.AddOrder(order2);
            orderService.AddOrder(order3);
            orderService.AddOrder(order4);

            //orderService.Export(@"D:\orderService.xml");
            orderService.xslT("D:\\orderService");
            // OrderService os= OrderService.Import(@"D:\orderService.xml");
            //try
            //{
            //    orderService.FindOrderByOrderNum("20181004001");


            //    orderService.FindOrderByClientName("Tom");

            //    orderService.FindOrderByProductBrand(Products.SAMSUNG);

            //    orderService.FindLargeOrder();
            //}
            //catch (DataException e)
            //{
            //    Console.WriteLine(e.Message);
            //}
        }
Beispiel #5
0
 static void Main(string[] args)
 {
     OrderService.data = new List <Order>();
     OrderService A = new OrderService();
 }
Beispiel #6
0
 static void Main(string[] args)
 {
     OrderService.Import("../../MyOrder.xml");
     Menu.OrderMenu();
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to use the order system!");
            OrderService orderservice = new OrderService();

            OrderDetail[] orderDetail1 = { new OrderDetail("A", 5, 20), new OrderDetail("B", 6, 30), new OrderDetail("C", 7, 40) };
            Order         order1       = new Order(1, "Frank", orderDetail1);

            orderservice.orders.Add(order1);
            orderservice.showOrder();
            Console.WriteLine("Add");
            OrderDetail[] orderDetail2 = { new OrderDetail("A", 5, 30), new OrderDetail("B", 6, 40) };
            Order         order2       = new Order(2, "Jack", orderDetail2);

            orderservice.orders.Add(order2);
            orderservice.showOrder();

            string xmlFileName = "ordersXml.xml";

            orderservice.Export(xmlFileName, orderservice.orders);
            object obj = orderservice.Import(xmlFileName);
            string xml = File.ReadAllText(xmlFileName);

            Console.WriteLine(xml);

            //Console.WriteLine("Change and please input the number of order you need to change: ");
            //try
            //{
            //    string c = Console.ReadLine();
            //    int changeNumber = int.Parse(c);
            //    OrderDetail[] orderDetail3 = { new OrderDetail("A", 50, 50), new OrderDetail("C", 60, 60) };
            //    OrderService.changeOrders(changeNumber, 3, "William", orderDetail3);
            //    OrderService.showOrder();
            //}
            //catch (MyOrderException e)
            //{
            //    Console.WriteLine("Fail to change!" + e.getInformation());
            //}
            //Console.WriteLine("Remove and please input the number of order you need to remove: ");
            //try
            //{
            //    string r = Console.ReadLine();
            //    int removeNumber = int.Parse(r);
            //    OrderService.removeOrder(removeNumber);
            //    OrderService.showOrder();
            //}
            //catch (MyOrderException e)
            //{
            //    Console.WriteLine("Fail to remove!" + e.getInformation());
            //}
            //Console.WriteLine("Find by orderNumber: ");
            //try
            //{
            //    string fo = Console.ReadLine();
            //    int findNumber = int.Parse(fo);
            //    OrderService.findOrderByOrderNumber(findNumber);
            //}
            //catch (MyOrderException e)
            //{
            //    Console.WriteLine("Fail to find!" + e.getInformation());
            //}
            ////如上同理,不再多做异常信息输出
            //Console.WriteLine("Find by goodName: ");
            //OrderService.findOrderByGoodName("A");
            //Console.WriteLine("Find by guestName: ");
            //string fg = Console.ReadLine();
            //OrderService.findOrderByGuestName(fg);
            Console.Write("Done!!!");
        }