private void button4_Click(object sender, EventArgs e) { bool b = true; if (dataGridView1.Rows.Count == 1) { MessageBox.Show("请填写信息"); b = false; } else { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (dataGridView1.Rows[i].Cells[0].Value == null) { MessageBox.Show("编号不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[1].Value == null) { MessageBox.Show("商品名称不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[3].Value == null) { MessageBox.Show("单位不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[4].Value == null) { MessageBox.Show("数量不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[5].Value == null) { MessageBox.Show("单价不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[6].Value == null) { MessageBox.Show("金额不能为空"); b = false; } else if (textBox1.Text == "") { MessageBox.Show("请选择供应商"); b = false; } else if (textBox3.Text == "") { MessageBox.Show("销售人员不能为空!"); } } } if (b == false) { } else { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("是否确认保存?", "提交", messButton); if (dr == DialogResult.OK) { string[] customer = supplier_text.Text.Split(' '); string[] employer = textBox3.Text.Split(' '); sale dao = new sale(); double mm = Convert.ToDouble(label10.Text); dao.addDanju(Convert.ToDateTime(dateTimePicker1.Text), textBox1.Text, employer[0], mm, textBox4.Text, customer[0]); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { sale_good p = new sale_good(); Console.Write(dataGridView1.Rows[i].Cells[0].Value + "lallalalaalalalalalalla"); p.Good_number = dataGridView1.Rows[i].Cells[0].Value.ToString(); p.Customernumber = customer[0]; p.Dan_date = Convert.ToDateTime(dateTimePicker1.Text); Console.Write("这是一个人" + p.Customernumber + "这是一个人"); p.Unit = dataGridView1.Rows[i].Cells[3].Value.ToString(); p.Count = Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value); p.Price = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value); Console.Write("这是一个人" + p.Price + "这是一个人"); p.Money = Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value); if (dataGridView1.Rows[i].Cells[7].Value == null) { p.Remark = ""; } else { p.Remark = dataGridView1.Rows[i].Cells[7].Value.ToString(); } p.Danju_id = textBox1.Text; // Console.Write("这是一个人" + p.Danju_id + "这是一个人"); dao.addsale(p); } MessageBox.Show("保存成功"); } else { } } }