public void Init() { service = new OrderService(); }
static void Main(string[] args) { //-------------------客户---------------------- Customer JackMa = new Customer("Jack Ma"); Customer LeiJun = new Customer("Lei Jun"); //-------------------客户---------------------- //-------------------商品---------------------- Product hdnoodle = new Product("hd noodles", 5); Product dumpling = new Product("dumpling", 8); Product baozi = new Product("bao zi", 2); Product hamburger = new Product("hamburger", 10); Product xiaomi = new Product("xiao mi", 3000); //-------------------商品---------------------- //-------------------测试代码-------------------- Console.WriteLine(baozi);//测试商品类ToString //----------------创立订单和订单项-------------- Order o1 = new Order(JackMa); Order o2 = new Order(LeiJun); OrderDetails o_1 = new OrderDetails(baozi, 100); OrderDetails o_2 = new OrderDetails(hamburger, 50); OrderDetails o_3 = new OrderDetails(dumpling, 30); OrderDetails o_4 = new OrderDetails(hdnoodle, 100); OrderDetails o_5 = new OrderDetails(dumpling, 200); //----------------创立订单和订单项-------------- //----------------增删改订单和订单项-------------- OrderService.AddOrder(o1); OrderService.AddOrder(o1); OrderService.AddOrderitem(o1, o_1); OrderService.AddOrderitem(o1, o_2); OrderService.AddOrderitem(o1, o_2); Console.WriteLine(o1); OrderService.AddOrder(o2); OrderService.AddOrderitem(o2, o_4); OrderService.AddOrderitem(o2, o_5); OrderService.DeleteOrderitem(o1, o_2); OrderService.ChangeOrderitme(o1, o_1, o_3); OrderService.AddOrderitem(o2, o_1); //----------------增删改订单和订单项-------------- //----------------对全部订单排序输出-------------- OrderService.Disp_order(); Console.WriteLine("Sort by Id lambda"); OrderService.blanket_order.Sort((p1, p2) => p1.Id - p2.Id); foreach (var item in OrderService.blanket_order) { Console.WriteLine(item); } //----------------对全部订单排序输出-------------- Console.WriteLine($"Is o1 equals to o2?: {o1.Equals(o2)}");//测试equal(); //---------------按指定信息查找订单--------------- Console.WriteLine("以下输出id为2的订单:\n"); OrderService.GetOrderbyid(2); Console.WriteLine("以下输出含有dumplings的订单:\n"); OrderService.GetOrder(dumpling); Console.WriteLine("以下输出含有xiaomi的订单:\n"); OrderService.GetOrder(xiaomi); Console.WriteLine("以下输出leijun的订单:\n"); OrderService.GetOrder("Lei Jun"); Console.WriteLine("以下输出金额2300的订单:\n"); OrderService.GetOrder(2300); //---------------按指定信息查找订单--------------- OrderService.export(); OrderService.import(); }
static void Main(string[] args) { using (var db = new Db()) { 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); } /* * db.goods.Add(milk); * db.goods.Add(eggs); * db.goods.Add(apple); * * db.customer.Add(customer1); * db.customer.Add(customer2); * * db.order.Add(order1); * db.order.Add(order2); * db.order.Add(order3); * * db.SaveChanges();*/ } }