Exemplo n.º 1
0
        protected void CalcularButton_Click(object sender, EventArgs e)
        {
            ViewState["Prestamos"] = new Prestamos();
            this.BindGrid();


            PrestamoRepositorio repositorio = new PrestamoRepositorio();
            Prestamos           prestamo    = new Prestamos();
            PrestamoDetalles    cuota       = new PrestamoDetalles();



            int      fila  = Utilidades.util.ToInt(TiempoTextBox.Text);
            DateTime fecha = Convert.ToDateTime(FechaTextBox.Text);


            decimal interes = Utilidades.util.ToDecimal(InteresTextBox.Text);
            int     tiempo  = Utilidades.util.ToInt(TiempoTextBox.Text);
            decimal capital = Utilidades.util.ToDecimal(CapitalTextBox.Text);

            BalanceTextBox.Text = repositorio.BalanceCuota(capital, interes).ToString();

            if (ValidacionIT(interes, tiempo, capital) == true)
            {
                return;
            }

            interes /= 100;

            for (int i = 1; i <= fila; i++)
            {
                cuota.Interes = (interes * capital) / tiempo;
                cuota.Capital = capital / tiempo;

                decimal monto = (cuota.Interes * tiempo) + capital;
                if (i == 1)
                {
                    cuota.Balance = monto - (cuota.Interes + cuota.Capital);
                }
                else
                {
                    cuota.Balance = cuota.Balance - (cuota.Capital + cuota.Interes);
                }



                prestamo = (Prestamos)ViewState["Prestamos"];


                prestamo.AgregarDetalle(0, Utilidades.util.ToInt(PrestamoidTextBox.Text), i, cuota.Fecha.AddMonths(i), Math.Round(cuota.Interes, 2), Math.Round(cuota.Capital, 2), Math.Round(cuota.Balance, 2));

                ViewState["Prestamos"] = prestamo;


                this.BindGrid();
            }

            BalanceTextBox.Visible = true;
            Labelbalance.Visible   = true;
        }