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;

using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

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

	public void Update(CompteDataObject row)
	{
		// ... Update SQL
	}

	public void Delete(CompteDataObject row)
	{
		// ... Delete SQL
	}

	public void Insert(CompteDataObject new_row)
	{
		// ... Insert SQL
	}

	public List<CompteDataObject> GetAll()
	{
		SqlConnection cx=null;
		List<CompteDataObject> liste = new List<CompteDataObject>();
		try
		{
			string cs;
			cs = ConfigurationManager.ConnectionStrings["bancaConnectionString"].ConnectionString;
			cx = new SqlConnection(cs);

			// tous les enregistrements de la table compte
			string rq = "select * from compte";
			SqlCommand sql = new SqlCommand(rq, cx);
			cx.Open();
			SqlDataReader reader = sql.ExecuteReader();
			while (reader.Read())
			{
				// converir chaque ligne en objet
				CompteDataObject row = new CompteDataObject();
				row.Id_compte = (int) reader["id_compte"];
				row.Titulaire = (string)reader["titulaire"];
				row.Solde = (decimal)reader["solde"];
				
				// ajouter à la liste
				liste.Add(row);
			}
			reader.Close();
		}
		catch(Exception err)
		{
			throw err;
		}
		finally
		{
			if (cx != null)
				cx.Close();
		}
		return liste;
	}
}
