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 Groupe create(Groupe obj) { //Si l'objet n'a pas d'id, on récupère le dernier id dans la table, pour que l'id de l'objet actuel soit le suivant if (obj.Id == -1) { obj.Id = OutilsSQL.getLastInsertedId("groupe", Connexion.getInstance()) + 1; } /* * id * nom * id_enseignant * id_cours */ string query = @"INSERT INTO groupe(id, nom, id_enseignant, id_cours) VALUES (" + obj.Id + ", '" + obj.Nom + "', " + obj.enseignant.Id + ", " + obj.idCours + ");"; //Console.ReadLine(); using (SqlCommand command = new SqlCommand(query, Connexion.getInstance())) { command.ExecuteNonQuery(); //Connexion.getInstance().Close(); } return(obj); }
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 PartieAnnee create(PartieAnnee obj) { if (obj.Id == -1) { obj.Id = OutilsSQL.getLastInsertedId("partie_annee", Connexion.getInstance()) + 1; } using (SqlCommand command_c = new SqlCommand("INSERT INTO partie_annee VALUES (" + obj.Id + ", '" + obj.Nom + "', " + obj.Annee.Id + ", '" + obj.Description + "');", Connexion.getInstance())) { command_c.ExecuteNonQuery(); } return(obj); }
public override PartieAnnee update(int idAupdate, PartieAnnee obj) { string query = "UPDATE dbo.partie_annee SET id = @id, nom = @nom, id_annee = @id_annee, description = @description WHERE id = @id"; using (SqlCommand command = new SqlCommand(query, Connexion.getInstance())) { command.Parameters.AddWithValue("@id", obj.Id); command.Parameters.AddWithValue("@nom", obj.Nom); command.Parameters.AddWithValue("@id_annee", obj.Annee.Id); command.Parameters.AddWithValue("@description", obj.Description); command.ExecuteNonQuery(); } return(obj); }
public override EquivalentTD update(int idAupdate, EquivalentTD obj) { string query = "UPDATE dbo.equivalent_td SET id = @id, id_categorie_enseignant = @id_categorie_enseignant, id_type_cours = @id_type_cours, ratio_cours_td = @ratio_cours_td WHERE id = @id"; using (SqlCommand command = new SqlCommand(query, Connexion.getInstance())) { command.Parameters.AddWithValue("@id", obj.Id); command.Parameters.AddWithValue("@id_categorie_enseignant", obj.Categorie.Id); command.Parameters.AddWithValue("@id_type_cours", obj.TypeCours is null ? DBNull.Value : (object)obj.TypeCours.Id); command.Parameters.AddWithValue("@ratio_cours_td", obj.Ratio); command.ExecuteNonQuery(); } return(obj); }
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 create(EquivalentTD obj) { if (obj.Id == -1) { obj.Id = OutilsSQL.getLastInsertedId("equivalent_td", Connexion.getInstance()) + 1; } string query = "INSERT INTO dbo.equivalent_td (id, id_categorie_enseignant, id_type_cours, ratio_cours_td) VALUES (@id, @id_categorie_enseignant, @id_type_cours, @ratio_cours_td)"; using (SqlCommand command = new SqlCommand(query, Connexion.getInstance())) { command.Parameters.AddWithValue("@id", obj.Id); command.Parameters.AddWithValue("@id_categorie_enseignant", obj.Categorie.Id); command.Parameters.AddWithValue("@id_type_cours", obj.TypeCours is null ? DBNull.Value : (object)obj.TypeCours.Id); command.Parameters.AddWithValue("@ratio_cours_td", obj.Ratio); command.ExecuteNonQuery(); } return(obj); }
public override TypeCours update(int idAupdate, TypeCours update) { using (SqlCommand command_u = new SqlCommand(@"UPDATE type_cours SET nom='" + update.Nom + "', " + "has_groups=" + update.Groupes + " WHERE id=" + idAupdate + ";", Connexion.getInstance())) { command_u.ExecuteNonQuery(); } // Connexion.getInstance().Close(); return(update); }
public override void delete(TypeCours obj) { using (SqlCommand command_d = new SqlCommand("DELETE FROM type_cours WHERE id=" + obj.Id + ";", Connexion.getInstance())) { command_d.ExecuteNonQuery(); } //Connexion.getInstance().Close(); }
public override void delete(PartieAnnee obj) { using (SqlCommand command_d = new SqlCommand("DELETE FROM partie_annee WHERE id=" + obj.Id + ";", Connexion.getInstance())) { command_d.ExecuteNonQuery(); } }
public override List <TypeCours> findAll() { List <TypeCours> tps = new List <TypeCours>(); using (SqlCommand command_f = new SqlCommand("SELECT * FROM type_cours;", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { tps.Add(new TypeCours(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetInt32(2))); } } } } return(tps); }
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); }
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 List <Categorie> findAll() { List <Categorie> categories = new List <Categorie>(); using (SqlCommand command_f = new SqlCommand("SELECT * FROM categorie_enseignant;", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { categories.Add(new Categorie(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetDouble(2))); } } } } return(categories); }
public override void delete(EquivalentTD obj) { using (SqlCommand command = new SqlCommand("DELETE FROM equivalent_td WHERE id=" + obj.Id + ";", Connexion.getInstance())) { command.ExecuteNonQuery(); } // Connexion.getInstance().Close(); }
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 TypeCours find(string type) { Console.WriteLine("recherche type cours"); TypeCours typeCours = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, has_groups FROM type_cours WHERE nom='" + type + "';", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { typeCours = new TypeCours(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetInt32(2)); } } reader_f.Close(); } //Connexion.getInstance().Close(); return(typeCours); } }
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 Categorie find(string nom) { Categorie categ = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, heures_a_travailler FROM categorie_enseignant WHERE nom='" + nom + "';", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { categ = new Categorie(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetDouble(2)); } } reader_f.Close(); } //Connexion.getInstance().Close(); return(categ); } }
public override Categorie find(int id) { Categorie categorieEnseignant = null; using (SqlCommand command_f = new SqlCommand("SELECT nom, heures_a_travailler FROM categorie_enseignant WHERE id=" + id + ";", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { categorieEnseignant = new Categorie(id, reader_f.GetString(0), reader_f.GetDouble(1)); reader_f.NextResult(); } } //else //{ // throw new Exception("Aucun objet avec cet id n'a été trouvé."); //} reader_f.Close(); } } // Connexion.getInstance().Close(); return(categorieEnseignant); }
public override void delete(Categorie obj) { using (SqlCommand command_d = new SqlCommand("DELETE FROM categorie_enseignant WHERE id=" + obj.Id + ";", Connexion.getInstance())) { command_d.ExecuteNonQuery(); } //Connexion.getInstance().Close(); }
public override Categorie update(int idAupdate, Categorie update) { using (SqlCommand command_u = new SqlCommand(@"UPDATE categorie_enseignant SET nom='" + update.Nom + "', " + "heures_a_travailler=" + update.Heures + " WHERE id=" + idAupdate + ";", Connexion.getInstance())) { command_u.ExecuteNonQuery(); } // Connexion.getInstance().Close(); return(update); }
public override TypeCours find(int id) { TypeCours typeCours = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, has_groups FROM type_cours WHERE id=" + id + ";", Connexion.getInstance())) { using (SqlDataReader reader_f = command_f.ExecuteReader()) { if (reader_f.HasRows) { while (reader_f.Read()) { typeCours = new TypeCours(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetInt32(2)); reader_f.NextResult(); } } else { throw new Exception("Aucun objet avec cet id n'a été trouvé."); } reader_f.Close(); } } //Connexion.getInstance().Close(); return(typeCours); }
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); }