static void Main(string[] args) { //生成订单 //public Order(int id, string cname,params ProductDetails[] products ) //public ProductDetails(int pid, string pname, double pprice) OrderService.AddOrder(new Order(001, "客户1", new ProductDetails(01, "商品1", 67))); OrderService.AddOrder(new Order(007, "客户7", new ProductDetails(07, "商品7", 87))); OrderService.AddOrder(new Order(006, "客户6", new ProductDetails(06, "商品6", 199))); OrderService.AddOrder(new Order(003, "客户3", new ProductDetails(03, "商品3", 53), new ProductDetails(04, "商品4", 73), new ProductDetails(05, "商品5", 23))); Console.WriteLine("所有订单如下:"); var query1 = OrderService.QueryAll(); foreach (var q1 in query1) { Console.WriteLine(q1.ToString()); } //查询订单 Console.WriteLine("订单按订单号查询:"); var query2 = OrderService.QueryById(003); foreach (var q2 in query2) { Console.WriteLine(q2.ToString()); } Console.WriteLine("订单按客户名查询:"); var query3 = OrderService.QueryByClientName("客户7"); foreach (var q3 in query3) { Console.WriteLine(q3.ToString()); } Console.WriteLine("订单按商品号查询:"); var query4 = OrderService.QueryByProductId(01); foreach (var q4 in query4) { Console.WriteLine(q4.ToString()); } Console.WriteLine("订单按商品名查询:"); var query5 = OrderService.QueryByProductName("商品6"); foreach (var q5 in query5) { Console.WriteLine(q5.ToString()); } Console.WriteLine("订单按商品价格查询:"); var query6 = OrderService.QueryByProductPrice(23); foreach (var q6 in query6) { Console.WriteLine(q6.ToString()); } //更改订单 Console.WriteLine("更改订单:"); OrderService.UpdateOrder(new Order(001, "客户10", new ProductDetails(10, "商品10", 64))); Console.WriteLine("更改后的订单如下:"); var query7 = OrderService.QueryAll(); foreach (var q7 in query7) { Console.WriteLine(q7.ToString()); } //删除订单 Console.WriteLine("删除订单:"); OrderService.DeleteOrder(007); Console.WriteLine("删除后的订单如下:"); var query8 = OrderService.QueryAll(); foreach (var q8 in query8) { Console.WriteLine(q8.ToString()); } }
static void Main(string[] args) { OrderService service = new OrderService(); while (true) { Console.WriteLine("请选择功能:添加订单;删除订单;查找订单;设置订单;退出系统。"); string mod = Console.ReadLine(); switch (mod) { case "添加订单": List <OrderItem> orderItems = new List <OrderItem>(); while (true) { Console.WriteLine("请输入商品名称:"); string goodname = Console.ReadLine(); Console.WriteLine("请输入商品数量:"); int goodnum = Int32.Parse(Console.ReadLine()); Console.WriteLine("请输入商品单价"); int goodprice = Int32.Parse(Console.ReadLine()); Console.WriteLine("请输入客户名:"); string cusname = Console.ReadLine(); Console.WriteLine("是否购买其他商品:是/否"); string flag = Console.ReadLine(); if (flag == "是") { orderItems.Add(new OrderItem(goodname, goodnum, goodprice)); } else if (flag == "否") { orderItems.Add(new OrderItem(goodname, goodnum, goodprice)); service.AddOrder(cusname, orderItems); break; } } break; case "删除订单": while (true) { Console.WriteLine("请输入订单号:"); int ornum = Int32.Parse(Console.ReadLine()); service.DeleteOrder(ornum); Console.WriteLine("是否继续删除:是/否"); string flag = Console.ReadLine(); if (flag == "是") { continue; } else if (flag == "否") { break; } } break; case "查找订单": while (true) { Console.WriteLine("请输入查找模式:订单号查找/商品名查找/客户名查找"); string mode = Console.ReadLine(); if (mode == "订单号查找") { Console.WriteLine("请输入订单号:"); int num = Int32.Parse(Console.ReadLine()); Console.WriteLine(service.SearchOrderNum(num)); } else if (mode == "商品名查找") { Console.WriteLine("请输入商品名:"); string name = Console.ReadLine(); Console.WriteLine(service.SearchItemName(name)); } else if (mode == "客户名查找") { Console.WriteLine("请输入客户名:"); string name = Console.ReadLine(); Console.WriteLine(service.SearchCustomer(name)); } Console.WriteLine("是否继续查找:是/否"); string flag = Console.ReadLine(); if (flag == "是") { continue; } else if (flag == "否") { break; } } break; case "设置订单": while (true) { Console.WriteLine("请输入订单号:"); int ornum = Int32.Parse(Console.ReadLine()); Console.WriteLine("请输入修改后的订单号"); int ornum1 = Int32.Parse(Console.ReadLine()); service.SetOrderNum(ornum, ornum1); Console.WriteLine("是否继续修改:是/否"); string flag = Console.ReadLine(); if (flag == "是") { continue; } else if (flag == "否") { break; } } break; case "退出系统": break; default: Console.WriteLine("无此功能"); break; } } }