| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data;
- using System.Data.SqlClient;
- using CG67.FicheCollege.Domaine;
- using CG67.FicheCollege.Interface;
- namespace CG67.FicheCollege.Entrepot
- {
- public class EntrepotContact : EntrepotBase, IEntrepotContact
- {
- public IList<Contact> GetAllContactByCodeRNE(string codeRNE)
- {
- IList<Contact> resultat = GetByCodeRNE(codeRNE);
- Contact cg = GetConseillerGeneralByRNE(codeRNE);
- if (cg != null)
- resultat.Add(cg);
- Contact cg1 = GetConseillerGeneralSuppleantByRNE(codeRNE);
- if (cg1 != null)
- resultat.Add(cg1);
- return resultat;
- }
- public IList<Contact> GetByCodeRNE(string codeRNE)
- {
- IList<Contact> resultat = new List<Contact>();
- using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
- {
- try
- {
- connexion.Open();
- using (SqlCommand command = connexion.CreateCommand())
- {
- // command.CommandText = "SELECT * FROM Contact WHERE CodeRNE = @RNE";
- command.CommandText = "SELECT * FROM Contact INNER JOIN Fonction ON Contact.IdFonction = Fonction.Id WHERE (CodeRNE = @RNE)";
- command.Parameters.AddWithValue("@RNE", codeRNE);
- using (SqlDataReader dr = command.ExecuteReader())
- {
- while (dr.Read())
- {
- resultat.Add(new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(), dr["TypeContact"].ToString(), dr["Email"].ToString()));
- }
- }
- }
- }
- catch
- {
- throw;
- }
- finally
- {
- if (connexion.State == ConnectionState.Open)
- connexion.Close();
- }
- }
- return resultat;
- }
- public Contact GetConseillerGeneralByRNE(string codeRNE)
- {
- Contact resultat = null;
- using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
- {
- try
- {
- connexion.Open();
- using (SqlCommand command = connexion.CreateCommand())
- {
- //command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
- command.CommandText = "SELECT * FROM Contact, Fonction WHERE (IdFonction = Fonction.Id) and Contact.id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
- command.Parameters.AddWithValue("@RNE", codeRNE);
- using (SqlDataReader dr = command.ExecuteReader())
- {
- if (dr.Read())
- {
- resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), dr["Libelle"].ToString(), dr["TypeContact"].ToString(), dr["Email"].ToString());
- }
- }
- }
- }
- catch
- {
- throw;
- }
- finally
- {
- if (connexion.State == ConnectionState.Open)
- connexion.Close();
- }
- return resultat;
- }
- }
-
- public Contact GetConseillerGeneralSuppleantByRNE(string codeRNE)
- {
- Contact resultat = null;
- using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
- {
- try
- {
- connexion.Open();
- using (SqlCommand command = connexion.CreateCommand())
- {
- //command.CommandText = "SELECT * FROM Contact WHERE id = (select idConseillerGeneral from etablissement where codeRNE=@RNE)";
- command.CommandText = "SELECT * FROM Contact, Fonction WHERE (IdFonction = Fonction.Id) and Contact.id = (select IdSuppleant from etablissement where codeRNE=@RNE)";
- command.Parameters.AddWithValue("@RNE", codeRNE);
- string sup="suppleant";
- using (SqlDataReader dr = command.ExecuteReader())
- {
- if (dr.Read())
- {
- resultat = new Contact(dr["Civilite"].ToString(), dr["Nom"].ToString(), dr["Prenom"].ToString(), sup, dr["TypeContact"].ToString(), dr["Email"].ToString());
- }
- }
- }
- }
- catch
- {
- throw;
- }
- finally
- {
- if (connexion.State == ConnectionState.Open)
- connexion.Close();
- }
- return resultat;
- }
- }
- }
- }
|