示例#1
0
        private void eliminar_venta_button_Click(object sender, EventArgs e)
        {
            if (venta == null)
            {
                return;
            }

            var mensaje = "La venta se eliminará de la base de datos. Las unidades vendidas se agregarán al lote al cual pertenecían. ¿Desea continuar?";

            var continuar = MessageBox.Show(mensaje, "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (continuar == DialogResult.No)
            {
                return;
            }

            try
            {
                ConfigGlobal.conexion.EliminarVenta(venta.Id);
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("Tarea completada.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

            lote_id_tb.Text           = "N/A";
            producto_tb.Text          = "N/A";
            unidades_vendidas_tb.Text = "N/A";
            total_tb.Text             = "N/A";
            fecha_venta_tb.Text       = "N/A";
            cliente_tb.Text           = "N/A";
            venta_id_tb.Clear();
            venta_id_tb.Focus();
            venta = null;
        }
示例#2
0
        private void cargar_venta_button_Click(object sender, EventArgs e)
        {
            if (venta != null)
            {
                return;
            }

            if (Ayudantes.EsEnteroPositivo(venta_id_tb.Text) == false)
            {
                MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                var ventaId = Convert.ToInt32(venta_id_tb.Text);
                venta = ConfigGlobal.conexion.CargarVenta_PorId(ventaId);
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (venta == null)
            {
                MessageBox.Show("La venta no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            lote_id_tb.Text           = venta.Lote.Id.ToString();
            producto_tb.Text          = venta.Lote.Producto.Nombre;
            unidades_vendidas_tb.Text = venta.Unidades.ToString();
            total_tb.Text             = venta.Total.ToString();
            fecha_venta_tb.Text       = venta.Fecha;
            cliente_tb.Text           = venta.Cliente?.NombreCompleto;
        }
示例#3
0
        private void agregar_lote_button_Click(object sender, EventArgs e)
        {
            // validar campos
            if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false)
            {
                MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false)
            {
                MessageBox.Show("Cantidad de unidades inválida", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // cargar lote y verificar que el lote se haya encontrado

            var        loteId = int.Parse(lote_id_tb.Text.Trim());
            LoteModelo lote   = null;

            try
            {
                lote = ConfigGlobal.conexion.CargarLote_PorId(loteId);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lote == null)
            {
                MessageBox.Show("El lote no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // verificar que el lote no exista en la lista

            var loteExistente = ventas.List.OfType <VentaModelo>().ToList().Find(x => x.LoteId == lote.Id);

            if (loteExistente != null)
            {
                MessageBox.Show("El lote ya existe en la lista.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // verificar que existan suficientes unidades en el lote

            var unidadesAVender = int.Parse(unidades_tb.Text);

            if (unidadesAVender > lote.UnidadesDisponibles)
            {
                if (lote.UnidadesDisponibles == 0)
                {
                    MessageBox.Show($"El lote no contiene unidades.", "Lote vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                MessageBox.Show($"Cantidad solicitada de unidades inválida. Solo { lote.UnidadesDisponibles } unidades disponibles.", "Cantidad disponible insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // crear venta
            var venta = new VentaModelo();

            venta.Unidades          = unidadesAVender;
            venta.Lote              = lote;
            venta.PrecioVentaUnidad = lote.PrecioVentaUnidad;

            ventas.Add(venta);
            CalcularTotal();
        }
示例#4
0
文件: VenderForm.cs 项目: gucclx/Siv
        /// <summary>
        /// Carga y agrega el lote especificado con las unidades especificadas
        /// al datagridview.
        /// </summary>
        private void AgregarLote()
        {
            if (ValidarCampos() == false)
            {
                return;
            }
            var loteId = int.Parse(lote_id_tb.Text);

            LoteModelo lote = null;

            try
            {
                lote = ConfigGlobal.conexion.CargarLote_PorId(loteId);
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (lote == null)
            {
                MessageBox.Show("El lote no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                LimpiarCamposLote();
                return;
            }

            // Verificar que el lote no exista en la lista de ventas.
            var loteExistente = ventas.List.OfType <VentaModelo>().ToList().Find(l => l.LoteId == lote.Id);

            if (loteExistente != null)
            {
                MessageBox.Show("El lote ya existe en la lista.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                LimpiarCamposLote();
                return;
            }

            // Verificar que existan suficientes unidades en el lote.
            var unidadesAVender = uint.Parse(unidades_tb.Text);

            if (unidadesAVender > lote.UnidadesDisponibles)
            {
                LimpiarCamposLote();
                if (lote.UnidadesDisponibles == 0)
                {
                    MessageBox.Show($"El lote no contiene unidades.", "Lote vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                MessageBox.Show($"Cantidad solicitada de unidades inválida. Solo { lote.UnidadesDisponibles } unidades disponibles.", "Cantidad disponible insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var venta = new VentaModelo();

            venta.Unidades          = unidadesAVender;
            venta.Lote              = lote;
            venta.PrecioVentaUnidad = lote.PrecioVentaUnidad;

            ventas.Add(venta);
            CalcularTotal();
            lote_id_tb.Clear();
            lote_id_tb.Focus();
            unidades_tb.Clear();
        }