Пример #1
0
        private void agregarDetallesVentas()
        {
            detalles_ventas detalles = new detalles_ventas();
            decimal         total, precio;
            int             cantidad;

            cantidad             = Convert.ToInt32(txt_cantidad.Text);
            precio               = Convert.ToDecimal(lbl_precio.Text);
            total                = precio * cantidad;
            detalles.ID_VENTA    = Convert.ToInt32(lbl_numVenta.Text);
            detalles.ID_PRODUCTO = Convert.ToInt32(txt_codigo.Text);
            detalles.CANTIDAD    = cantidad;
            detalles.TOTAL       = total;
            detalles.ID_ELIMINAR = Convert.ToInt32(lbl_idDetalleVenta.Text);
            detalles.agregarDetalleVenta();
        }
Пример #2
0
        private void QuitarFila()
        {
            int pos, id, cantidad, numProductos;

            id       = Convert.ToInt32(dgridVentas.CurrentRow.Cells[0].Value);
            cantidad = Convert.ToInt32(dgridVentas.CurrentRow.Cells[3].Value);
            pos      = dgridVentas.CurrentRow.Index;
            decimal  suma     = 0;
            Conexion conexion = new Conexion();

            if (pos != -1)
            {
                if (MessageBox.Show("Quieres quitar el producto del carrito?", "Ventas", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    numProductos           = dgridVentas.Rows.Count;
                    lbl_cantProductos.Text = numProductos.ToString();
                    detalles_ventas detalles = new detalles_ventas();
                    detalles.ID_ELIMINAR = Convert.ToInt32(dgridVentas.CurrentRow.Cells[5].Value);
                    detalles.eliminarDetalleVenta();
                    foreach (DataGridViewRow fila in dgridVentas.Rows)
                    {
                        suma           = suma + Convert.ToDecimal(fila.Cells[4].Value.ToString());
                        lbl_total.Text = suma.ToString();
                    }
                    SqlCommand comando = new SqlCommand("UPDATE Inventario SET existencia= existencia+@cantidad WHERE id_producto=@id", conexion.abrirConexion());
                    comando.Parameters.AddWithValue("@cantidad", cantidad);
                    comando.Parameters.AddWithValue("@id", id);
                    comando.ExecuteNonQuery();
                    comando.Parameters.Clear();
                    conexion.cerrarConexion();
                    dgridVentas.Rows.RemoveAt(pos);
                }
                else
                {
                    MessageBox.Show("Debes seleccionar la fila", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }