private void button1_Click(object sender, EventArgs e) { Car car = new Car(); //获取车辆开始停车的时间 DateTime time = dateTimePicker1.Value; string plate = txtPlate.Text; int needPosition = Convert.ToInt32(txtPosition.Text); int startMoney = Convert.ToInt32(txtStartMoney.Text); int id = Id; int carTypeId = (int)comboBox1.Tag; int carPositionId = Convert.ToInt32(comboBox2.SelectedItem); car.CarTypeId = carTypeId; car.CreateDateTime = time; car.ManangerId = id; car.Money = startMoney; car.NeedPosition = needPosition; car.Plate = plate; car.CarPositionId = carPositionId; CarType carType = new CarType(); int n = carType.Add(car); if (n > 0) { MessageBox.Show("保存成功"); this.Close(); } else { MessageBox.Show("保存失败"); } }