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, "15622586649"); Order order2 = new Order(2, customer2, "15622586649"); Order order3 = new Order(3, customer2, "15622586649"); 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=2) and qurey all"); os.RemoveOrder(2); os.QueryAllOrders().ForEach( od => Console.WriteLine(od)); } 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.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); } }
public void Export(OrderService order) { XmlSerializer xmlser = new XmlSerializer(typeof(OrderService[])); XmlSerialize(xmlser, xmlFileName, order); }
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); } }
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, "张三"); 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, "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); } Console.ReadLine(); }
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); } }