コード例 #1
0
        /*private void contarResultados()
         * {
         *  lblCantResultados.Text = $"Mostrandose: {dgvListados.Rows.Count} abonados.";
         * }*/

        private void guardaPegueEditado()
        {
            string[] fechaEstadoPegue;

            string nombres              = txtNombreTab2.Text;
            string apellidos            = txtApellidosTab2.Text;
            string numIdentidad         = txtNumeroIdentidadTab2.Text;
            string bloque               = numBloque.Value.ToString();
            string casa                 = numCasa.Value.ToString();
            string tipoPegueNombre      = cboTipoPegue.Text;
            int    tipoPegueID          = cboTipoPegue.SelectedIndex + 1;
            string estadoPegueNombre    = cboEstado.Text;
            int    estadoPegueID        = cboEstado.SelectedIndex + 1;
            int    cantidadMesesPagados = Convert.ToInt32(lblCantMesesPagados.Text);
            string codPegue             = lblCodPegue.Text;
            int    abonadoId            = Convert.ToInt32(lblIdAbonado.Text);
            string nota                 = txtNota.Text;

            string mesEstado;
            string yearEstado;
            int    mesEstadoID;


            pgbPorcentajeAlmacenado.Enabled = true;
            pgbPorcentajeAlmacenado.Visible = true;
            pgbPorcentajeAlmacenado.Value   = 25;


            string numeroIdentidad       = DataAbonadoAccess.obtenerNumIdentidadByID(abonadoId);
            int    idTipoPegue           = DataAbonadoAccess.obtenerTipoPegueIDPorNombre(tipoPegueNombre);
            int    idEstadoPegue         = DataAbonadoAccess.obtenerEstadoPegueIDPorNombre(estadoPegueNombre);
            bool   tieneFechaEstadoPegue = DataAbonadoAccess.existeFechaEstadoPegue(codPegue);

            if (tieneFechaEstadoPegue)
            {
                fechaEstadoPegue = DataAbonadoAccess.obtenerMesDeFechaControlPegue(codPegue);
                mesEstado        = cboMesEstado.Text;
                yearEstado       = numYearEstado.Value.ToString();
                mesEstadoID      = cboMesEstado.SelectedIndex + 1;

                pgbPorcentajeAlmacenado.Value = 50;

                if (Convert.ToInt32(fechaEstadoPegue[4]) != estadoPegueID)
                {
                    if (estadoPegueID == 0)
                    {
                        DataAbonadoAccess.eliminarFechaEstadoPegue(codPegue);
                    }
                    else
                    {
                        DataAbonadoAccess.eliminarFechaEstadoPegue(codPegue);
                        guardarFechaEstadoPegue(estadoPegueID, mesEstadoID, codPegue, yearEstado);
                    }
                }
            }
            else
            {
                mesEstado   = cboMesEstado.Text;
                yearEstado  = numYearEstado.Value.ToString();
                mesEstadoID = cboMesEstado.SelectedIndex + 1;
                guardarFechaEstadoPegue(estadoPegueID, mesEstadoID, codPegue, yearEstado);
            }



            if (cantidadMesesPagados < lsbMeses.Items.Count)
            {
                cantidadMesesPagados = (cantidadMesesPagados == 0) ? 1 : cantidadMesesPagados;
                for (int i = cantidadMesesPagados; i <= lsbMeses.Items.Count; i++)
                {
                    guardarControlPago(codPegue, i);
                }
                pgbPorcentajeAlmacenado.Value = 75;
            }

            DataAbonadoAccess.actualizarPegue(codPegue, casa, tipoPegueID, estadoPegueID, Convert.ToInt32(bloque), nota);
            pgbPorcentajeAlmacenado.Value = 100;

            pgbPorcentajeAlmacenado.Visible = false;
            pgbPorcentajeAlmacenado.Value   = 0;
            resetearPegue();
            resetearAbonadoEnPegue();

            MessageBox.Show($"Pegue de {nombres} {apellidos} actualizado correctamente", "Pegue", MessageBoxButtons.OK);

            seleccionarPanelListados();
        }