EntrepotEtablissement.cs 14 KB

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