}//fin constructeur #region Service Methods public Diplome getDiplome(String IdDiplome) { List<UniteEnseignement> ues = null; var select = "SELECT diplome.Intitule" + "\n"; var from = "FROM formation.Diplome diplome" + "\n"; var where = "WHERE diplome.IdDiplome = '{0}'"; var diplome = new Diplome(); using (var dbConnection = new SqlConnection(MasterProgramDbConnectionString)) { dbConnection.Open(); using (SqlCommand sqlCommand = dbConnection.CreateCommand()) { ues = getUEs(IdDiplome, sqlCommand); sqlCommand.CommandText = String.Format(select + from + where, IdDiplome); SqlDataReader reader = sqlCommand.ExecuteReader(); reader.Read(); String id = IdDiplome; String intitule; if (!reader.IsDBNull(1)) { intitule = (String)reader["Intitule"]; } else { intitule = null; } reader.Close(); diplome.IdDiplome = id; diplome.Intitule = intitule; diplome.UEs = ues; }//fin SqlCommand dbConnection.Close(); }//fin dbConnection return diplome; }//fin getDiplome()
}//fin getDiplome() public List<Diplome> getAllDiplomes() { var diplomes = new List<Diplome>(); List<UniteEnseignement> ues = null; using (var dbConnection = new SqlConnection(MasterProgramDbConnectionString)) { dbConnection.Open(); using (SqlCommand sqlCommand = dbConnection.CreateCommand()) { sqlCommand.CommandText = "SELECT * FROM formation.Diplome"; SqlDataReader reader = sqlCommand.ExecuteReader(); String intitule = null; while (reader.Read()) { var id = (String)reader["IdDiplome"]; if (!reader.IsDBNull(1)) { intitule = (String)reader["Intitule"]; } else { intitule = null; } var diplome = new Diplome { IdDiplome = (String)reader["IdDiplome"], Intitule = intitule, UEs = ues }; if (diplome!=null) { diplomes.Add(diplome); } }// fin While reader.Close(); foreach (Diplome diplome in diplomes) { var id = diplome.IdDiplome; diplome.UEs = getUEs(id, sqlCommand); } }//fin SqlCommand dbConnection.Close(); } return diplomes; }//fin getMatiere ()
}//fin getIdUEs() protected List<Diplome> getDiplomes(String IdUE, SqlCommand sqlCommand) { var select = "SELECT diplome.Intitule "; var from = "FROM formation.DIPLOME diplome "; var where = "WHERE diplome.IdDiplome = '{0}' "; var IdDiplomes = getIdDiplomes(IdUE, sqlCommand); var Diplomes = new List<Diplome>(); String intitule = null; foreach (String id in IdDiplomes) { sqlCommand.CommandText = String.Format(select + from + where, id); SqlDataReader reader = sqlCommand.ExecuteReader(); reader.Read(); if (!reader.IsDBNull(1)) { intitule = (String)reader["Intitule"]; } else { intitule = null; } var diplome = new Diplome { IdDiplome = id, Intitule = intitule, UEs = null }; reader.Close(); Diplomes.Add(diplome); } return Diplomes; }//fin getDiplomes()