예제 #1
0
        public void CargarPrestamosCuotas(string prestamo)
        {
            // INSTANCIAS
            Prestamos_CuotasCL oPrestamosCuotas = new Prestamos_CuotasCL();

            Abonos_CuotasCL oAbonosCuotas = new Abonos_CuotasCL();

            // TRAE LAS CUOTAS DE LOS PRESTAMOS
            DataSet oDatos = oPrestamosCuotas.TraerPrestamoCuotas(prestamo);

            // ASIGNA LOS DATOS AL DATAGRID DE CUOTAS
            dtgCuotas.DataSource = oDatos.Tables[0];

            // CICLO QUE REVISA LAS FILAS DEL DATAGRID DE CUOTAS
            foreach (DataGridViewRow row in dtgCuotas.Rows)
            {
                if (Convert.ToBoolean(row.Cells["pago"].Value.ToString()) == true)
                {
                    // ESTABLECE COLOR VERDE SI LA COLUMNA PAGO ESTA CON CHECK
                    row.DefaultCellStyle.BackColor = Color.LightGreen;
                }
                else
                {
                    // ESTABLECE COLOR SALMON SI LA COLUMNA PAGO ESTA SIN CHECK
                    row.DefaultCellStyle.BackColor = Color.Salmon;
                }

                // TRAE LOS ABONOS DE UNA CUOTA
                DataSet oDatosAbonos = oAbonosCuotas.TraerAbono_Cuotas(row.Cells["id"].Value.ToString());

                // CALCULA LA CANTIDAD DE ABONOS
                int cantidadAbonos = Convert.ToInt32(oDatosAbonos.Tables[0].Rows.Count);

                // COMPRUEBA LA CANTIDAD
                if (cantidadAbonos > 0)
                {
                    // ESTABLECE EL TEXTO DEL BOTON DE ABONOS
                    row.Cells["abonos"].Value = "Abonos";
                }
                else
                {
                    // CAMBIA EL TIPO DE COLUMNA A TEXTO
                    row.Cells["abonos"]       = new DataGridViewTextBoxCell();
                    row.Cells["abonos"].Value = "";
                }
            }

            // LLAMA AL METODO QUE ORDENA LAS COLUMNAS
            OrdenColumnas();
        }
예제 #2
0
        // VALIDA SI LAS CUOTAS YA HAN SIDO PAGADAS
        public bool ValidarPago()
        {
            Prestamos_CuotasCL oCuotas = new Prestamos_CuotasCL();

            errores = "";

            int    cont_cuotas_pagadas       = 0;
            int    diferencia_cuotas_pagadas = 0;
            int    cont_cuotas_pendientes    = 0;
            string errores_coutas_pagadas    = "Las siguientes cuotas ya han sido pagadas:";
            string errores_coutas_pendientes = "\nLos siguientes prestamos tienen cuotas pendientes: ";

            var prestamos = dtgPrestamosCuotas.Rows.Cast <DataGridViewRow>().GroupBy(r => r.Cells["Prestamo"].Value);

            foreach (var prestamo in prestamos)
            {
                cont_cuotas_pagadas       = 0;
                diferencia_cuotas_pagadas = 0;
                cont_cuotas_pendientes    = 0;

                int idPrestamo = Convert.ToInt32(prestamo.Key);

                DataTable cuotas_prestamo = oCuotas.TraerPrestamoCuotas(idPrestamo.ToString()).Tables[0];

                var cuotas = prestamo.ToList();

                DataGridViewRow primer_row = prestamo.First();

                // PRIMER COUTA DE LA PLANILLA DEL RESPECTIVO PRESTAMO

                string primer_cuota = primer_row.Cells["Numero_cuota"].Value.ToString();

                // RECORRE LAS CUOTAS PARA CALCULAR LA DIFERENCIA DE CUOTAS NO PAGADAS

                foreach (DataRow cuota_prestamo in cuotas_prestamo.Rows)
                {
                    string cuota = cuota_prestamo["num_cuota"].ToString();

                    if (cuota == primer_cuota)
                    {
                        break;
                    }

                    if (Convert.ToBoolean(cuota_prestamo["pago"]) == false)
                    {
                        diferencia_cuotas_pagadas++;
                    }
                }


                // CORROBORA ESTADO DE COUTAS YA PAGADAS

                if (diferencia_cuotas_pagadas > 0)
                {
                    cont_cuotas_pendientes++;
                    string pendienteTexto = diferencia_cuotas_pagadas > 1 ? "pendientes" : "pendiente";
                    string cuotaTexto     = diferencia_cuotas_pagadas > 1 ? "cuotas" : "cuota";

                    errores_coutas_pendientes += String.Format("\nEl prestamo {0} tiene {1} {2} {3}", idPrestamo, diferencia_cuotas_pagadas, cuotaTexto, pendienteTexto);
                }

                // CORROBORA ESTADO DE COUTAS YA PAGADAS

                foreach (DataGridViewRow cuota in cuotas)
                {
                    foreach (DataRow cuota_prestamo in cuotas_prestamo.Rows)
                    {
                        if (Convert.ToBoolean(cuota_prestamo["pago"]) == true && cuota_prestamo["num_cuota"].ToString() == cuota.Cells["Numero_cuota"].Value.ToString())
                        {
                            cont_cuotas_pagadas++;
                            errores_coutas_pagadas += "\n" + "La cuota numero " + cuota.Cells["Numero_cuota"].Value.ToString() + " del prestamo " + cuota.Cells["Prestamo"].Value.ToString();
                        }
                    }
                }


                errores += cont_cuotas_pagadas > 0 ? errores_coutas_pagadas : "";
                errores += cont_cuotas_pendientes > 0 ? errores_coutas_pendientes : "";
            }

            if (errores != "")
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }