protected void CalcularLinkButton_Click(object sender, EventArgs e)
        {
            List <CuotasDetalle> listaCuotas = new List <CuotasDetalle>();
            int     tiempo = Utils.ToInt(TiempoTextBox.Text);
            decimal tasaInters = Utils.ToDecimal(InteresTextBox.Text) / 100;
            decimal montoCapital = Utils.ToDecimal(CapitalTextBox.Text);
            decimal capital = Utils.ToDecimal(CapitalTextBox.Text) / tiempo;
            decimal pago = 0, balanceAnt = 0, totalIntere = 0;


            for (int i = 1; i <= tiempo; i++)
            {
                CuotasDetalle c = new CuotasDetalle();
                c.NoCuota = i;
                c.Interes = decimal.Round(capital * tasaInters, 2);
                c.Capital = decimal.Round(capital, 2);
                pago      = decimal.Round(capital + c.Interes, 2);
                if (i == 1)
                {
                    c.Balance  = decimal.Round((tasaInters * montoCapital) + (montoCapital - pago), 2);
                    balanceAnt = c.Balance;
                }

                else
                {
                    c.Balance  = decimal.Round(balanceAnt - pago, 2);
                    balanceAnt = c.Balance;
                }
                totalIntere += c.Interes;

                listaCuotas.Add(c);
                ViewState["PrestamosDetalles"] = listaCuotas;
            }

            InteresTotalTextBox.Text = totalIntere.ToString();
            CapitalTotalTextBox.Text = (montoCapital + totalIntere).ToString();
            CuotaGridView.DataSource = listaCuotas;
            CuotaGridView.DataBind();



            /*int id = 0;
             * PrestamoRepositorio repositorio = new PrestamoRepositorio();
             *
             * if (IdTextBox.Text == string.Empty)
             *  ViewState["PrestamosDetalles"] = repositorio.CalcularCuotas(Utils.ToInt(TiempoTextBox.Text), Utils.ToDouble(CapitalTextBox.Text), (Utils.ToDouble(InteresTextBox.Text)) / 100 / 12);
             * else
             *  ViewState["PrestamosDetalles"] = repositorio.CalcularCuotasModificadas((List<CuotasDetalle>)ViewState["PrestamosDetalles"], id, Utils.ToInt(TiempoTextBox.Text), Utils.ToDouble(CapitalTextBox.Text), (Utils.ToDouble(InteresTextBox.Text) / 100 / 12));
             * CuotaGridView.DataSource = ViewState["PrestamosDetalles"];
             * CuotaGridView.DataBind();*/
        }
示例#2
0
        protected void CalcularButton_Click(object sender, EventArgs e)
        {
            CuotasDetalle        cuotas         = new CuotasDetalle();
            List <CuotasDetalle> cuotasDetalles = new List <CuotasDetalle>();

            decimal interes, capital, montoPagar;
            int     meses;

            interes = Utils.ToDecimal(InteresTextBox.Text) / 100;
            capital = Utils.ToDecimal(CapitalTextBox.Text);
            meses   = Utils.ToInt(TiempoMesesTextBox.Text);

            for (int i = 0; i < Utils.ToInt(TiempoMesesTextBox.Text); i++)
            {
                cuotas.Interes       = interes * capital / meses;
                cuotas.Capital       = capital / meses;
                cuotas.MontoPorCuota = cuotas.Interes + cuotas.Capital;

                montoPagar = cuotas.Interes * meses + capital;
                TotalARetornarTextBox.Text = montoPagar.ToString();
                if (i == 0)
                {
                    cuotas.BCE = montoPagar - (cuotas.Interes + cuotas.Capital);
                }
                else
                {
                    cuotas.BCE = cuotas.BCE - (cuotas.Interes + cuotas.Capital);
                }
                if (i == 0)
                {
                    cuotasDetalles.Add(new CuotasDetalle(0, Utils.ToInt(PrestamoIdTextBox.Text), Utils.ToInt(CuentaIdDropDownList.Text), cuotas.Fecha, Math.Round(cuotas.Interes, 2), Math.Round(cuotas.Capital, 2), Math.Round(cuotas.MontoPorCuota, 2), Math.Round(cuotas.BCE, 2)));
                }
                else
                {
                    cuotasDetalles.Add(new CuotasDetalle(0, Utils.ToInt(PrestamoIdTextBox.Text), Utils.ToInt(CuentaIdDropDownList.SelectedValue), cuotas.Fecha.AddMonths(i), Math.Round(cuotas.Interes, 2), Math.Round(cuotas.Capital, 2), Math.Round(cuotas.MontoPorCuota, 2), Math.Round(cuotas.BCE, 2)));
                }

                ViewState["CuotasDetalle"] = cuotasDetalles;
                DatosGridView.DataSource   = ViewState["CuotasDetalle"];
                DatosGridView.DataBind();
            }
        }