Ejemplo n.º 1
0
        private bool ValidarForm()
        {
            bool esFormValido = true;

            if (producto == null)
            {
                esFormValido = false;
                MessageBox.Show($"Debe seleccionar un producto.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

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

            if (Ayudantes.EsDecimalNoNegativo(inversion_total_tb.Text) == false)
            {
                esFormValido = false;
                MessageBox.Show("Inversión total inválida.", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            if (Ayudantes.EsDecimalNoNegativo(precio_venta_defecto_tb.Text) == false)
            {
                esFormValido = false;
                MessageBox.Show("Precio de venta inválido.", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(esFormValido);
        }
Ejemplo n.º 2
0
        private void cargar_lote_button_Click(object sender, EventArgs e)
        {
            if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false)
            {
                MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

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

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

            producto_tb.Text             = lote.Producto.Nombre;
            unidades_adquiridas_tb.Text  = lote.UnidadesCompradas.ToString();
            unidades_disponibles_tb.Text = lote.UnidadesDisponibles.ToString();
            inversion_unidad_tb.Text     = lote.InversionUnidad.ToString();
            precio_venta_unidad_tb.Text  = lote.PrecioVentaUnidad.ToString();
            inversion_total_tb.Text      = (lote.InversionUnidad * lote.UnidadesCompradas).ToString();
        }
Ejemplo n.º 3
0
        private async void exportar_button_Click(object sender, EventArgs e)
        {
            if (resultados == null || resultados.DataSource == null)
            {
                return;
            }

            using (var dialogGuardar = new SaveFileDialog())
            {
                dialogGuardar.Filter          = "CSV |*.csv";
                dialogGuardar.OverwritePrompt = true;
                if (dialogGuardar.ShowDialog() == DialogResult.OK)
                {
                    FileInfo archivo = new FileInfo(dialogGuardar.FileName);
                    try
                    {
                        Exportando(true);
                        ConfigTareaLabel($"Exportando { resultados.List.Count.ToString("#,##0") } filas...");
                        await Ayudantes.GuardarCsvReporteAsync(reportes : resultados.List.Cast <ReporteVentaModelo>().ToList(), archivo : archivo);

                        MessageBox.Show("Tarea completada", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            Exportando(false);
            ConfigTareaLabel(visible: false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Valida el id del lote a cargar y las unidades a cargar.
        /// </summary>
        /// <returns>
        /// false si el id del lote o las unidades a cargar no son validas.
        /// true si lo son.
        /// </returns>
        private bool ValidarCampos()
        {
            if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false)
            {
                MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false)
            {
                MessageBox.Show("Cantidad de unidades inválida", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private async void exportar_inventario_button_Click(object sender, EventArgs e)
        {
            var frm = new HistorialLotesFiltroForm(this);

            this.Hide();
            frm.ShowDialog();
            this.Show();


            var destino = GuardarDialogo();

            if (destino == null)
            {
                return;
            }

            Exportando(true);
            CambiarTareaLabel("Exportando...");

            List <ReporteInventarioModelo> reportes;
            int?comienzo = 0;

            try
            {
                do
                {
                    reportes = await Task.Run(() =>
                                              ConfigGlobal.conexion.CargarReporteInventario(reporteFiltro, limiteFilas: LimiteFilas, comienzo: comienzo)
                                              );

                    await Ayudantes.GuardarCsvReporteAsync(reportes, destino);

                    comienzo = reportes.LastOrDefault()?.LoteId;
                } while (reportes.Count > 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Exportando(false);
                return;
            }

            MessageBox.Show("Tarea completada", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Exportando(false);
            reporteFiltro = null;
        }
Ejemplo n.º 6
0
        private void editar_button_Click(object sender, EventArgs e)
        {
            if (lote == null)
            {
                return;
            }
            if (Ayudantes.EsEnteroNoNegativo(unidades_disponibles_tb.Text) == false)
            {
                MessageBox.Show("Unidades disponibles inválidas.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var nuevoUnidadesDisponibles = uint.Parse(unidades_disponibles_tb.Text);

            if (nuevoUnidadesDisponibles > lote.UnidadesDisponibles)
            {
                MessageBox.Show("No se permite agregar unidades al lote. Unidades disponibles inválidas.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (Ayudantes.EsDecimalNoNegativo(precio_venta_unidad_tb.Text) == false)
            {
                MessageBox.Show("Precio de venta por unidad inválido.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var nuevoPrecioVenta = decimal.Parse(precio_venta_unidad_tb.Text);

            lote.PrecioVentaUnidad   = nuevoPrecioVenta;
            lote.UnidadesDisponibles = nuevoUnidadesDisponibles;

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

            MessageBox.Show("Tarea completada", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            LimpiarForm();
        }
Ejemplo n.º 7
0
        private void ventas_dtgv_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // Columna precio de venta.
            if (e.ColumnIndex == 3)
            {
                var precioVenta = e.FormattedValue.ToString();
                if (Ayudantes.EsDecimalNoNegativo(precioVenta) == false)
                {
                    e.Cancel = true;
                    MessageBox.Show("Precio de venta inválido", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                var venta = ((VentaModelo)ventas_dtgv.Rows[e.RowIndex].DataBoundItem);
                venta.PrecioVentaUnidad = decimal.Parse(e.FormattedValue.ToString());
                CalcularTotal();
            }

            // Columna unidades.
            else if (e.ColumnIndex == 4)
            {
                var stringUnidadesAVender = e.FormattedValue.ToString();
                if (Ayudantes.EsEnteroPositivo(stringUnidadesAVender) == false)
                {
                    e.Cancel = true;
                    MessageBox.Show($"Cantidad solicitada de unidades inválida.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                var venta = ((VentaModelo)ventas_dtgv.Rows[e.RowIndex].DataBoundItem);
                var intUnidadesAVender = uint.Parse(stringUnidadesAVender);

                if (intUnidadesAVender > venta.Lote.UnidadesDisponibles)
                {
                    e.Cancel = true;
                    MessageBox.Show($"Cantidad solicitada de unidades inválida. Solo { venta.Lote.UnidadesDisponibles } unidades disponibles.", "Cantidad insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                venta.Unidades = intUnidadesAVender;
                CalcularTotal();
            }
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        private void CalcularInversionPorUnidad()
        {
            inversion_unidad_tb.Text = "N/A";

            if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false)
            {
                return;
            }
            if (Ayudantes.EsDecimalNoNegativo(inversion_total_tb.Text) == false)
            {
                return;
            }

            int unidades = int.Parse(unidades_tb.Text);

            if (unidades == 0)
            {
                return;
            }

            decimal inversion = decimal.Parse(inversion_total_tb.Text);

            inversion_unidad_tb.Text = (inversion / unidades).ToString();
        }
Ejemplo n.º 10
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();
        }