public OrderDetails(int seri, Goods gs, int Quantity) { this.serialNo = seri; this.goods = gs; this.Quantity = Quantity; }
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); 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("Remove order(id=2) and qurey all"); os.RemoveOrder(2); os.QueryAllOrders().ForEach( od => Console.WriteLine(od)); } catch (Exception e) { Console.WriteLine(e.Message); } }
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'"); List <Order> orders2 = os.QueryByAmount(10000); foreach (Order od in orders2) { Console.WriteLine(od.ToString()); } Console.WriteLine("___________序列化___和____反序列化__________"); 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(); }
static void Main(string[] args) { string Name; bool T = true; int index = 0, Number = 0; OrderService os = new OrderService(); while (T) { try { Console.WriteLine("!!!!!!!!!! 本店只有 辣条 七个小矮人 快乐水 !!!!!!!!!!! \n\n ============== 请选择您要功能:\n ============== 1.添加订单 2.删除订单 3.查询 4.显示订单 ============== \n ============== 其他键退出"); int select = Convert.ToInt32(Console.ReadLine()); if (select == 1) { index++; //创建一个订单 Order order1 = new Order(); order1.OrderId = index; Console.WriteLine("\n################## 客户: ##################"); order1.Client = Console.ReadLine(); //添加明细 int index1 = 0; bool T1 = true; while (T1) { try { Console.WriteLine("\n请选择:\n——————————1.添加明细 ——————————\n——————————2.完成 ——————————"); int select1 = Convert.ToInt32(Console.ReadLine()); if (select1 == 1) { index1++; Console.WriteLine("名称:"); Name = Console.ReadLine(); Goods goods = new Goods(Name); Console.WriteLine("数量:"); Number = Convert.ToInt32(Console.ReadLine()); OrderDetails orderDetails = new OrderDetails(goods, Number); orderDetails.DetailsNumber = index1; order1.AddDetails(orderDetails); Console.WriteLine("\n-*-*-*-*- 完成 -*-*-*-*-\n"); } else if (select1 == 2) { T1 = false; } } catch { Console.WriteLine("\n ******请正确输入!******"); } } //通过OrderService加入OrderList os.AddOrder(order1); } else if (select == 2) { Console.WriteLine("\n\n ################## 2.)删除订单: ##################\n——————1.按照客户名删除订单——————\n——————2.按照订单号删除订单——————\n——————其他返回\n"); int sd = Convert.ToInt32(Console.ReadLine()); if (sd == 1) { Console.WriteLine("\n2.按照客户名删除订单"); Console.WriteLine("需要删除掉订单的客户:"); string client = Console.ReadLine(); os.DeleteByCliend(client); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } else if (sd == 2) { Console.WriteLine("\n2.按照订单号删除订单"); Console.WriteLine("需要删除掉订单的订单号:"); int client = Convert.ToInt32(Console.ReadLine()); os.DeleteById(client); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } } else if (select == 3) { Console.WriteLine("\n\n ################## 3.)查询订单:(请选择) ##################\n——————1.按照客户名查询订单——————\n——————2.按照订单号查询订单——————\n——————3.查询小于指定金额的订单——————\n——————4.按照商品名查询订单——————\n——————其他返回\n"); int sd = Convert.ToInt32(Console.ReadLine()); if (sd == 1) { Console.WriteLine("\n2.按照客户名查询订单"); Console.WriteLine("需要查询订单的客户:"); string client = Console.ReadLine(); os.FindByName(client); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } else if (sd == 2) { Console.WriteLine("\n2.按照订单号查询订单"); Console.WriteLine("需要查询订单的订单号:"); int client = Convert.ToInt32(Console.ReadLine()); os.FindByID(client); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } else if (sd == 3) { Console.WriteLine("\n3.查询小于指定金额的订单"); Console.WriteLine("输入您的金额:"); double client = Convert.ToDouble(Console.ReadLine()); os.FindByTotal(client); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } else if (sd == 4) { Console.WriteLine("\n2.按照商品名称查询订单"); Console.WriteLine("需要查询商品:"); string goodsName = Console.ReadLine(); os.FindByGN(goodsName); Console.WriteLine("-*-*-*-*- 完成 -*-*-*-*-\n"); } } else if (select == 4) { os.ShowForUser(); Console.WriteLine("\n***完成*** \n "); } else { Console.WriteLine("*****谢谢使用!*****"); break; } } catch { Console.WriteLine("\n ******请正确输入!******"); } } }
public OrderDetails(Goods goods, int number) { this.CommodityNumber = number; this.good = goods; this.TotalPrice = this.good.Price * this.CommodityNumber; }