コード例 #1
0
        private void ButtonRemover_Click(object sender, EventArgs e)
        {
            Ventas venta = new Ventas();

            if (VentaDetalleDataGridView.Rows.Count > 0 && VentaDetalleDataGridView.CurrentRow != null)
            {
                List <VentasDetalle> detalle = (List <VentasDetalle>)VentaDetalleDataGridView.DataSource;
                detalle.RemoveAt(VentaDetalleDataGridView.CurrentRow.Index);
                Productos producto = (Productos)ProductoComboBox.SelectedItem;

                int x = Convert.ToInt32(CantidadNumericUpDown.Value);
                producto.Inventario += x;

                decimal subtotal = 0;

                foreach (var item in detalle)
                {
                    subtotal -= item.Importe;
                }

                subtotal            *= (-1);
                SubTotalTextBox.Text = subtotal.ToString();

                itbis             = VentasBLL.CalcularItbis(Convert.ToDecimal(SubTotalTextBox.Text));
                ItbisTextBox.Text = itbis.ToString();

                Total = VentasBLL.CalcularTotal(Convert.ToDecimal(SubTotalTextBox.Text), Convert.ToDecimal(ItbisTextBox.Text));

                TotalTextBox.Text = Total.ToString();

                VentaDetalleDataGridView.DataSource = null;
                VentaDetalleDataGridView.DataSource = detalle;

                QuitarColumnas();
            }
        }
コード例 #2
0
        private void ButtonAgregar_Click(object sender, EventArgs e)
        {
            List <VentasDetalle> detalle = new List <VentasDetalle>();

            if (VentaDetalleDataGridView.DataSource != null)
            {
                detalle = (List <VentasDetalle>)VentaDetalleDataGridView.DataSource;
            }

            Repositorio <Productos> repositorio = new Repositorio <Productos>(new Contexto());
            Productos producto = (Productos)ProductoComboBox.SelectedItem;

            if ((int)CantidadNumericUpDown.Value > producto.Inventario)
            {
                MessageBox.Show("no hay suficiente Productos para la venta!!", "Error!!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                detalle.Add(
                    new VentasDetalle(vDetalleId: 0,
                                      ventaId: (int)Convert.ToInt32(VentaIdNumericUpDown.Value),
                                      productoId: (int)ProductoComboBox.SelectedValue,
                                      producto: (string)ProductosBLL.RetornarDescripcion(ProductoComboBox.Text),
                                      cantidad: Convert.ToInt32(CantidadNumericUpDown.Value),
                                      precio: Convert.ToInt32(PrecioTextBox.Text),
                                      importe: Convert.ToInt32(ImporteTextBox.Text)));

                VentaDetalleDataGridView.DataSource = null;
                VentaDetalleDataGridView.DataSource = detalle;

                QuitarColumnas();
            }

            if (CantidadNumericUpDown.Value == 0)
            {
                MessageBox.Show("Introduzca una cantidad!!", "Error!!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            int x = Convert.ToInt32(CantidadNumericUpDown.Value);

            producto.Inventario -= x;

            decimal subtotal = 0;

            foreach (var item in detalle)
            {
                subtotal += item.Importe;
            }

            SubTotalTextBox.Text = subtotal.ToString();

            itbis = VentasBLL.CalcularItbis(Convert.ToDecimal(SubTotalTextBox.Text));

            ItbisTextBox.Text = itbis.ToString();

            Total = VentasBLL.CalcularTotal(Convert.ToDecimal(SubTotalTextBox.Text), Convert.ToDecimal(ItbisTextBox.Text));

            TotalTextBox.Text = Total.ToString();
        }