public void AddOrder(int num, string name, string address, string phone, List <string> cargo, List <int> number, List <double> price) { string customerName = name; Customer customerExample = new Customer(customerName); customerExample.Address = address; customerExample.PhoneNumber = phone; List <Cargo> cargoexample = new List <Cargo>(); for (int i = 0; i < cargo.Count(); i++) { cargoexample.Add(new Cargo(cargo[i], price[i])); } List <OrderDetails> DetailsExample = new List <OrderDetails>(); for (int i = 0; i < cargo.Count(); i++) { DetailsExample.Add(new OrderDetails(cargoexample[i], number[i])); } Order order1 = new Order(num, customerExample, DetailsExample); int n = 0; foreach (Order a in OrderList) { if (!order1.Equals(a)) { n++; } } if (n == OrderList.Count) { OrderList.Add(order1); } else { Console.WriteLine("该订单已经添加过"); } }
public void createOrder(Customer customer, Goods goods, int sum) { OrderDetail orderDetail = new OrderDetail(); orderDetail.setCustomer(customer); orderDetail.setGoods(goods); orderDetail.setName(customer.getName() + goods.getName() + orderNum); orderDetail.setMoney(goods.getPrice() * sum); Order order = new Order(); order.setId(orderNum); order.setOrderDetail(orderDetail); foreach (Order orderExist in orders) { if (order.Equals(orderExist)) { throw new Exception("订单重复"); } } orders.Add(order); }