EntrepotEtablissement.cs 14 KB

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