public void TestMethod1() { Customer customer1 = new Customer(1, "Customer1"); Goods apple = new Goods(1, "apple", 5.59); OrderDetail orderDetails1 = new OrderDetail(1, apple, 800); Order order1 = new Order(1, customer1); order1.AddDetails(orderDetails1); OrderService os = new OrderService(); os.AddOrder(order1); Assert.IsTrue(os.Export("s.xml")); }
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); 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)); os.Export("orders.xml"); } catch (Exception e) { Console.WriteLine(e.Message); } }
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); } }
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(); }
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); } }
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); } }
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); } }
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); } }