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
|
private List<DataRow> GetDomaines()
{
//Initialisation d'une variable Liste contenant des lignes de données où seront récupérés les résultats de la requête suivante.
List<DataRow> liste = null;
//Stockage de la requête pure SQL permettant de récupérer la liste des Traitements, CR, Périodes et Applications avec leur statut en fonction de la période dans une variable de type string.
string query = "select CD_TRT, LB_TRT, CD_CR, LB_CR, PERIODE, PREREQUIS, CD_APPLI, case "
+ "when (exists (select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.STATUT = 'OK' and j.JR_EXEC >= DAY(l.DT_DEB))) "
+ "and not exists (select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.PERIODE = p.PERIODE "
+ "and ((j.JR_EXEC < DAY(l.DT_DEB) and l.DT_DEB is not null) or (l.STATUT in('KO','NEXEC')))) then 'OK' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.PERIODE = p.PERIODE "
+ "and DAY(l.DT_DEB) IS not null and l.STATUT = 'KO')) then 'KO' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.PERIODE = p.PERIODE "
+ "and j.JR_EXEC < DAY(l.DT_DEB) and DAY(l.DT_DEB) IS not null and l.STATUT in('NEXEC'))) then 'EN COURS' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.PERIODE = p.PERIODE and l.STATUT in ('NEXEC','KO') "
+ "and j.JR_EXEC < DAY(l.DT_DEB) and DAY(l.DT_DEB) IS not null)) then 'EN RETARD' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where l.PERIODE = p.PERIODE and l.CD_APPLI = 'ESPAS' and cr.CD_CR = l.CD_CR and j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.PERIODE = p.PERIODE "
+ "and j.JR_EXEC < DAY(l.DT_DEB) and DAY(l.DT_DEB) IS not null)) then 'OK RETARD' "
+ "else 'NON INITIE' end STATUT "
+ "from dbo.REF_TRT t, dbo.REF_CR cr, (select distinct PERIODE from dbo.LOGS) p "
+ "order by t.ORDRE_TRT";
//Création d'une variable de connection où sont stockés toutes les informations nécessaires à la connexion à la base de données.
//Ces informations sont stockées dans le fichier de config Web.config.
string connString = ConfigurationManager.AppSettings["REF_ConnectionString"];
//Création d'un objet instance de SqlConnection (classe permettant la connexion ouverte à une base de données) où est stocké le contenu de la variable connString.
using (SqlConnection conn = new SqlConnection(connString))
{
//Création d'un objet de commande permettant de spécifier comment la commande sera inteprétée, ici en commande de texte SQL avec CommandType.Text.
using (SqlCommand objCommand = new SqlCommand(query, conn))
{
//Création d'un objet de commande permettant de spécifier comment la commande sera inteprétée, ici en commande de texte SQL avec CommandType.Text.
objCommand.CommandType = CommandType.Text;
//Création d'un objet instance de DataTable qui va récupérer la résultat de la requête.
DataTable dt = new DataTable();
//Création d'un objet instance de SqlDataAdapter qui va effectuer le lien avec SQL Server afin de récupérer les données.
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
//Ouverture de la connexion.
conn.Open();
//L'instruction FILL récupère les données de la source de données et les insère dans dt.
adp.Fill(dt);
//Vérification du contenu de dt.
if (dt != null)
{
//Remplissage de la liste.
liste = dt.AsEnumerable().ToList();
}
}
}
//Le résultat est retourné à l'action.
return liste;
} |
Partager