private void btnQuery_Click(object sender, EventArgs e) { switch (cbxField.SelectedIndex) { case 0: //所有订单 orderbindingSource.DataSource = orderService.Orders; break; case 1: //根据ID查询 int.TryParse(Keyword, out int id); Order order = orderService.GetOrder(id); List <Order> result = new List <Order>(); if (order != null) { result.Add(order); } orderbindingSource.DataSource = result; break; case 2: //根据客户查询 orderbindingSource.DataSource = orderService.QueryOrdersByCustomerName(Keyword); break; case 3: //根据货物查询 orderbindingSource.DataSource = orderService.QueryOrdersByGoodsName(Keyword); break; case 4: //根据总价格查询(大于某个总价) float.TryParse(Keyword, out float totalPrice); orderbindingSource.DataSource = orderService.QueryByTotalAmount(totalPrice); break; } orderbindingSource.ResetBindings(false); }