private void button3_Click(object sender, EventArgs e) { int codprodu = 0; int dgCantidad = 0; //Boton Agregar Factura if (txtcantidad.Text == "" || txtcantidad.Text == "0") { MessageBox.Show("Ingresar Cantidad", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (dataGridView1.Rows.Count > 0) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { for (int row = Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value); row == Convert.ToInt32(otmpProducto.CodProducto); row++) { dgCantidad = Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value); codprodu = row; if (codprodu == Convert.ToInt32(otmpProducto.CodProducto)) { dgCantidad = dgCantidad + Convert.ToInt32(txtcantidad.Text); oFacturaBL.modCantidad(dgCantidad, codprodu.ToString()); CargarGrilla(); } } } } if (codprodu != Convert.ToInt32(otmpProducto.CodProducto)) { oFacturaBL.AgregarDetalle(new ItemBE() { Cantidad = Convert.ToInt32(txtcantidad.Text), Precio = Convert.ToDecimal(txtprecio.Text), Producto = otmpProducto, }); CargarGrilla(); } } }