static void Main(string[] args) { Order[] originList = { new Order("EDX541253", "Andy Lau"), new Order("DFDSC34234", "Jack Bree"), new Order("LLP234234", "Charie Do") }; originList[0].CreateNewEntry("可乐", 1500, 3.5); originList[0].CreateNewEntry("鸡翅", 552, 4.5); originList[0].CreateNewEntry("鸡腿", 300, 6); originList[1].CreateNewEntry("凳子", 25, 32.5); originList[1].CreateNewEntry("公鸡", 20, 53); originList[2].CreateNewEntry("鸡腿", 330, 6.6); originList[2].CreateNewEntry("冰棍", 560, 3.5); originList[2].CreateNewEntry("香蕉", 10000, 1.5); foreach (Order order in originList) { orderservice.AddOrder(order); } Console.WriteLine("原始订单表:"); orderservice.ShowOrder(); Console.WriteLine("输入1添加订单,2删除订单,3修改订单,4查询订单,5打印订单表,6序列化订单表,7载入订单,0退出"); int A; bool valid = int.TryParse(Console.ReadLine(), out A); while (!valid || A < 0 || A > 7) { Console.Write("输入错误,请输入0 或 1 或 2 或 3 或 4 或 5 : "); valid = int.TryParse(Console.ReadLine(), out A); } while (A != 0) { switch (A) { case 1: AddOrder(); break; case 2: RemoveOrder(); break; case 3: orderservice.ShowOrder(); Console.Write("请输入要修改的订单序号(如果要删除序列表的第一个订单即订单1就输入1:"); int orderNum; bool valid1 = int.TryParse(Console.ReadLine(), out orderNum); while (!valid1 || A > orderservice.numOfOrder) { Console.Write($"输入错误,请输入小于等于{orderservice.numOfOrder}整型数字:"); valid1 = int.TryParse(Console.ReadLine(), out orderNum); } Order chosenOrder = orderservice.orderList[orderNum - 1]; AlterOrder(chosenOrder); break; case 4: Console.WriteLine("输入1按照订单号查找,输入2按照客户姓名查找,输入3按照商品名称查找,输入4查询订单金额大于1万元的订单,0退出"); int A1; bool valid2 = int.TryParse(Console.ReadLine(), out A1); while (!valid2 || A1 < 0 || A1 > 4) { Console.Write("输入错误,请输入0 或 1 或 2 或 3 : "); valid2 = int.TryParse(Console.ReadLine(), out A1); } switch (A1) { case 1: Console.Write("\n输入要查询的订单号(可以查询出包含该字符串的订单,如 ED 可以查询出EDX541253: "); string numOfOrder = Console.ReadLine(); Console.WriteLine(" 查询结果:"); orderservice.FindByNum(numOfOrder); break; case 2: Console.Write("\n输入要查询的客户姓名(可以查询出包含该字符串的订单,如 And 可以查询出Andy Lau:"); string name = Console.ReadLine(); Console.WriteLine(" 查询结果:"); orderservice.FindByName(name); break; case 3: Console.Write("\n输入要查询的商品名称(可以查询出包含该字符串的订单,如 香 可以查询出香蕉:"); string kind = Console.ReadLine(); Console.WriteLine(" 查询结果:"); orderservice.FindByKind(kind); break; case 4: Console.WriteLine(" 查询结果:"); orderservice.FindTpMoreThan1000(); break; default: break; } break; case 5: orderservice.ShowOrder(); break; case 6: orderservice.Export(); break; case 7: orderservice = orderservice.Import(); break; default: break; } Console.WriteLine("输入1添加订单,2删除订单,3修改订单,4查询订单,5打印订单表,6序列化订单表,7载入订单,0退出"); valid = int.TryParse(Console.ReadLine(), out A); while (!valid) { Console.Write("输入错误,请输入整型数字:"); valid = int.TryParse(Console.ReadLine(), out A); } } }
private static void HandleOptions() { OrderService orderService = new OrderService(); while (true) { Console.WriteLine(" 菜 单"); Console.WriteLine("1、添加订单"); Console.WriteLine("2、删除订单"); Console.WriteLine("3、修改订单"); Console.WriteLine("4、查询订单"); Console.WriteLine("5、显示所有订单"); Console.WriteLine("6、序列化为xml文件"); Console.WriteLine("7、从xml文件载入订单"); Console.WriteLine("8、退出系统"); Console.Write("请选择需要进行的操作:"); try { int option = int.Parse(Console.ReadLine()); XmlSerializer xmlSer = new XmlSerializer(typeof(List <Order>)); string xmlFileName = "orders.xml"; switch (option) { case 1: orderService.Add(); break; case 2: orderService.Remove(); break; case 3: orderService.Modify(); break; case 4: orderService.Query(); break; case 5: orderService.Show(); break; case 6: orderService.Export(xmlSer, xmlFileName); break; case 7: orderService.Import(xmlSer, xmlFileName); break; case 8: return; default: Console.WriteLine("请输入1到8之间的数字!任意键继续"); Console.ReadKey(); break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }