private void button2_Click(object sender, EventArgs e) { int Source = 0; if (comboBox1.SelectedValue.ToString() == "1") { Source = 1; } if (comboBox1.SelectedValue.ToString() == "2") { Source = 2; } if (comboBox1.SelectedValue.ToString() == "3") { Source = 3; } if (comboBox1.SelectedValue.ToString() == "4") { Source = 4; } if (comboBox1.SelectedValue.ToString() == "1" && comboBox1.SelectedValue.ToString() == Source.ToString()) { Source = 2; } if (comboBox1.SelectedValue.ToString() == "2" && comboBox1.SelectedValue.ToString() == Source.ToString()) { Source = 3; } if (comboBox1.SelectedValue.ToString() == "3" && comboBox1.SelectedValue.ToString() == Source.ToString()) { Source = 4; } if (comboBox1.SelectedValue.ToString() == "4" && comboBox1.SelectedValue.ToString() == Source.ToString()) { Source = 1; } if (dataGridView1.Rows.Count >= 2) { bllss4.insertIntoOrders(TranID, int.Parse(comboBox1.SelectedValue.ToString()), Source, int.Parse(comboBox2.SelectedValue.ToString()), dateTimePicker1.Value.ToString()); DataTable dt = bllss4.getIDOrders(); int OrderId = int.Parse(dt.Rows[0][0].ToString()); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { DataTable dt1 = bllss4.getIdByPartName(dataGridView1.Rows[i].Cells["PartName"].Value.ToString()); int PartID = int.Parse(dt1.Rows[0][0].ToString()); string BathNumber = dataGridView1.Rows[i].Cells["BatchNumber"].Value.ToString(); float Amount = float.Parse(dataGridView1.Rows[i].Cells["Amount"].Value.ToString()); bllss4.insertIntoOrderItems(OrderId, PartID, BathNumber, Amount); bllss4.updateParts(PartID, Amount); } MessageBox.Show("Thêm dữ liệu thành công"); } else { MessageBox.Show("Bạn cần thêm dữ liệu vào bảng"); } }