public List <Lapins> GetAll() { List <Lapins> lapins = new List <Lapins>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,surnom,age,idGerant,vitesse,endurance,chance from Lapin", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { int n = 0; if (rdr["idGerant"].ToString() != "") { n = Convert.ToInt32(rdr["idGerant"]); } lapins.Add(new Lapins(Convert.ToInt32(rdr["id"]), rdr["surnom"].ToString(), state.unChanged, n, Convert.ToInt32(rdr["chance"]), Convert.ToInt32(rdr["endurance"]), Convert.ToInt32(rdr["vitesse"]))); } } } } return(lapins); }
public List <Lapins> GetAll(int id) { List <Lapins> lapins = new List <Lapins>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,surnom,age,idGerant,vitesse,endurance,chance,gagnant from Lapin inner join Participer on Lapin.id = Participer.idLapin where idCourse=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = id; using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { int n = 0; if (rdr["idGerant"].ToString() != "") { n = Convert.ToInt32(rdr["idGerant"]); } lapins.Add(new Lapins(Convert.ToInt32(rdr["id"]), rdr["surnom"].ToString(), state.unChanged, n, Convert.ToInt32(rdr["chance"]), Convert.ToInt32(rdr["endurance"]), Convert.ToInt32(rdr["vitesse"]), Convert.ToInt32(rdr["gagnant"]))); } } } } return(lapins); }
public static MySqlConnection GetMySqlConnection() { if (DaoConnectionSingleton.mySqlConnection == null) { DaoConnectionSingleton.mySqlConnection = new MySqlConnection(DaoConnectionSingleton.GetStringConnection()); } return(DaoConnectionSingleton.mySqlConnection); }
private void delete(Lapins lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("delete from Lapin where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = lapin.GetId(); cmd.ExecuteNonQuery(); } } }
private void delete(Participer p) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("delete from Participer where idCourse=@idC and idLapin=@idL", cnx)) { cmd.Parameters.Add(new MySqlParameter("@idC", MySqlDbType.Int32)); cmd.Parameters["@idC"].Value = p.IdCourse; cmd.Parameters.Add(new MySqlParameter("@idL", MySqlDbType.Int32)); cmd.Parameters["@idL"].Value = p.IdLapin; cmd.ExecuteNonQuery(); } } }
private void update(Participer p) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update Participer set gagnant=1 where idCourse=@idCourse and idLapin=@idLapin", cnx)) { cmd.Parameters.Add(new MySqlParameter("@idCourse", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@idLapin", MySqlDbType.Int32)); cmd.Parameters["@idCourse"].Value = p.IdCourse; cmd.Parameters["@idLapin"].Value = p.IdLapin; cmd.ExecuteNonQuery(); } } p.State1 = state.unChanged; }
private void insert(Participer p) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("insert into Participer(idCourse,Gagnant,idLapin) values(@idCourse,@Gagnant,@idLapin)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@idCourse", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@idLapin", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@Gagnant", MySqlDbType.Int32)); cmd.Parameters["@idCourse"].Value = p.IdCourse; cmd.Parameters["@idLapin"].Value = p.IdLapin; cmd.Parameters["@Gagnant"].Value = p.Gagnant; cmd.ExecuteNonQuery(); } } p.State1 = (state.unChanged); }
private void insert(Lapins lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); if (lapin.GetIdGerant() == 0) { using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,vitesse,endurance,chance) values(@surnom,@age,@vitesse,@endurance,@chance)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@vitesse", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@endurance", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@chance", MySqlDbType.Int32)); cmd.Parameters["@surnom"].Value = lapin.GetSurnom(); cmd.Parameters["@age"].Value = lapin.GetAge(); cmd.Parameters["@vitesse"].Value = lapin.Vitesse; cmd.Parameters["@endurance"].Value = lapin.Endurance; cmd.Parameters["@chance"].Value = lapin.Chance; cmd.ExecuteNonQuery(); } } else { using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,vitesse,endurance,chance,idGerant) values(@surnom,@age,@vitesse,@endurance,@chance,@idGerant)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@vitesse", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@endurance", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@chance", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@idGerant", MySqlDbType.Int32)); cmd.Parameters["@surnom"].Value = lapin.GetSurnom(); cmd.Parameters["@age"].Value = lapin.GetAge(); cmd.Parameters["@vitesse"].Value = lapin.Vitesse; cmd.Parameters["@endurance"].Value = lapin.Endurance; cmd.Parameters["@chance"].Value = lapin.Chance; cmd.Parameters["@idGerant"].Value = lapin.GetIdGerant(); cmd.ExecuteNonQuery(); } } } lapin.SetState(state.unChanged); }
private void delete(Gerant gerant) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update lapin set idGerant= null where idGerant=@idGerant", cnx)) { cmd.Parameters.Add(new MySqlParameter("@idGerant", MySqlDbType.Int32)); cmd.Parameters["@idGerant"].Value = gerant.Id; cmd.ExecuteNonQuery(); } using (MySqlCommand cmd = new MySqlCommand("delete from gerant where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = gerant.Id; cmd.ExecuteNonQuery(); } } }
public List <Gerant> GetAll() { List <Gerant> gerants = new List <Gerant>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,age,nom,prenom,pwd,budget from gerant", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { gerants.Add(new Gerant(rdr["nom"].ToString(), rdr["prenom"].ToString(), Convert.ToInt32(rdr["age"]), rdr["pwd"].ToString(), state.unChanged, Convert.ToInt32(rdr["budget"]), Convert.ToInt32(rdr["id"]))); } } } } return(gerants); }
public List <Participer> GetAll() { List <Participer> p = new List <Participer>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select * from Participer", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { p.Add(new Participer(Convert.ToInt32(rdr["idCourse"]), Convert.ToInt32(rdr["idLapin"]), Convert.ToInt32(rdr["Gagnant"]), state.unChanged)); } } } } return(p); }
private void update(Course course) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update Course set distance=@distance, @nomprixDuGagnant=nomprixDuGagnant where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@distance", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@prixDuGagnant", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@prixEntree", MySqlDbType.Int32)); cmd.Parameters["@prixEntree"].Value = course.PrixEntree; cmd.Parameters["@prixDuGagnant"].Value = course.PrixDuGagnant; cmd.Parameters["@id"].Value = course.GetId(); cmd.Parameters["@distance"].Value = course.GetDistance(); cmd.ExecuteNonQuery(); } } course.SetState(state.unChanged); }
private void insert(Course course) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("insert into Course(distance,nom,prixDuGagnant,prixEntree) values(@distance,@nom,@prixDuGagnant,@prixEntree)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@distance", MySqlDbType.Int32)); cmd.Parameters["@distance"].Value = course.GetDistance(); cmd.Parameters.Add(new MySqlParameter("@prixDuGagnant", MySqlDbType.Int32)); cmd.Parameters["@prixDuGagnant"].Value = course.PrixDuGagnant; cmd.Parameters.Add(new MySqlParameter("@prixEntree", MySqlDbType.Int32)); cmd.Parameters["@prixEntree"].Value = course.PrixEntree; cmd.Parameters.Add(new MySqlParameter("@nom", MySqlDbType.VarChar)); cmd.Parameters["@nom"].Value = course.GetNom(); cmd.ExecuteNonQuery(); } } course.SetState(state.unChanged); }
public List <Course> GetAll() { List <Course> courses = new List <Course>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,distance,nom,prixDuGagnant,prixEntree from Course", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { courses.Add(new Course(Convert.ToInt32(rdr["id"]), Convert.ToInt32(rdr["distance"]), rdr["nom"].ToString(), Convert.ToInt32(rdr["prixDuGagnant"]), Convert.ToInt32(rdr["prixEntree"]), state.unChanged)); } } } } return(courses); }
private void insert(Gerant gerant) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("insert into gerant(nom,prenom,age,pwd,budget) values(@nom,@prenom,@age,@pwd,@budget)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@nom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@prenom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@pwd", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@budget", MySqlDbType.Int32)); cmd.Parameters["@budget"].Value = gerant.Budget; cmd.Parameters["@age"].Value = gerant.Age; cmd.Parameters["@nom"].Value = gerant.Nom; cmd.Parameters["@prenom"].Value = gerant.Prenom; cmd.Parameters["@pwd"].Value = gerant.Password; cmd.ExecuteNonQuery(); } } gerant.State1 = (state.unChanged); }
private void update(Gerant gerant) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update Gerant set age=@age, nom=@nom, prenom=@prenom, budget=@budget where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@nom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@prenom", MySqlDbType.VarChar)); cmd.Parameters.Add(new MySqlParameter("@budget", MySqlDbType.Int32)); cmd.Parameters["@budget"].Value = gerant.Budget; cmd.Parameters["@id"].Value = gerant.Id; cmd.Parameters["@age"].Value = gerant.Age; cmd.Parameters["@nom"].Value = gerant.Nom; cmd.Parameters["@prenom"].Value = gerant.Prenom; cmd.ExecuteNonQuery(); } } gerant.State1 = (state.unChanged); }
private void update(Lapins lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); if (lapin.GetIdGerant() == 0) { using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age, idGerant=NULL where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters["@id"].Value = lapin.GetId(); cmd.Parameters["@age"].Value = lapin.GetAge(); cmd.Parameters["@surnom"].Value = lapin.GetSurnom(); cmd.ExecuteNonQuery(); } } else { using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age,idGerant=@idGerant where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@idGerant", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters["@id"].Value = lapin.GetId(); cmd.Parameters["@age"].Value = lapin.GetAge(); cmd.Parameters["@surnom"].Value = lapin.GetSurnom(); cmd.Parameters["@idGerant"].Value = lapin.GetIdGerant(); cmd.ExecuteNonQuery(); } } } lapin.SetState(state.unChanged); }