private void BtnFind_Click(object sender, EventArgs e) { switch (cmbAccordItem.SelectedIndex) { case 0: //所有订单 bindingSourceOrder.DataSource = orderService.orderList; break; case 1: //根据ID查询 IEnumerable <Order> orderList = orderService.FindOrder(Int32.Parse(txtAccordDtail.Text)); bindingSourceOrder.DataSource = orderList; break; case 2: //根据顾客名查询 IEnumerable <Order> orderList2 = orderService.FindOrder(false, txtAccordDtail.Text); bindingSourceOrder.DataSource = orderList2; break; case 3: //根据商品物查询 IEnumerable <Order> orderList3 = orderService.FindOrder(true, txtAccordDtail.Text); bindingSourceOrder.DataSource = orderList3; break; } bindingSourceOrder.ResetBindings(true); }
static void Main(string[] args) { //测试数据——订单明细 OrderItem itemOne = new OrderItem("铅笔", 5, 1); OrderItem itemTwo = new OrderItem("钢笔", 10, 50); OrderItem itemThree = new OrderItem("圆珠笔", 20, 2); OrderItem itemFour = new OrderItem("橡皮擦", 20, 2); OrderItem itemFive = new OrderItem("篮球", 200, 10); OrderItem itemSix = new OrderItem("足球", 300, 5); //测试数据——订单 Order order1 = new Order("文具", "hhx", 600); Thread.Sleep(1000); Order order2 = new Order("运动器材", "Tom", 5000); Thread.Sleep(1000); Order order3 = new Order("其他", "hhx", 3000); //添加明细 Console.WriteLine("添加订单明细:"); order1.AddItems(itemOne); order1.AddItems(itemTwo); order1.AddItems(itemThree); order2.AddItems(itemSix); order2.AddItems(itemFive); order3.AddItems(itemFive); order3.AddItems(itemOne); //添加订单 Console.WriteLine("添加订单:"); OrderService service = new OrderService(); service.AddOrder(order1); service.AddOrder(order2); service.AddOrder(order1); //输出订单信息 Console.WriteLine(service.ToString()); //删除订单 Console.WriteLine("删除order2:"); service.DelOrder(order2.OrderNum); //service.DelOrder(2); //订单号错误删除失败 Console.WriteLine("当前订单状况:\n{0}", service.ToString()); //修改订单,将order1修改为order3 service.ChangeOrder(order1.OrderNum, order3); Console.WriteLine("当前订单状况:\n{0}", service.ToString()); //查询订单,按照订单号 service.AddOrder(order2); service.AddOrder(order1); var tmp = service.FindOrder(order1.OrderNum); service.SelfDefSort(); if (tmp.Count != 0) { for (int n = 0; n < tmp.Count; n++) { Console.WriteLine(tmp[n].ToString()); } } //订单查询,按照商品名称和客户 var tmp1 = service.FindOrder("铅笔"); var tmp2 = service.FindOrder("Tom"); foreach (Order o in tmp1) { Console.WriteLine("按照商品名:\n{0}", o.ToString()); } foreach (Order o in tmp2) { Console.WriteLine("按照客户名:\n{0}", o.ToString()); } //订单排序 Console.WriteLine("未排序:\n{0}", service.ToString()); service.DefSort(); Console.WriteLine("默认排序:\n{0}", service.ToString()); service.SelfDefSort(); Console.WriteLine("lambda表达式自定义排序:\n{0}", service.ToString()); service.Export(); Console.WriteLine(File.ReadAllText("D:\\Order.xml")); List <Order> ts = service.Import(); if (ts != null) { foreach (Order s in ts) { Console.WriteLine(s.ToString()); } } Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Welcome to Order Management System!"); OrderService service = new OrderService(); service.Import("orders.xml"); service.OrderIDCounter = service.Orders != null && service.Orders.Count > 0 ? service.Orders[service.Orders.Count - 1].OrderID : 0; while (true) { try { String orderID; String customerName; String customerAddress; String action = GetInput("1.add an order\t2.delete an order\t3.modify an order\t4.select the orders\nPlease select an action: "); switch (action) { case "1": customerName = GetInput("Customer name:"); customerAddress = GetInput("Customer address:"); Console.WriteLine("Add an order successful!"); Console.WriteLine("Your order ID is:" + service.AddOrder(new Order(0, new Customer(customerName, customerAddress), DateTime.Now, new List <OrderItem>()))); break; case "2": orderID = GetInput("Order ID:"); service.DeleteOrder(Int32.Parse(orderID)); Console.WriteLine("Delete the order successful!"); break; case "3": orderID = GetInput("Order ID:"); String operation = GetInput( "customer name\tcustomer address\torder time\tadd item\n" + "delete item\tquantity\nPlease select an operation:" ); String modifyData = ""; if (operation != "add item") { modifyData = GetInput("The data After modify:"); } object data = null; int goodsID = 0; switch (operation) { case "customer name": case "customer address": data = modifyData; break; case "order time": data = DateTime.Parse(modifyData); break; case "add item": goodsID = Int32.Parse(GetInput("Goods ID:")); int quantity = Int32.Parse(GetInput("Quantity:")); data = new OrderItem(new Goods(goodsID), quantity); break; case "delete item": goodsID = Int32.Parse(GetInput("Goods ID:")); break; case "quantity": goodsID = Int32.Parse(GetInput("Quantity:")); data = Int32.Parse(modifyData); break; default: throw new ArgumentException("Invalid argument!"); } service.AlterOrder(Int32.Parse(orderID), operation, data, goodsID); Console.WriteLine("Modify successful!"); Console.Write(service.FindOrder(int.Parse(orderID), null, null)[0]); break; case "4": Console.WriteLine("Please enter search conditions:"); orderID = GetInput("Order ID:"); String goodsName = GetInput("Goods name:"); customerName = GetInput("Customer name:"); int orderId = orderID == "" ? int.MinValue : int.Parse(orderID); goodsName = goodsName == "" ? null : goodsName; customerName = customerName == "" ? null : customerName; List <Order> results = service.FindOrder(orderId, goodsName, customerName); Console.WriteLine("Result:"); foreach (Order order in results) { Console.WriteLine(order); } break; default: throw new ArgumentException("No such operation!"); } service.Export("orders.xml"); } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (FormatException) { Console.WriteLine("Invalid input!"); } } }