public override Enseignant find(string nom) { Enseignant ens = null; using (SqlCommand command_f = new SqlCommand("SELECT id, nom, prenom, nb_heures_assignees, id_categorie_enseignant, image FROM enseignant 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 <Categorie> TPSQL = factoSQL.getCategorieDAO(); Categorie categ2 = TPSQL.find(reader_f.GetInt32(4)); ens = new Enseignant(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetString(2), reader_f.GetDouble(3), categ2, reader_f.GetString(5)); reader_f.NextResult(); } } reader_f.Close(); } } return(ens); }
public override List <Enseignant> findAll() { List <Enseignant> enss = new List <Enseignant>(); using (SqlCommand command_f = new SqlCommand("SELECT * FROM enseignant;", 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(); Categorie categ2 = TPSQL.find(reader_f.GetInt32(4)); enss.Add(new Enseignant(reader_f.GetInt32(0), reader_f.GetString(1), reader_f.GetString(2), reader_f.GetDouble(3), categ2, reader_f.GetString(5))); } } } } return(enss); }
/// <summary> /// Initialise l'objet d'application de singleton. Il s'agit de la première ligne du code créé /// à être exécutée. Elle correspond donc à l'équivalent logique de main() ou WinMain(). /// </summary> /// public App() { Connexion connexion = new Connexion(); connexion.creerConnexion(); AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); DAO <Categorie> categorie = factoSQL.getCategorieDAO(); Categorie categorieDefaut = new Categorie { Id = 1, Nom = "Catégorie par défaut", Heures = 0 }; if (!(categorie.find(categorieDefaut.Id).Id == 1)) { categorie.create(categorieDefaut); } //TypeCours CM = new TypeCours { Id = 1, Nom = "CM", Groupes = 1}; //if (!(typeCours.find(CM.Nom) is TypeCours)) // typeCours.create(CM); //TypeCours TD = new TypeCours { Id = 2, Nom = "TD", Groupes = 2 }; //if (!(typeCours.find(TD.Nom) is TypeCours)) // typeCours.create(TD); //TypeCours TP = new TypeCours { Id = 3, Nom = "TP", Groupes = 2 }; //if (!(typeCours.find(TP.Nom) is TypeCours)) // typeCours.create(TP); /*TypeCours tp = new TypeCours("TP", true); * Categorie maitreDeConference = new Categorie("maitre de conférences", 240); * Departement dpt = new Departement("Informatique"); * Departement dpt2 = new Departement("Informatique2"); * AbstractDAOFactory factoSQL = AbstractDAOFactory.getFactory(types.SQL_FACTORY); * * DAO<Departement> depart = factoSQL.getDepartementDAO(); * //depart.create(dpt2); * * DAO<Annee> an = factoSQL.getAnneeDAO(); * an.create(new Annee("M1", depart.find(1))); * an.create(new Annee("M2", depart.find(1))); * an.create(new Annee("M3", depart.find(2))); * * DAO<PartieAnnee> pan = factoSQL.getPartieAnneeDAO(); * PartieAnnee test = new PartieAnnee("Semestre 1", an.find(1)); * pan.create(test); * pan.create(new PartieAnnee("Semestre 2", an.find(1))); * pan.create(new PartieAnnee("Semestre 3", an.find(2))); * * DAO<Enseignement> en = factoSQL.getEnseignementDAO(); * en.create(new Enseignement("EC1", pan.find(1))); * * //Console.WriteLine(maitreDeConference); * //Console.ReadLine(); * DAO<Categorie> categorie = factoSQL.getCategorieDAO(); * categorie.create(new Categorie("maitre de conference", 130)); * * * DAO<Enseignant> ens = factoSQL.getEnseignantDAO(); * ens.create(new Enseignant("John", "Bob", categorie.find(1))); * ens.create(new Enseignant("Bobby", "Malik", categorie.find(1))); * ens.create(new Enseignant("Benoit", "Martin", categorie.find(1))); * ens.create(new Enseignant("Make", "Crelo", categorie.find(1)));*/ Connexion.getInstance().Close(); this.InitializeComponent(); this.Suspending += OnSuspending; }