private void cantidad_textbox_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } if (e.KeyChar == (char)Keys.Enter) { int cantidad = 0; if (!int.TryParse(cantidad_textbox.Text, out cantidad)) { MessageBox.Show("Debe ingresar un número entero.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (ObtenerCantidadProducto(Codigo_textbox.Text) == 0) { MessageBox.Show("Error en la busqueda de la cantidad del producto seleccionado.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ObtenerCantidadProducto(Codigo_textbox.Text) < int.Parse(cantidad_textbox.Text)) { MessageBox.Show("La cantidad ingresada es mayor a la vendida.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ObtenerCantidadProducto(Codigo_textbox.Text) >= int.Parse(cantidad_textbox.Text)) { //Se hace la devolucion del producto //Obtener el precio del producto e ingresarlo, al igual ingresarlo en la base de datos Detalle detalle = new Detalle(); detalle.id_producto = Codigo_textbox.Text; detalle.id_venta = new Validaciones().LimpiarString(clave_venta_textbox.Text); detalle.cantidad = ObtenerCantidadProducto(Codigo_textbox.Text) - int.Parse(cantidad_textbox.Text); detalle.precio = productoDetalle.precio; detalle.total = productoDetalle.precio * detalle.cantidad; new DAODetalle().ModificarDetalle(detalle); List <Detalle> detalles = new List <Detalle>(); detalles = new DAODetalle().GetDetails(new Validaciones().LimpiarString(clave_venta_textbox.Text)); Ventas devolucion = new DAOVentas().GetVentaXId(clave_venta_textbox.Text); devolucion.Total = ObtenerTotalVenta(detalles); new DAOVentas().ModificarVenta(devolucion); //Se verifica si el producto es una oferta para regresar la cantidad. DTOOfertas oferta = new DAOOfertas().GetOferta(Codigo_textbox.Text); if (oferta != null) { new DAOProductos().Aumentarproductos(oferta.codigo, oferta.cantidad * int.Parse(cantidad_textbox.Text)); } else { new DAOProductos().Aumentarproductos(Codigo_textbox.Text, int.Parse(cantidad_textbox.Text)); } MessageBox.Show("Devolución realizada con éxito.", "Devolución", MessageBoxButtons.OK, MessageBoxIcon.Information); FocusTicket(); } } } }
public List <Detalle> ObtenerListaDetallesCredito(int id_cliente) { List <Detalles_credito_cliente> detalles = null; detalles = GetDetallesCredito(id_cliente); //Obtengo toda la informacion con una lista de detalles tomando en cuenta List <Detalle> DetallesCreditos = new List <Detalle>(); foreach (Detalles_credito_cliente temp in detalles) { List <Detalle> temporal = new List <Detalle>(); temporal = new DAODetalle().GetDetails(temp.id_venta); //Agrego los elementos de temporal a la lista de detallescreditos foreach (Detalle tmp in temporal) { DetallesCreditos.Add(tmp); } } return(DetallesCreditos); }