private void AddItemToCart(string codigo, decimal cantidad) { var curProd = inventBL.GetProductoByCode(codigo); if (curProd != null) { decimal?precioVenta = curProd.PrecioVenta; try { if (precioVenta == 0.0M) { lblMensaje.Text = "El producto no tiene precio de venta!!!"; } else { if (curProd.VerificaDisponible) { var existencia = inventBL.GetExistenciaByIdProducto(curProd.IdProducto); if (existencia != null) { var yaSolicitado = detailRep.CartLines.Where(p => p.Producto.IdProducto == curProd.IdProducto).Sum(c => c.Cantidad); if (existencia.Cantidad >= (cantidad + yaSolicitado)) { detailRep.AddItem(curProd, cantidad, Math.Round(cantidad * (curProd.PrecioVenta * curProd.Descuento / 100), 2)); } else { MessageBox.Show("No hay suficiente cantidad de producto en existencias!!!"); } } else { MessageBox.Show("Producto no encontrado en existencias!!!"); } } else { detailRep.AddItem(curProd, cantidad, Math.Round(cantidad * (curProd.PrecioVenta * curProd.Descuento / 100), 2)); } txtCodigoProducto.SelectAll(); txtCantidad.Text = "1"; txtCodigoProducto.Focus(); DisplayCartData(); } } catch (Exception ex) { ControlBusiness.BusinessHelpers.General.DoError(ex, "Control", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }