using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for SimulationFabrique
/// </summary>
public class SimulationFabrique
{
	public SimulationFabrique()
	{		
	}	

	public DataSet GetAll(double m, double t, double n)
	{
		double i;
		i = t / (12 * 100);
		n = n * 12; // mois

		double echeance = m * i / (1 - Math.Pow(1 + i, -n));
		DataSet ds = new DataSet();
		DataTable dt = new DataTable("Simulation");
		dt.Columns.Add("Numéro", typeof(int));
		dt.Columns.Add("Echéance", typeof(double));
		dt.Columns.Add("Intérêts", typeof(double));
		dt.Columns.Add("Capital", typeof(double));

		for (int j = 0; j < n; j++)
		{
			double interets;
			interets = m * i;
			m = m - (echeance - interets);
			DataRow dr = dt.NewRow();
			dr["Numéro"] = j + 1;
			dr["Echéance"] = echeance;
			dr["Intérêts"] = interets;
			dr["Capital"] = m;

			dt.Rows.Add(dr);
		}

		ds.Tables.Add(dt);
		return ds;
	}
}
