public override TypeCours create(TypeCours obj) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Categorie> categorie = factoSQL.getCategorieDAO(); if (obj.Id == -1) { obj.Id = OutilsSQL.getLastInsertedId("type_cours", Connexion.getInstance()) + 1; } using (SqlCommand command_c = new SqlCommand("INSERT INTO type_cours VALUES (" + obj.Id + ", '" + obj.Nom + "', '" + obj.Groupes + "');", Connexion.getInstance())) { command_c.ExecuteNonQuery(); // Connexion.getInstance().Close(); } //foreach (Categorie categ in categorie.findAll()) //{ // int idT = OutilsSQL.getLastInsertedId("equivalent_td", Connexion.getInstance()) + 1; // using (SqlCommand command_test = new SqlCommand("INSERT INTO equivalent_td VALUES (" + idT + ", '" + categ.Id + "', '" + obj.Id + "', 1 );", Connexion.getInstance())) // { // command_test.ExecuteNonQuery(); // } //} return(obj); }
public override List <PartieAnnee> findAll() { List <PartieAnnee> ans = new List <PartieAnnee>(); using (SqlCommand command_f = new SqlCommand("SELECT * FROM partie_annee;", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Annee> TPSQL = factoSQL.getAnneeDAO(); Annee annee2 = TPSQL.find(reader_f.GetInt32(2)); ans.Add(new PartieAnnee(reader_f.GetInt32(0), reader_f.GetString(1), annee2, reader_f.GetString(3))); } } } } return(ans); }
public override List <EquivalentTD> findAll() { List <EquivalentTD> eqtds = new List <EquivalentTD>(); using (SqlCommand command_f = new SqlCommand("SELECT * FROM equivalent_td;", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Categorie> TPSQL = factoSQL.getCategorieDAO(); DAO <TypeCours> TPSQL2 = factoSQL.getTypeCoursDao(); Categorie categ = TPSQL.find(reader_f.GetInt32(1)); TypeCours tp = reader_f.IsDBNull(2) ? default(TypeCours) : TPSQL2.find(reader_f.GetInt32(2)); eqtds.Add(new EquivalentTD(reader_f.GetInt32(0), categ, tp, reader_f.GetDouble(3))); } } } } return(eqtds); }
public override PartieAnnee find(string nom) { PartieAnnee annee = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, id_annee, description FROM partie_annee WHERE nom='" + nom + "';", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Annee> TPSQL = factoSQL.getAnneeDAO(); Annee annee2 = TPSQL.find(reader_f.GetInt32(2)); annee = new PartieAnnee(reader_f.GetInt32(0), reader_f.GetString(1), annee2, reader_f.GetString(3)); } } reader_f.Close(); } // Connexion.getInstance().Close(); return(annee); } }
public override PartieAnnee find(int id) { PartieAnnee annee = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, id_annee, description FROM partie_annee WHERE id=" + id + ";", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Annee> TPSQL = factoSQL.getAnneeDAO(); Annee annee2 = TPSQL.find(reader_f.GetInt32(2)); annee = new PartieAnnee(reader_f.GetInt32(0), reader_f.GetString(1), annee2, reader_f.GetString(3)); reader_f.NextResult(); } } else { throw new Exception("Aucun objet avec cet id n'a été trouvé."); } reader_f.Close(); } } return(annee); }
public override Groupe find(int id) { //Console.WriteLine("id à trouver dans find:" + id); Groupe groupe = null; /* id * nom * id_enseignant * id_cours */ using (SqlCommand command = new SqlCommand(@"SELECT nom, id_enseignant, id_cours FROM groupe WHERE id=" + id + ";", Connexion.getInstance())) { using (SqlDataReader reader = command.ExecuteReader()) { Dictionary <TypeCours, double> ratios = new Dictionary <TypeCours, double>(); //Factory pour chercher les objets TypeCours dans la DB AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); int idEnseignant = -1; int idCours = -1; string nom = ""; if (reader.HasRows) { while (reader.Read()) { /* * nom * id_enseignant * id_cours */ nom = reader.GetString(0); idEnseignant = reader.GetInt32(1); idCours = reader.GetInt32(2); reader.NextResult(); } } else { throw new Exception("Aucun groupe avec cet id n'a été trouvé."); } reader.Close(); } } //Connexion.getInstance().Close(); return(groupe); }
public override Categorie create(Categorie obj) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Categorie> categorie = factoSQL.getCategorieDAO(); if (obj.Id == -1) { obj.Id = OutilsSQL.getLastInsertedId("categorie_enseignant", Connexion.getInstance()) + 1; } using (SqlCommand command_c = new SqlCommand(@"INSERT INTO categorie_enseignant VALUES (" + obj.Id + ", '" + obj.Nom + "', " + obj.Heures + ");", Connexion.getInstance())) { command_c.ExecuteNonQuery(); } return(obj); }
public override EquivalentTD find(int id) { EquivalentTD eqtd = null; using (SqlCommand command_f = new SqlCommand("SELECT id, id_categorie_enseignant, id_type_cours, ratio_cours_td FROM equivalent_td WHERE id=" + id + ";", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Categorie> TPSQL = factoSQL.getCategorieDAO(); DAO <TypeCours> TPSQL2 = factoSQL.getTypeCoursDao(); Categorie categ = TPSQL.find(reader_f.GetInt32(1)); TypeCours tp = TPSQL2.find(reader_f.GetInt32(2)); eqtd = new EquivalentTD(reader_f.GetInt32(0), categ, tp, reader_f.GetDouble(3)); reader_f.NextResult(); } } else { throw new Exception("Aucun objet avec cet id n'a été trouvé."); } reader_f.Close(); } } //Connexion.getInstance().Close(); return(eqtd); }