using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.OracleClient; using System.Data.OleDb; using CG67.FicheCollege.Domaine; using CG67.FicheCollege.Interface; namespace CG67.FicheCollege.Entrepot { public class EntrepotEtablissement : EntrepotBase, IEntrepotEtablissement { public IList GetAll() { IList resultat = new List(); using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { connexion.Open(); using (SqlCommand command = connexion.CreateCommand()) { // 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"; 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"; using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { // resultat.Add(new Etablissement(dr["CodeRNE"].ToString(), dr["NomCollege"].ToString(),dr["Commune"].ToString(), dr["Ville"].ToString())); resultat.Add(new Etablissement(dr["CodeRNE"].ToString(), dr["NomCollege"].ToString(), dr["Commune"].ToString())); } } } } catch { throw; } finally { if (connexion.State == ConnectionState.Open) connexion.Close(); } } return resultat; } public Etablissement GetByCodeRNEAndAnnee(string codeRNE, int annee) { Etablissement resultat = null; using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { connexion.Open(); using (SqlCommand command = connexion.CreateCommand()) { command.CommandText = "Select * from Etablissement LEFT JOIN Adresse ON (Etablissement.IdAdresse = Adresse.Id) WHERE Etablissement.CodeRNE = @RNE"; command.Parameters.AddWithValue("@RNE", codeRNE); command.Parameters.AddWithValue("@Annee", annee); using (SqlDataReader dr = command.ExecuteReader()) { if (dr.Read()) { string adresse; if (dr["NumRue"].ToString()!="") { adresse = dr["NumRue"].ToString() + ", " + dr["TypeDeVoie"].ToString() + " " + dr["Voie"].ToString(); } else { adresse = dr["TypeDeVoie"].ToString() + " " + dr["Voie"].ToString(); } string a = dr["DemiPension"].ToString(); resultat = new Etablissement(codeRNE, dr.GetBoolean(dr.GetOrdinal("Prive")), annee, dr["NomCollege"].ToString(), dr["Commune"].ToString(), dr["Canton"].ToString(), dr["TypeEtablissement"].ToString(), Convert.ToInt16(dr["AnneeConstruction"].ToString()), dr["Telephone"].ToString(), dr["Email"].ToString(), dr["Fax"].ToString(), dr["NomPropriétaire"].ToString(), adresse, dr["ComplementAdresse"].ToString(), Convert.ToInt32(dr["CodePostal"].ToString()), dr["Ville"].ToString(), dr["LienPhoto"].ToString(), dr["fichierPPM"].ToString(), dr.GetBoolean(dr.GetOrdinal("DemiPension")), dr.GetBoolean(dr.GetOrdinal("Internat")), dr.GetBoolean(dr.GetOrdinal("Ascenseur")), int.Parse(dr["CapaciteTheorique"].ToString()), EntrepotFactory.GetEntrepotActionEducative().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotClasseDecouverte().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotATC().GetByCodeRNE, EntrepotFactory.GetEntrepotContratAide().GetByCodeRNE, EntrepotFactory.GetEntrepotBilinguisme().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotSoutienScolaireEnLigne().GetByRNEAndAnnee, EntrepotFactory.GetEntrepotCommentaires().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotContact().GetAllContactByCodeRNE, EntrepotFactory.GetEntrepotDotation().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotEquipement().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotInvestissement().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotEffectifDetail().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotMCG().GetByCodeRNE, EntrepotFactory.GetEntrepotLogement().GetByCodeRNE, EntrepotFactory.GetEntrepotProgTravaux().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotProjetPilote().GetByCodeRNEAndAnnee, EntrepotFactory.GetEntrepotRestauration().GetByRNEAndAnnee, EntrepotFactory.GetEntrepotFichiersTravaux().GetByCodeRNE); } } // liste chargées d'office. pourquoi ? // command.CommandText = "SELECT * FROM EtpTheorique WHERE CodeRNE = @RNE AND Annee = @Annee"; // using (SqlDataReader dr2 = command.ExecuteReader()) // { // if (dr2.Read()) // { // resultat.ValeurETPTheorique = Convert.ToInt32(dr2["Valeur"].ToString()); // } // } command.CommandText = "SELECT * from SecteurRecrutement WHERE CodeRNE = @RNE and Annee=@annee order by libelle"; using (SqlDataReader dr7 = command.ExecuteReader()) { IList lstSecteurRecrut = new List(); while (dr7.Read()) { lstSecteurRecrut.Add(new EtablissementRecrutement(dr7["Libelle"].ToString())); } resultat.LstSecteurRecrutement = lstSecteurRecrut; } // command.CommandText = "SELECT * FROM Reserve WHERE CodeRNE = @RNE AND Annee = @Annee"; // : using (SqlDataReader dr3 = command.ExecuteReader()) // { // if (dr3.Read()) // { // resultat.Reserve = Convert.ToInt32(dr3["Montant"].ToString()); // } // } command.CommandText = "SELECT Annee, TypeDonnees,EffectifTotal FROM EffectifTotal WHERE CodeRNE = @RNE AND TypeClasses = @typeclasses AND Annee > @AnneeMoins10 ORDER BY Annee ASC"; command.Parameters.AddWithValue("@AnneeMoins10", annee - 10); command.Parameters.AddWithValue("@typeclasses", "Normal"); using (SqlDataReader dr4 = command.ExecuteReader()) { resultat.LstEffectif = new List(); IList lstEffectifReel = new List(); while (dr4.Read()) { lstEffectifReel.Add(new Effectif(dr4["Annee"].ToString(),dr4["TypeDonnees"].ToString(), Convert.ToInt32(dr4["EffectifTotal"].ToString()))); } foreach (Effectif e in lstEffectifReel) { if (e.TypeEffectif == "R") resultat.LstEffectif.Add(e); } foreach (Effectif e in lstEffectifReel) { bool trouve = false; if (e.TypeEffectif == "P") { foreach (Effectif e1 in resultat.LstEffectif) if (e1.Annee == e.Annee) trouve = true; if (!trouve) resultat.LstEffectif.Add(e); } } } command.CommandText = "SELECT * from Restructuration WHERE CodeRNE = @RNE"; using (SqlDataReader dr6 = command.ExecuteReader()) { IList lstRestructuration = new List(); while (dr6.Read()) { lstRestructuration.Add(Convert.ToInt32(dr6["Annee"].ToString())); } resultat.LstRestructuration = lstRestructuration; } // 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()"; // using (SqlDataReader dr8 = command.ExecuteReader()) // { // int nbrRemplacements = 0; // while (dr8.Read()) // { // nbrRemplacements++; ; // } // resultat.NbrRemplacementsATC = nbrRemplacements; // } } } catch (Exception erreur) { throw erreur; } finally { if (connexion.State == ConnectionState.Open) connexion.Close(); } } resultat.Surface = 0; using (SqlConnection connexion = new SqlConnection(this.ChaineDeConnexion)) { try { connexion.Open(); using (SqlCommand command = connexion.CreateCommand()) { command.CommandText= "select superficie from dbo.Surface where codeRNE =@RNE AND ANNEE = @ANNEE "; command.Parameters.AddWithValue("@RNE", codeRNE); command.Parameters.AddWithValue("@ANNEE", annee); using (SqlDataReader dr9 = command.ExecuteReader()) if (dr9.Read()) { resultat.Surface = Convert.ToDouble(dr9["superficie"].ToString()); } } } catch { throw; } finally { if (connexion.State == ConnectionState.Open) connexion.Close(); } } //using (OracleConnection connexion = new OracleConnection(this.ChaineDeConnexion)) //{ // try // { // connexion.Open(); // using (OracleCommand command = connexion.CreateCommand()) // { // 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"; // command.Parameters.AddWithValue(":RNE", codeRNE); // using (OracleDataReader reader = command.ExecuteReader()) // { // if (reader.Read()) // { // resultat.Surface = Convert.ToDouble(reader["SurfaceTotale"].ToString()); // } // } // } // } // catch // { // throw; // } // finally // { // if (connexion.State == ConnectionState.Open) // connexion.Close(); // } //} return resultat; } } }