1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Common;
namespace DAL
{
public class PersonProvider
{
private static PersonProvider s_Instance;
private static object s_InstanceLocker = new object();
// Singleton
public static PersonProvider Instance
{
get
{
lock (s_InstanceLocker)
{
if (s_Instance == null)
{
s_Instance = new PersonProvider();
}
return s_Instance;
}
}
}
public List<PersonEntity> LoadData()
{
List<PersonEntity> list = null;
using (DbConnection cn = Sql.Instance.GetSqlConnection())
{
using (System.Data.Common.DbCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "Select * from [VW_PERSONNEL]";
cmd.Connection = cn;
using (System.Data.Common.DbDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (list == null)
{
list = new List<PersonEntity>();
}
PersonEntity p = new PersonEntity();
p.Id = rdr["ID"] == DBNull.Value ? string.Empty : rdr["ID"].ToString();
p.Nom = rdr["NOM"] == DBNull.Value ? string.Empty : rdr["NOM"].ToString();
p.Prenom = rdr["PRENOM"] == DBNull.Value ? string.Empty : rdr["PRENOM"].ToString();
list.Add(p);
}
}
}
}
return list;
}
}
} |