private void btnAñadir_Click(object sender, EventArgs e) { try { PuntoDeVenta.Library.Entity_Classes.FacturaDetalle facturaDetalle = new PuntoDeVenta.Library.Entity_Classes.FacturaDetalle(); PuntoDeVenta.Library.Entity_Classes.Producto prod = new PuntoDeVenta.Library.Entity_Classes.Producto(); using (MuebleriaDBEntities context = new MuebleriaDBEntities()) { String codigo = txtCodigoBarra.Text; prod = productHelper.ToModelProduct(context.TBL_PRODUCTOS.SingleOrDefault(x => x.CodigoDeBarra == codigo)); } facturaDetalle.CodigoDeBarra = txtCodigoBarra.Text; if (productHelper.CheckProductAvailability(txtCodigoBarra.Text, Convert.ToInt32(txtCantidad.Text))) { facturaDetalle.Cantidad = Convert.ToInt32(txtCantidad.Text); } else { MessageBox.Show("No existen productos disponibles en el almacen para este producto."); throw new Exception(); } facturaDetalle.NombreProducto = txtProductoNombre.Text; facturaDetalle.PrecioPorCantidad = prod.PrecioPorUnidad * facturaDetalle.Cantidad; if (NUDDescuento.Value != 0) { facturaDetalle.Descuento = NUDDescuento.Value; facturaDetalle.PrecioConDescuento = facturaDetalle.PrecioPorCantidad - ((facturaDetalle.PrecioPorCantidad / 100) * facturaDetalle.Descuento); } else { facturaDetalle.Descuento = 0; facturaDetalle.PrecioConDescuento = facturaDetalle.PrecioPorCantidad; } decimal total = 0; list.Add(facturaDetalle); foreach (var item in list) { total += item.PrecioConDescuento; } txtTotal.Text = total.ToString("0.00"); this.TBL_FACTURABindingSource.DataSource = list; this.reportViewer1.RefreshReport(); Clear(); } catch (Exception r) { MessageBox.Show("Existen campos imcompletos. Por favor, verifique."); } txtCodigoBarra.Focus(); }
private void LoadingTimer_Tick(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(txtCodigoBarra.Text)) { ScanningClear(); } else { String barcode; PuntoDeVenta.Library.Entity_Classes.Producto producto = new PuntoDeVenta.Library.Entity_Classes.Producto(); using (MuebleriaDBEntities context = new MuebleriaDBEntities()) { barcode = txtCodigoBarra.Text; try { producto = productHelper.ToModelProduct(context.TBL_PRODUCTOS.SingleOrDefault(x => x.CodigoDeBarra == barcode)); } catch { ScanningClear(); } } txtProductoNombre.Text = producto.NombreProducto; txtMarca.Text = producto.Marca; decimal price = Convert.ToDecimal(productHelper.GetProductPrice(txtCodigoBarra.Text)) * Convert.ToDecimal(txtCantidad.Text); decimal PrecioDescuento = price - (price / 100) * (NUDDescuento.Value); if (NUDDescuento.Value == 0) { txtPrecioDescuento.Text = price.ToString("0.00"); } if (NUDDescuento.Value > 0) { txtPrecioDescuento.Text = PrecioDescuento.ToString("0.00"); } } } catch { //ScanningClear(); } }