EntrepotEtablissement.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Data.OracleClient;
  7. using System.Data.OleDb;
  8. using CG67.FicheCollege.Domaine;
  9. using CG67.FicheCollege.Interface;
  10. namespace CG67.FicheCollege.Entrepot
  11. {
  12. public class EntrepotEtablissement : EntrepotBase, IEntrepotEtablissement
  13. {
  14. public IList<Etablissement> GetAll()
  15. {
  16. IList<Etablissement> resultat = new List<Etablissement>();
  17. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  18. {
  19. try
  20. {
  21. connexion.Open();
  22. using (SqlCommand command = connexion.CreateCommand())
  23. {
  24. command.CommandText = "Select Etablissement.CodeRNE, Etablissement.NomCollege, Adresse.Ville from Etablissement LEFT JOIN Adresse ON (Etablissement.IdAdresse = Adresse.Id) ORDER BY Adresse.Ville, Etablissement.NomCollege ASC";
  25. using (SqlDataReader dr = command.ExecuteReader())
  26. {
  27. while (dr.Read())
  28. {
  29. resultat.Add(new Etablissement(dr["CodeRNE"].ToString(), dr["NomCollege"].ToString(), dr["Ville"].ToString()));
  30. }
  31. }
  32. }
  33. }
  34. catch
  35. {
  36. throw;
  37. }
  38. finally
  39. {
  40. if (connexion.State == ConnectionState.Open)
  41. connexion.Close();
  42. }
  43. }
  44. return resultat;
  45. }
  46. public Etablissement GetByCodeRNEAndAnnee(string codeRNE, int annee)
  47. {
  48. Etablissement resultat = null;
  49. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  50. {
  51. try
  52. {
  53. connexion.Open();
  54. using (SqlCommand command = connexion.CreateCommand())
  55. {
  56. command.CommandText = "Select * from Etablissement LEFT JOIN Adresse ON (Etablissement.IdAdresse = Adresse.Id) WHERE Etablissement.CodeRNE = @RNE";
  57. command.Parameters.AddWithValue("@RNE", codeRNE);
  58. command.Parameters.AddWithValue("@Annee", annee);
  59. using (SqlDataReader dr = command.ExecuteReader())
  60. {
  61. if (dr.Read())
  62. {
  63. string adresse;
  64. if (dr["NumRue"].ToString()!="")
  65. {
  66. adresse = dr["NumRue"].ToString() + ", " + dr["TypeDeVoie"].ToString() + " " + dr["Voie"].ToString();
  67. }
  68. else
  69. {
  70. adresse = dr["TypeDeVoie"].ToString() + " " + dr["Voie"].ToString();
  71. }
  72. string a = dr["DemiPension"].ToString();
  73. resultat = new Etablissement(codeRNE, annee, dr["NomCollege"].ToString(),
  74. dr["TypeEtablissement"].ToString(), Convert.ToInt16(dr["AnneeConstruction"].ToString()),
  75. dr["Telephone"].ToString(), dr["Email"].ToString(), dr["Fax"].ToString(),
  76. dr["NomPropriétaire"].ToString(), adresse, dr["ComplementAdresse"].ToString(),
  77. Convert.ToInt32(dr["CodePostal"].ToString()), dr["Ville"].ToString(), dr["LienPhoto"].ToString(),
  78. dr.GetBoolean(dr.GetOrdinal("DemiPension")), dr.GetBoolean(dr.GetOrdinal("Internat")), int.Parse(dr["CapaciteTheorique"].ToString()),
  79. EntrepotFactory.GetEntrepotActionEducative().GetByCodeRNEAndAnnee,
  80. EntrepotFactory.GetEntrepotClasseDecouverte().GetByCodeRNEAndAnnee,
  81. EntrepotFactory.GetEntrepotATC().GetByCodeRNE,
  82. EntrepotFactory.GetEntrepotContratAide().GetByCodeRNE,
  83. EntrepotFactory.GetEntrepotBilinguisme().GetByCodeRNEAndAnnee,
  84. EntrepotFactory.GetEntrepotCommentaires().GetByCodeRNEAndAnnee,
  85. EntrepotFactory.GetEntrepotContact().GetAllContactByCodeRNE,
  86. EntrepotFactory.GetEntrepotDotation().GetByCodeRNEAndAnnee,
  87. EntrepotFactory.GetEntrepotEquipement().GetByCodeRNEAndAnnee,
  88. EntrepotFactory.GetEntrepotInvestissement().GetByCodeRNEAndAnnee,
  89. EntrepotFactory.GetEntrepotEffectifDetail().GetByCodeRNEAndAnnee,
  90. EntrepotFactory.GetEntrepotMCG().GetByCodeRNE,
  91. EntrepotFactory.GetEntrepotLogement().GetByCodeRNE,
  92. EntrepotFactory.GetEntrepotProgTravaux().GetByCodeRNEAndAnnee,
  93. EntrepotFactory.GetEntrepotProjetPilote().GetByCodeRNEAndAnnee,
  94. EntrepotFactory.GetEntrepotRestauration().GetByRNEAndAnnee);
  95. }
  96. }
  97. // liste chargées d'office. pourquoi ?
  98. command.CommandText = "SELECT * FROM EtpTheorique WHERE CodeRNE = @RNE AND Annee = @Annee";
  99. using (SqlDataReader dr2 = command.ExecuteReader())
  100. {
  101. if (dr2.Read())
  102. {
  103. resultat.ValeurETPTheorique = Convert.ToInt32(dr2["Valeur"].ToString());
  104. }
  105. }
  106. command.CommandText = "SELECT * from SecteurRecrutement WHERE CodeRNE = @RNE and Annee=@annee order by libelle";
  107. using (SqlDataReader dr7 = command.ExecuteReader())
  108. {
  109. IList<EtablissementRecrutement> lstSecteurRecrut = new List<EtablissementRecrutement>();
  110. while (dr7.Read())
  111. {
  112. lstSecteurRecrut.Add(new EtablissementRecrutement(dr7["Libelle"].ToString()));
  113. }
  114. resultat.LstSecteurRecrutement = lstSecteurRecrut;
  115. }
  116. command.CommandText = "SELECT * FROM Reserve WHERE CodeRNE = @RNE AND Annee = @Annee";
  117. using (SqlDataReader dr3 = command.ExecuteReader())
  118. {
  119. if (dr3.Read())
  120. {
  121. resultat.Reserve = Convert.ToInt32(dr3["Montant"].ToString());
  122. }
  123. }
  124. command.CommandText = "SELECT Annee, TypeDonnees,EffectifTotal FROM EffectifTotal WHERE CodeRNE = @RNE AND TypeClasses = @typeclasses AND Annee > @AnneeMoins10 ORDER BY Annee ASC";
  125. command.Parameters.AddWithValue("@AnneeMoins10", annee - 10);
  126. command.Parameters.AddWithValue("@typeclasses", "Normal");
  127. using (SqlDataReader dr4 = command.ExecuteReader())
  128. {
  129. resultat.LstEffectif = new List<Effectif>();
  130. IList<Effectif> lstEffectifReel = new List<Effectif>();
  131. while (dr4.Read())
  132. {
  133. lstEffectifReel.Add(new Effectif(dr4["Annee"].ToString(),dr4["TypeDonnees"].ToString(), Convert.ToInt32(dr4["EffectifTotal"].ToString())));
  134. }
  135. foreach (Effectif e in lstEffectifReel)
  136. {
  137. if (e.TypeEffectif == "R")
  138. resultat.LstEffectif.Add(e);
  139. }
  140. foreach (Effectif e in lstEffectifReel)
  141. {
  142. bool trouve = false;
  143. if (e.TypeEffectif == "P")
  144. {
  145. foreach (Effectif e1 in resultat.LstEffectif)
  146. if (e1.Annee == e.Annee)
  147. trouve = true;
  148. if (!trouve)
  149. resultat.LstEffectif.Add(e);
  150. }
  151. }
  152. }
  153. command.CommandText = "SELECT * from Restructuration WHERE CodeRNE = @RNE";
  154. using (SqlDataReader dr6 = command.ExecuteReader())
  155. {
  156. IList<int> lstRestructuration = new List<int>();
  157. while (dr6.Read())
  158. {
  159. lstRestructuration.Add(Convert.ToInt32(dr6["Annee"].ToString()));
  160. }
  161. resultat.LstRestructuration = lstRestructuration;
  162. }
  163. command.CommandText = "SELECT * from Remplacement INNER JOIN ATC ON (ATC.Id = Remplacement.IdATCRemplace) INNER JOIN Contact ON (ATC.Id = Contact.Id) WHERE CodeRNE = @RNE AND Remplacement.DateDebut + DureeEnSemaine >= GETDATE()";
  164. using (SqlDataReader dr8 = command.ExecuteReader())
  165. {
  166. int nbrRemplacements = 0;
  167. while (dr8.Read())
  168. {
  169. nbrRemplacements++; ;
  170. }
  171. resultat.NbrRemplacementsATC = nbrRemplacements;
  172. }
  173. }
  174. }
  175. catch (Exception erreur)
  176. {
  177. throw erreur;
  178. }
  179. finally
  180. {
  181. if (connexion.State == ConnectionState.Open)
  182. connexion.Close();
  183. }
  184. }
  185. resultat.Surface = 0;
  186. using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion))
  187. {
  188. try
  189. {
  190. connexion.Open();
  191. using (SqlCommand command = connexion.CreateCommand())
  192. {
  193. command.CommandText= "select superficie from dbo.Surface where codeRNE =@RNE AND ANNEE = @ANNEE ";
  194. command.Parameters.AddWithValue("@RNE", codeRNE);
  195. command.Parameters.AddWithValue("@ANNEE", annee);
  196. using (SqlDataReader dr9 = command.ExecuteReader())
  197. if (dr9.Read())
  198. {
  199. resultat.Surface = Convert.ToDouble(dr9["superficie"].ToString());
  200. }
  201. }
  202. }
  203. catch
  204. {
  205. throw;
  206. }
  207. finally
  208. {
  209. if (connexion.State == ConnectionState.Open)
  210. connexion.Close();
  211. }
  212. }
  213. //using (OracleConnection connexion = new OracleConnection(this.ChaineDeConnexion))
  214. //{
  215. // try
  216. // {
  217. // connexion.Open();
  218. // using (OracleCommand command = connexion.CreateCommand())
  219. // {
  220. // command.CommandText = "SELECT Sum(Externat_Enseignementgeneral + Externat_Labochimie_sciencenat + Externat_Labophysique + Externat_Salleinformatique + Externat_Batimentsdemontables + Externat_Administration + Gymnaseatelier_Gymnases + Gymnaseatelier_Ateliers + Restauration_internats_internats + Restauration_internats_Restauration + Logements_et_exterieur_Logements + Logements_et_exterieur_Autres + Logements_et_exterieur_Logautres + Logements_et_exterieur_Cours + Logements_et_exterieur_Parkings + Logements_et_exterieur_Espacesverts + Logements_et_exterieur_Airessportives + Logements_et_exterieur_Consouvertes) as SurfaceTotale FROM [T_EDL Surfaces données du rectorat] LEFT JOIN T_COLLEGE ON ([T_EDL Surfaces données du rectorat].Lien_T_College = T_COLLEGE.REF_COLLEGE) WHERE T_COLLEGE.CODE_COLLEGE = :RNE";
  221. // command.Parameters.AddWithValue(":RNE", codeRNE);
  222. // using (OracleDataReader reader = command.ExecuteReader())
  223. // {
  224. // if (reader.Read())
  225. // {
  226. // resultat.Surface = Convert.ToDouble(reader["SurfaceTotale"].ToString());
  227. // }
  228. // }
  229. // }
  230. // }
  231. // catch
  232. // {
  233. // throw;
  234. // }
  235. // finally
  236. // {
  237. // if (connexion.State == ConnectionState.Open)
  238. // connexion.Close();
  239. // }
  240. //}
  241. return resultat;
  242. }
  243. }
  244. }