static void Main(string[] args) { try { Client cli1 = new Client("1", "Mark"); Client cli2 = new Client("2", "Coco"); Client cli3 = new Client("3", "Jackson"); Goods apple = new Goods("1", "Apple", 1.5); Goods milk = new Goods("2", "Milk", 3.0); Goods bed = new Goods("3", "Bed", 200); OrderDetails pro1 = new OrderDetails("1", 4, apple); OrderDetails pro2 = new OrderDetails("2", 2, milk); OrderDetails pro3 = new OrderDetails("3", 1, bed); Order ord1 = new Order("0001", cli1); Order ord2 = new Order("0002", cli2); Order ord3 = new Order("0003", cli3); OrderService os = new OrderService(); os.orderlist.Add(ord1); os.orderlist.Add(ord2); os.orderlist.Add(ord3); os.orderlist[0].AddProduct(pro1); os.orderlist[0].AddProduct(pro2); os.orderlist[0].AddProduct(pro3); os.orderlist[1].AddProduct(pro1); os.orderlist[1].AddProduct(pro3); os.orderlist[2].AddProduct(pro3); //XML序列化 XmlSerializer xmlser = new XmlSerializer(typeof(List <Order>)); string xmlFileName = "s.xml"; os.Export(xmlser, xmlFileName, os.orderlist); //显示xml文本 string xml = File.ReadAllText(xmlFileName); Console.WriteLine(xml); //XML反序列化 List <Order> orders = os.Import(xmlser, xmlFileName) as List <Order>; foreach (Order order in orders) { Console.WriteLine(order); } } catch (Exception e) { Console.WriteLine(e.Message); } }
//导出为HTML private void button7_Click(object sender, EventArgs e) { XmlSerializer xmlser = new XmlSerializer(typeof(List <Order>)); string fileName = "List.xml"; os.Export(xmlser, fileName, os.orderlist); XmlDocument doc = new XmlDocument(); doc.Load(fileName); XPathNavigator nav = doc.CreateNavigator(); nav.MoveToRoot(); XslTransform xt = new XslTransform(); xt.Load(@"..\..\List.xslt"); FileStream fs = File.OpenWrite(@"..\..\List.html"); XmlTextWriter writer = new XmlTextWriter(fs, System.Text.Encoding.Default); xt.Transform(nav, null, writer); }
static void Main(string[] args) { OrderDetails order1 = new OrderDetails("20181005001", "John", "Apple", 2.5, 3); OrderDetails order2 = new OrderDetails("20181005002", "Anna", "Apple", 2.5, 4); OrderDetails order3 = new OrderDetails("20181005003", "John", "Pear", 3.5, 3); OrderDetails order4 = new OrderDetails("20181005004", "Peter", "Orange", 3, 3); OrderDetails order5 = new OrderDetails("20181005004", "Peter", "Watermelen", 10, 1000); OrderService MyService = new OrderService(); try { MyService.addOrder(order1); MyService.addOrder(order2); MyService.addOrder(order3); MyService.addOrder(order4); MyService.addOrder(order5); //MyService.showAll(); //MyService.changeOrder(order4); //MyService.showAll(); MyService.searchOrder("订单号", "20181005004"); MyService.searchOrder("订单总额", "10000"); MyService.deleteOrder(order4); //MyService.showAll(); } catch (MyException e) { Console.WriteLine(e.Message); } string xmlFileName = MyService.Export(); MyService.Import(xmlFileName); }
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); } } }
static void Main(string[] args) { //测试 OrderService service = new OrderService(); //添加订单 Order myOrder01 = service.AddOrder("20181111001", "Lily", "13245678901"); Order myOrder02 = service.AddOrder("20181111002", "Mike", "15466666666"); try { //给订单添加条目(商品) myOrder01.AddProduct("apple"); myOrder01.AddProduct("sofa"); myOrder02.AddProduct("banana"); //修改订单中的内容 myOrder01.ChangeProduct("apple", "number", 12); //使apple的数量变为12 myOrder01.ChangeProduct("apple", "price", 5); //使apple单价变为5 myOrder01.ChangeProduct("sofa", "number", 3); myOrder01.ChangeProduct("sofa", "price", 5000); myOrder02.AddProduct("banana");//再增加一个banana myOrder02.ChangeProduct("banana", "price", 7); //显示订单内容 myOrder01.ShowOrder(); myOrder02.ShowOrder(); //按照客户名字查找订单 List <Order> myOrder = service.FindOrderByCustomer("Mike"); foreach (Order order in myOrder) { order.ShowOrder(); } //service.AddOrder("01","Lily"); //按照订单中的商品返回订单 List <Order> pdtOrder = service.FindOrderByProduct("banana"); //查找总额大于10000的订单 List <Order> bigOrder = service.FindOrderOverWan(); ////序列化订单 //// OrderService.Export(); //XmlSerializer xmlser = new XmlSerializer(typeof(List<Order>)); //string xmlFileName = "orders.xml"; //OrderService.XmlSerialize(xmlser, xmlFileName, OrderService.orderList); //Console.WriteLine("XML序列化订单:"); ////显示文本 //string xml = File.ReadAllText(xmlFileName); //Console.WriteLine(xml); ////反序列化订单 //List<Order> orderList2 = OrderService.XmlDeserialize(xmlser, xmlFileName) //as List<Order>; //foreach (Order order in OrderService.orderList) // Console.WriteLine(order); //序列化订单 service.Export(); //反序列化订单 service.Import("orders.xml"); service.ShowExploration(); //删除订单 service.DeleteOrder(myOrder01); service.DeleteOrder(myOrder02); } catch (MyException e) { Console.WriteLine(e.Message); Console.WriteLine("操作失败!"); } }
static void Main(string[] args) { OrderService orderService = new OrderService(); int flag = 0; while (true) { Console.WriteLine("请选择需要执行的操作(输入数字):"); Console.WriteLine("1.添加新订单"); Console.WriteLine("2.删除订单"); Console.WriteLine("3.查询订单"); Console.WriteLine("4.修改订单"); Console.WriteLine("5.查看订单列表"); Console.WriteLine("6.输出订单"); Console.WriteLine("7.导入订单"); Console.WriteLine("8.退出"); try { flag = Int32.Parse(Console.ReadLine()); if (flag < 1 || flag > 8) { throw new OrderException(); } else { switch (flag) { case 1: orderService.AddOrder(); break; case 2: orderService.DeleteOrder(); break; case 3: orderService.Search(); break; case 4: orderService.EditOrder(); break; case 5: orderService.DisplayOrderList(); break; case 6: orderService.Export(@"output.xml"); break; case 7: orderService.Import(@"output.xml"); break; case 8: return; } } } catch (Exception) { Console.WriteLine("输入有误!"); } } }
static void Main(string[] args) { 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("Find bigger than 70:"); os.GetBigger().ForEach( od => Console.WriteLine(od)); Console.WriteLine("Please input the goods' name you want to search:"); string str = Console.ReadLine(); os.QueryByGoodsName(str).ForEach( od => Console.WriteLine(od)); 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)); os.Export(order1, "E:\\ccc.txt"); Type type = typeof(Order); Order order4 = OrderService.Import("E:\\ccc.txt", type) as Order; Console.WriteLine("imported order:\n" + order4.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { //订单1 List <OrderDetail> orderDetails1 = new List <OrderDetail>(); OrderDetail od1_1 = new OrderDetail("笔", 1, "北京", 3); orderDetails1.Add(od1_1); OrderDetail od1_2 = new OrderDetail("纸", 0.5, "上海", 1000); orderDetails1.Add(od1_2); Order order1 = new Order(1, "张三", "13911111111", orderDetails1); //订单2 List <OrderDetail> orderDetails2 = new List <OrderDetail>(); OrderDetail od2_1 = new OrderDetail("书包", 100, "北京", 2); orderDetails2.Add(od2_1); OrderDetail od2_2 = new OrderDetail("电脑", 10000, "上海", 1); orderDetails2.Add(od2_2); Order order2 = new Order(2, "张四", "15311111111", orderDetails2); //订单3 List <OrderDetail> orderDetails3 = new List <OrderDetail>(); OrderDetail od3_1 = new OrderDetail("书包", 100, "北京", 1); orderDetails3.Add(od3_1); OrderDetail od3_2 = new OrderDetail("笔记本", 5, "上海", 30); orderDetails3.Add(od3_2); Order order3 = new Order(3, "张五", "13923222222", orderDetails3); List <Order> orders = new List <Order>(); orders.Add(order1); orders.Add(order2); orders.Add(order3); //订单服务 OrderService orderService = new OrderService(orders); orderService.ShowAllOrders(); //XML序列化 string xmlFileName = "s.xml"; orderService.Export(xmlFileName); Console.WriteLine("XML序列化\n"); //显示XML文本 string xml = File.ReadAllText(xmlFileName); Console.WriteLine(xml); Console.WriteLine("XML反序列化\n"); OrderService os = OrderService.Import(xmlFileName); os.ShowAllOrders(); //对订单的操作 int n = 1; while (n > 0) { Console.WriteLine("请输入整数表示操作 1.添加订单 2.删除订单(订单号) 3.修改订单 4.查询订单(订单号) 5.查询订单(购买人) 6.查询订单(订单内的商品)7.查找金额大于10000的订单 0退出"); n = int.Parse(Console.ReadLine()); Order find = new Order(); switch (n) { //1.添加订单 case 1: { string s1, s2, s; int j; Console.WriteLine("请输入一个新的订单"); Order newOrder; Console.WriteLine("请输入订单号"); s1 = Console.ReadLine(); j = int.Parse(s1); Console.WriteLine("请输入购买人"); s2 = Console.ReadLine(); Console.WriteLine("请输入购买人电话"); s = Console.ReadLine(); Console.WriteLine("请输入购买商品的数量"); int goodCount = 0; goodCount = int.Parse(Console.ReadLine()); List <OrderDetail> ods = new List <OrderDetail>(); string s3, s4; double d1; for (int i = 0; i < goodCount; i++) { Console.WriteLine("请输入商品名"); s3 = Console.ReadLine(); Console.WriteLine("请输入价格"); d1 = double.Parse(Console.ReadLine()); Console.WriteLine("请输入产地"); s4 = Console.ReadLine(); OrderDetail AOd = new OrderDetail(s3, d1, s4, goodCount); ods.Add(AOd); } newOrder = new Order(j, s2, s, ods); Console.WriteLine("添加第这个订单后"); orderService.AddOrder(newOrder); Console.WriteLine(); orderService.ShowAllOrders(); Console.WriteLine(); break; } //2.删除订单(订单号) case 2: { string s = ""; Console.WriteLine("请输入想删除的订单号的订单"); s = Console.ReadLine(); try { orderService.DelOrder(orderService.SearchByOrdNum(s)); orderService.ShowAllOrders(); Console.WriteLine("删除一个订单之后"); Console.WriteLine(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } break; } //3.修改订单(订单名) case 3: { try { Console.WriteLine("把订单名张三改成李四"); orderService.ChangeOrder("张三", "李四"); orderService.ShowAllOrders(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } Console.WriteLine(); break; } //4.查询订单(订单号) case 4: { Console.WriteLine("请输入想查询的订单号的订单"); string sNum = ""; sNum = Console.ReadLine(); try { find = orderService.SearchByOrdNum(sNum); find.ShowOrder(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } Console.WriteLine(); break; } //5.查询订单(购买人) case 5: { Console.WriteLine("请输入想查询的订单号的购买人"); string sName = ""; sName = Console.ReadLine(); try { find = orderService.SearchByBuyerName(sName); find.ShowOrder(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } Console.WriteLine(); break; } //6.查询订单(商品名) case 6: { Console.WriteLine("请输入想查询的订单号的商品名"); string gName = ""; gName = Console.ReadLine(); try { find = orderService.SearchByGoodsName(gName); find.ShowOrder(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } Console.WriteLine(); break; } case 7: { try { Console.WriteLine("金额超过10000的订单有"); find = orderService.SearchByOrdMonMoreThan10000(); find.ShowOrder(); } catch (CanNotFindOrder e) { Console.WriteLine(e.Message); } Console.WriteLine(); break; } default: n = -1; break; } } Console.ReadKey(); }