bool IngresaDetalle(int codClienteFactura) { bool respuesta = true; Clases.Conexion conectadetalle = new Clases.Conexion(); try { int resultado1 = 0; if (conectadetalle.AbrirConexion() == true) { Clases.DetalleFactura pDetalle = new Clases.DetalleFactura(); int j; txtCodFactura.Text = Convert.ToString(Clases.Factura.ObtenerCodigoFactura(conecta.conexion, codClienteFactura)); numFilas = dgvDetalleFactura.Rows.Count; for (j = 0; j < (numFilas - 1); j++) { // detalle factura pDetalle.Codigo_Factura = Convert.ToInt32(txtCodFactura.Text); pDetalle.Codigo_Producto = Convert.ToInt32(dgvDetalleFactura[6, j].Value); pDetalle.Secuencial_Detalle = Convert.ToInt32(dgvDetalleFactura[0, j].Value); pDetalle.Descripcion_Detalle = Convert.ToString(dgvDetalleFactura[1, j].Value); pDetalle.Cantidad_Detalle = Convert.ToInt32(dgvDetalleFactura[2, j].Value); pDetalle.PrecioUnitario_Detalle = Convert.ToDouble(dgvDetalleFactura[3, j].Value); pDetalle.Total_Detalle = Convert.ToDouble(dgvDetalleFactura[4, j].Value); resultado1 = Clases.DetalleFactura.AgregarDetalle(conectadetalle.conexion, pDetalle); if (resultado1 > 0) { if (ActualizaStock(pDetalle.Codigo_Producto, pDetalle.Cantidad_Detalle) == true) { //MessageBox.Show("Registro Ingresado exitosamente", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); respuesta = true; } } else { respuesta = false; } } conectadetalle.CerrarConexion(); } return(respuesta); } catch (MySqlException ex) { MessageBox.Show(ex.Message); conectadetalle.CerrarConexion(); respuesta = false; return(respuesta); } }
public static int AgregarDetalle(MySqlConnection conexion, DetalleFactura pDetalle) { int retorno = 0; MySqlCommand comando = new MySqlCommand(); comando.CommandText = "PA_Insertar_Detalle"; comando.CommandType = CommandType.StoredProcedure; comando.Connection = conexion; comando.Parameters.AddWithValue("@codFactura", pDetalle.Codigo_Factura); comando.Parameters.AddWithValue("@codProducto", pDetalle.Codigo_Producto); comando.Parameters.AddWithValue("@secuencialDetalle", pDetalle.Secuencial_Detalle); comando.Parameters.AddWithValue("@descripcionDetalle", pDetalle.Descripcion_Detalle); comando.Parameters.AddWithValue("@cantidadDetalle", pDetalle.Cantidad_Detalle); comando.Parameters.AddWithValue("@precioUnitarioDetalle", pDetalle.PrecioUnitario_Detalle); comando.Parameters.AddWithValue("@totalDetalle", pDetalle.Total_Detalle); retorno = comando.ExecuteNonQuery(); return(retorno); }