EntrepotEtablissement.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Oracle.DataAccess.Client;
  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 (Exception erreurInterne)
  35. {
  36. throw new Exception(" " + erreurInterne);
  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 = dr["NumRue"].ToString() + ", " + dr["TypeDeVoie"].ToString() + " " + dr["Voie"].ToString();
  64. resultat = new Etablissement(codeRNE, annee, dr["NomCollege"].ToString(),
  65. dr["TypeEtablissement"].ToString(), Convert.ToInt16(dr["AnneeConstruction"].ToString()),
  66. dr["Telephone"].ToString(), dr["Email"].ToString(), dr["Fax"].ToString(),
  67. dr["NomPropriétaire"].ToString(), adresse, dr["ComplementAdresse"].ToString(),
  68. Convert.ToInt32(dr["CodePostal"].ToString()), dr["Ville"].ToString(), dr["LienPhoto"].ToString(),
  69. EntrepotFactory.GetEntrepotActionEducative().GetByCodeRNEAndAnnee,
  70. EntrepotFactory.GetEntrepotATC().GetByCodeRNE,
  71. EntrepotFactory.GetEntrepotBilinguisme().GetByCodeRNEAndAnnee,
  72. EntrepotFactory.GetEntrepotCommentaires().GetByCodeRNEAndAnnee,
  73. EntrepotFactory.GetEntrepotContact().GetByCodeRNE,
  74. EntrepotFactory.GetEntrepotDotation().GetByCodeRNEAndAnnee,
  75. EntrepotFactory.GetEntrepotEquipement().GetByCodeRNEAndAnnee,
  76. EntrepotFactory.GetEntrepotInvestissement().GetByCodeRNEAndAnnee,
  77. EntrepotFactory.GetEntrepotMCG().GetByCodeRNE,
  78. EntrepotFactory.GetEntrepotLogement().GetByCodeRNE,
  79. EntrepotFactory.GetEntrepotProgTravaux().GetByCodeRNEAndAnnee,
  80. EntrepotFactory.GetEntrepotProjetPilote().GetByCodeRNEAndAnnee,
  81. EntrepotFactory.GetEntrepotRestauration().GetByRNEAndAnnee);
  82. }
  83. }
  84. command.CommandText = "SELECT * FROM EtpTheorique WHERE CodeRNE = @RNE AND Annee = @Annee";
  85. using (SqlDataReader dr2 = command.ExecuteReader())
  86. {
  87. if (dr2.Read())
  88. {
  89. resultat.ValeurETPTheorique = Convert.ToInt32(dr2["Valeur"].ToString());
  90. }
  91. }
  92. command.CommandText = "SELECT * FROM Reserve WHERE CodeRNE = @RNE AND Annee = @Annee";
  93. using (SqlDataReader dr3 = command.ExecuteReader())
  94. {
  95. if (dr3.Read())
  96. {
  97. resultat.Reserve = Convert.ToInt32(dr3["Montant"].ToString());
  98. }
  99. }
  100. command.CommandText = "SELECT Annee, sum(TotalEleves) as TotalEleves FROM Effectif WHERE CodeRNE = @RNE AND Annee BETWEEN @AnneeMoins10 AND @Annee GROUP BY Annee ORDER BY Annee ASC";
  101. command.Parameters.AddWithValue("@AnneeMoins10", annee - 10);
  102. using (SqlDataReader dr4 = command.ExecuteReader())
  103. {
  104. IList<int> lstEffectifReel = new List<int>();
  105. while (dr4.Read())
  106. {
  107. lstEffectifReel.Add(Convert.ToInt32(dr4["TotalEleves"].ToString()));
  108. }
  109. resultat.LstEffectifReel = lstEffectifReel;
  110. }
  111. command.CommandText = "SELECT Annee, sum(NbEleve) as TotalEleves FROM PrevisionEffectif WHERE CodeRNE = @RNE AND Annee BETWEEN @Annee AND @AnneePlus5 GROUP BY Annee ORDER BY Annee ASC";
  112. command.Parameters.AddWithValue("@AnneePlus5", annee + 5);
  113. using (SqlDataReader dr5 = command.ExecuteReader())
  114. {
  115. IList<int> lstEffectifPrev = new List<int>();
  116. while (dr5.Read())
  117. {
  118. lstEffectifPrev.Add(Convert.ToInt32(dr5["TotalEleves"].ToString()));
  119. }
  120. resultat.LstEffectifPrevisionnel = lstEffectifPrev;
  121. }
  122. command.CommandText = "SELECT * from Restructuration WHERE CodeRNE = @RNE";
  123. using (SqlDataReader dr6 = command.ExecuteReader())
  124. {
  125. IList<int> lstRestructuration = new List<int>();
  126. while (dr6.Read())
  127. {
  128. lstRestructuration.Add(Convert.ToInt32(dr6["Annee"].ToString()));
  129. }
  130. resultat.LstRestructuration = lstRestructuration;
  131. }
  132. command.CommandText = "SELECT * from SecteurRecrutement WHERE CodeRNE = @RNE";
  133. using (SqlDataReader dr7 = command.ExecuteReader())
  134. {
  135. IList<string> lstSecteurRecrut = new List<string>();
  136. while (dr7.Read())
  137. {
  138. lstSecteurRecrut.Add(dr7["Libelle"].ToString());
  139. }
  140. resultat.LstSecteurRecrutement = lstSecteurRecrut;
  141. }
  142. 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()";
  143. using (SqlDataReader dr8 = command.ExecuteReader())
  144. {
  145. int nbrRemplacements = 0;
  146. while (dr8.Read())
  147. {
  148. nbrRemplacements++; ;
  149. }
  150. resultat.NbrRemplacementsATC = nbrRemplacements;
  151. }
  152. }
  153. }
  154. catch (Exception e)
  155. {
  156. throw new Exception(e.ToString());
  157. }
  158. finally
  159. {
  160. if (connexion.State == ConnectionState.Open)
  161. connexion.Close();
  162. }
  163. }
  164. using (OleDbConnection connexion = new OleDbConnection(this.ChaineDeConnexionAccess))
  165. {
  166. try
  167. {
  168. connexion.Open();
  169. using (OleDbCommand command = connexion.CreateCommand())
  170. {
  171. 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";
  172. command.Parameters.AddWithValue("@RNE", codeRNE);
  173. using (OleDbDataReader reader = command.ExecuteReader())
  174. {
  175. if (reader.Read())
  176. {
  177. resultat.Surface = Convert.ToDouble(reader["SurfaceTotale"].ToString());
  178. }
  179. }
  180. }
  181. }
  182. catch
  183. {
  184. throw;
  185. }
  186. finally
  187. {
  188. if (connexion.State == ConnectionState.Open)
  189. connexion.Close();
  190. }
  191. }
  192. return resultat;
  193. }
  194. }
  195. }