private void button4_Click_1(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[] supplier = supplier_text.Text.Split(' '); string[] employer = textBox3.Text.Split(' '); try { purchase dao = new purchase(); double mm = Convert.ToDouble(label9.Text); dao.addDanju(Convert.ToDateTime(dateTimePicker1.Text), textBox1.Text, employer[0], mm, textBox4.Text, supplier[0], 1); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { purchase_material p = new purchase_material(); Console.Write(dataGridView1.Rows[i].Cells[0].Value + "lallalalaalalalalalalla"); p.RawMaterial_number = dataGridView1.Rows[i].Cells[0].Value.ToString(); p.Suppliernumber = supplier[0]; p.Dan_date = Convert.ToDateTime(dateTimePicker1.Text); Console.Write("这是一个人" + p.Suppliernumber + "这是一个人"); 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.Status = 1; p.Danju_id = textBox1.Text; // Console.Write("这是一个人" + p.Danju_id + "这是一个人"); dao.addpurchase(p); } MessageBox.Show("保存成功"); } catch (SystemException) { MessageBox.Show("操作有误"); } } else { } } }
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 (supplier_text.Text == "") { MessageBox.Show("请选择供应商"); b = false; } } } if (b == false) { } else { purchase dao = new purchase(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { purchase_material p = new purchase_material(); Console.Write(dataGridView1.Rows[i].Cells[0].Value + "lallalalaalalalalalalla"); p.RawMaterial_number = dataGridView1.Rows[i].Cells[0].Value.ToString(); p.Suppliernumber = supplier_text.Text; p.Dan_date = Convert.ToDateTime(dateTimePicker1.Text); 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); 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.Status = 1; dao.addpurchase(p); } MessageBox.Show("保存成功"); } }