private void AddButton_Click(object sender, EventArgs e) { List <OrderItem> orderItems = new List <OrderItem>(); for (int i = 0; i < checkedListBox.Items.Count; i++) { if (checkedListBox.GetItemChecked(i)) { string itemid = checkedListBox.GetItemText(checkedListBox.Items[i]); int count = 0; double UnitPrice = Product.namePrice[itemid]; switch (itemid) { case "鞋子": count = int.Parse(textBox1.Text); break; case "裤子": count = int.Parse(textBox2.Text); break; case "衣服": count = int.Parse(textBox3.Text); break; case "手表": count = int.Parse(textBox4.Text); break; case "帽子": count = int.Parse(textBox5.Text); break; } OrderItem orderItem = new OrderItem(itemid, count, UnitPrice); orderItems.Add(orderItem); } } orderN = new Order(OrderID.OrderId(), textBox_name.Text, orderItems); Form1.orderservice.AddOrder(orderN); MessageBox.Show($"添加{textBox_name.Text}的订单成功!"); }