//ajout d'une représentation public static int AddShow(Show uneRepresentation) { int nb; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "INSERT INTO Show(show_dateTime,show_seats,show_priceRate,show_theaterPiece) values( @dateRepresentation ,@nbPlacesRepresentation,@priceRateRepresentation, @pieceDeTheatreRepresentation)"; //param SqlParameter dateRep = new SqlParameter("@dateRepresentation", SqlDbType.DateTime); dateRep.Value = uneRepresentation.Show_dateTime; cmd.Parameters.Add(dateRep); SqlParameter nbPlaces = new SqlParameter("@nbPlacesRepresentation", SqlDbType.Int); nbPlaces.Value = uneRepresentation.Show_seats; cmd.Parameters.Add(nbPlaces); SqlParameter priceRate = new SqlParameter("@priceRateRepresentation", SqlDbType.Int); priceRate.Value = uneRepresentation.Show_priceRate.PriceRate_id; cmd.Parameters.Add(priceRate); SqlParameter pieceDeTheatre = new SqlParameter("@pieceDeTheatreRepresentation", SqlDbType.Int); pieceDeTheatre.Value = uneRepresentation.Show_theaterPiece.TheaterPiece_id; cmd.Parameters.Add(pieceDeTheatre); //fin param nb = cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); return(nb); }
// Accesseur en lecture, renvoi une instance de connexion public static ConnexionBD GetConnexionBD() { if (uneConnexionBD == null) { uneConnexionBD = new ConnexionBD(); } return(uneConnexionBD); }
// Ajout d'une nouvelle réservation public static void AddSpectator(Spectator uneReservation) { try { // Ouverture connaxion SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Requête SQL ajout table Spectator // SELECT SCOPE_IDENTITY() : renvoie l'id de la ligne qui vient d'être ajoutée string reqAdd = "INSERT INTO Spectator (spectator_lastname, spectator_firstname, spectator_email, spectator_phone) VALUES (@lastname, @firstname, @email, @phone); SELECT SCOPE_IDENTITY()"; SqlCommand commAddSpec = new SqlCommand(reqAdd, connexion); commAddSpec.Parameters.Add(new SqlParameter("@lastname", System.Data.SqlDbType.VarChar, 255)); commAddSpec.Parameters.Add(new SqlParameter("@firstname", System.Data.SqlDbType.VarChar, 255)); commAddSpec.Parameters.Add(new SqlParameter("@email", System.Data.SqlDbType.VarChar, 255)); commAddSpec.Parameters.Add(new SqlParameter("@phone", System.Data.SqlDbType.VarChar, 255)); commAddSpec.Parameters["@lastname"].Value = uneReservation.Spectator_lastname; commAddSpec.Parameters["@firstname"].Value = uneReservation.Spectator_firstname; commAddSpec.Parameters["@email"].Value = uneReservation.Spectator_email; commAddSpec.Parameters["@phone"].Value = uneReservation.Spectator_phone; // Exécution de la requête et récupération de l'id de la ligne qui vient d'être ajoutée int idSpec = Convert.ToInt32(commAddSpec.ExecuteScalar()); // Requête SQL ajout table To_Book string reqAddBook = "INSERT INTO To_book (toBook_spectator, toBook_show, seatsBooked) VALUES (@spectator, @show, @seatsBooked)"; connexion.Close(); SqlConnection connexionBook = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand commAddBook = new SqlCommand(reqAddBook, connexionBook); commAddBook.Parameters.Add(new SqlParameter("@spectator", System.Data.SqlDbType.Int)); commAddBook.Parameters.Add(new SqlParameter("@show", System.Data.SqlDbType.Int)); commAddBook.Parameters.Add(new SqlParameter("@seatsBooked", System.Data.SqlDbType.Int)); commAddBook.Parameters["@spectator"].Value = idSpec; commAddBook.Parameters["@show"].Value = uneReservation.Spectator_show.Show_id; commAddBook.Parameters["@seatsBooked"].Value = uneReservation.Spectator_seatsBooked; // Execution de la requête commAddBook.ExecuteNonQuery(); // Connexion fermée connexionBook.Close(); } catch (Exception e) { //Message box erreur string test = e.ToString(); } }
//renvoie le nombre de places réservées pour une représentation public static int GetSeatsBooked(int idRepresentation, int nbPlacesTotal) { int nbPlacesRestantesPourUneRepresentation = 0; int nbPlacesReserveesPourUneRepresentation = 0; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "SELECT * FROM To_book WHERE toBook_show = @idShow"; SqlParameter paramid = new SqlParameter("@idShow", SqlDbType.NChar); paramid.Value = idRepresentation; cmd.Parameters.Add(paramid); SqlDataReader monReader = cmd.ExecuteReader(); while (monReader.Read()) { nbPlacesReserveesPourUneRepresentation += Int32.Parse(monReader["seatsBooked"].ToString()); } monReader.Close(); SqlCommand cmd2 = new SqlCommand(); cmd2.Connection = maConnexion; cmd2.CommandText = "SELECT * FROM Show WHERE show_id = @idShow"; SqlParameter paramid2 = new SqlParameter("@idShow", SqlDbType.NChar); paramid2.Value = idRepresentation; cmd2.Parameters.Add(paramid2); SqlDataReader monReader2 = cmd2.ExecuteReader(); while (monReader2.Read()) { nbPlacesTotal = Int32.Parse(monReader2["show_seats"].ToString()); } monReader2.Close(); // Fermeture de la connexion maConnexion.Close(); nbPlacesRestantesPourUneRepresentation = nbPlacesTotal - nbPlacesReserveesPourUneRepresentation; return(nbPlacesRestantesPourUneRepresentation); }
//retourne un utilisateur en fonction de son pseudo public static AppUser GetUser(string pseudo) { // définition des variables AppUser unUtilisateur; int id = 0; string password = ""; bool isAdmin = false; SqlConnection maConnexion; // Connexion à la BD maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // initialisationn d'un reader SqlDataReader monReader = null; // initialisation et écriture d'une requête sql SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; SqlParameter paramPseudo = new SqlParameter("@pseudo", SqlDbType.NChar); paramPseudo.Value = pseudo; cmd.CommandText = "SELECT * FROM AppUser WHERE user_pseudo = @pseudo"; cmd.Parameters.Add(paramPseudo); // execution du reader monReader = cmd.ExecuteReader(); // vérif si retourne quelque chose ou non if (monReader.HasRows) { // while reader while (monReader.Read()) { id = Convert.ToInt32(monReader["user_id"].ToString()); password = monReader["user_password"].ToString(); isAdmin = (bool)monReader["user_isAdmin"]; } } unUtilisateur = new AppUser(id, pseudo, password, isAdmin); monReader.Close(); // Fermeture de la connexion maConnexion.Close(); return(unUtilisateur); }
public static List <Theme> GetThemes() { Theme leTheme = null; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Création d'une liste vide d'objet TheaterPiece List <Theme> lesThemes = new List <Theme>(); // Commande sql qui récupère les informations de la table Theater_piece SqlCommand cmdTheme = new SqlCommand(); cmdTheme.Connection = maConnexion; cmdTheme.CommandText = "SELECT * FROM Theme"; // Execution des requetes sql SqlDataReader readerTheme = cmdTheme.ExecuteReader(); // Theme while (readerTheme.Read()) { int idTheme = Int32.Parse(readerTheme["theme_id"].ToString()); string nomTheme = readerTheme["theme_name"].ToString(); leTheme = new Theme(idTheme, nomTheme); lesThemes.Add(leTheme); } // Fermeture reader readerTheme.Close(); readerTheme = cmdTheme.ExecuteReader(); // Fermeture reader readerTheme.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesThemes); }
public static List <Company> GetCompagnies() { Company laCompagnie = null; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); List <Company> lesCompagnies = new List <Company>(); SqlCommand cmdCompagnie = new SqlCommand(); cmdCompagnie.Connection = maConnexion; cmdCompagnie.CommandText = "SELECT * FROM Company"; // Execution des requetes sql SqlDataReader readerCompagnie = cmdCompagnie.ExecuteReader(); // Company while (readerCompagnie.Read()) { int idCompagnie = Int32.Parse(readerCompagnie["company_id"].ToString()); string nomCompagnie = readerCompagnie["company_name"].ToString(); string villeCompagnie = readerCompagnie["company_city"].ToString(); string regionCompagnie = readerCompagnie["company_region"].ToString(); string directeurArtistique = readerCompagnie["company_artisticDirector"].ToString(); laCompagnie = new Company(idCompagnie, nomCompagnie, villeCompagnie, regionCompagnie, directeurArtistique); lesCompagnies.Add(laCompagnie); } // Fermeture reader readerCompagnie.Close(); readerCompagnie = cmdCompagnie.ExecuteReader(); // Fermeture de la connexion maConnexion.Close(); return(lesCompagnies); }
public static List <PublicType> GetTypesPublic() { PublicType leType = null; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Création d'une liste vide d'objet TheaterPiece List <PublicType> lesTypes = new List <PublicType>(); // Commande sql qui récupère les informations de la table Theater_piece SqlCommand cmdTypePublic = new SqlCommand(); cmdTypePublic.Connection = maConnexion; cmdTypePublic.CommandText = "SELECT * FROM Public_Type"; // Execution des requetes sql SqlDataReader readerTypePublic = cmdTypePublic.ExecuteReader(); // Public type while (readerTypePublic.Read()) { int idType = Int32.Parse(readerTypePublic["publicType_id"].ToString()); string nomType = readerTypePublic["publicType_name"].ToString(); leType = new PublicType(idType, nomType); lesTypes.Add(leType); } // Fermeture reader readerTypePublic.Close(); readerTypePublic = cmdTypePublic.ExecuteReader(); // Fermeture de la connexion maConnexion.Close(); return(lesTypes); }
// Edition d'une réservation public static string EditSpectator(Spectator laReservation) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqEditSpec = "UPDATE Spectator SET spectator_lastname = @lastname, spectator_firstname = @firstname, spectator_email = @email, spectator_phone = @phone WHERE spectator_id = @id; UPDATE To_book SET toBook_show = @idShow, seatsBooked = @seatsBooked WHERE toBook_spectator = @id;"; SqlCommand commeEditSpec = new SqlCommand(reqEditSpec, connexion); commeEditSpec.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)); commeEditSpec.Parameters["@id"].Value = laReservation.Spectator_id; commeEditSpec.Parameters.Add(new SqlParameter("@lastname", System.Data.SqlDbType.VarChar, 255)); commeEditSpec.Parameters["@lastname"].Value = laReservation.Spectator_lastname; commeEditSpec.Parameters.Add(new SqlParameter("@firstname", System.Data.SqlDbType.VarChar, 255)); commeEditSpec.Parameters["@firstname"].Value = laReservation.Spectator_firstname; commeEditSpec.Parameters.Add(new SqlParameter("@email", System.Data.SqlDbType.VarChar, 255)); commeEditSpec.Parameters["@email"].Value = laReservation.Spectator_email; commeEditSpec.Parameters.Add(new SqlParameter("@phone", System.Data.SqlDbType.VarChar, 255)); commeEditSpec.Parameters["@phone"].Value = laReservation.Spectator_phone; commeEditSpec.Parameters.Add(new SqlParameter("@idShow", System.Data.SqlDbType.Int)); commeEditSpec.Parameters["@idShow"].Value = laReservation.Spectator_show.Show_id; commeEditSpec.Parameters.Add(new SqlParameter("@seatsBooked", System.Data.SqlDbType.Int)); commeEditSpec.Parameters["@seatsBooked"].Value = laReservation.Spectator_seatsBooked; commeEditSpec.ExecuteNonQuery(); connexion.Close(); return("Edition effectuée avec succès !"); } catch (Exception e) { return(e.Message); } }
// Suppression de toutes les représentations par rapport à une pièce de théâtre public static void RemoveShows(TheaterPiece unePiece) { // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "DELETE FROM Show WHERE show_theaterPiece = @idPiece;"; //param SqlParameter idPiece = new SqlParameter("@idPiece", SqlDbType.Int); idPiece.Value = unePiece.TheaterPiece_id; cmd.Parameters.Add(idPiece); //fin param cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); }
//modification d'un représentation public static int ModifShow(Show uneRepresentation) { try { int nb; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "UPDATE Show SET show_dateTime=@dateRepresentation, show_seats=@nbPlacesRepresentation, show_priceRate=@priceRateRepresentation, show_theaterPiece=@pieceDeTheatreRepresentation WHERE show_id = @idShow"; //param SqlParameter idShow = new SqlParameter("@idShow", SqlDbType.Int); idShow.Value = uneRepresentation.Show_id; cmd.Parameters.Add(idShow); SqlParameter dateRep = new SqlParameter("@dateRepresentation", SqlDbType.DateTime); dateRep.Value = uneRepresentation.Show_dateTime; cmd.Parameters.Add(dateRep); SqlParameter nbPlaces = new SqlParameter("@nbPlacesRepresentation", SqlDbType.Int); nbPlaces.Value = uneRepresentation.Show_seats; cmd.Parameters.Add(nbPlaces); SqlParameter priceRate = new SqlParameter("@priceRateRepresentation", SqlDbType.Int); priceRate.Value = uneRepresentation.Show_priceRate.PriceRate_id; cmd.Parameters.Add(priceRate); SqlParameter pieceDeTheatre = new SqlParameter("@pieceDeTheatreRepresentation", SqlDbType.Int); pieceDeTheatre.Value = uneRepresentation.Show_theaterPiece.TheaterPiece_id; cmd.Parameters.Add(pieceDeTheatre); //fin param nb = cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); return(nb); } catch (Exception e) { string error = e.Message; return(0); } }
// Suppression des réservations en fonction de la pièce public static void RemoveSpectators(TheaterPiece unePiece) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqDelSpec = "DELETE FROM To_book WHERE toBook_show IN (SELECT show_id FROM Show WHERE show_theaterPiece = @idPiece) ; DELETE FROM Spectator WHERE spectator_id IN (SELECT toBook_spectator FROM To_Book, Show WHERE toBook_show = show_id AND show_theaterPiece = @idPiece ); "; SqlCommand commDelSpec = new SqlCommand(reqDelSpec, connexion); commDelSpec.Parameters.Add(new SqlParameter("@idPiece", System.Data.SqlDbType.Int)); commDelSpec.Parameters["@idPiece"].Value = unePiece.TheaterPiece_id; commDelSpec.ExecuteNonQuery(); connexion.Close(); } catch (Exception e) { string error = e.Message; } }
// Suppression des réservations en fonction du show public static void RemoveSpectators(int idShow) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqDelSpec = "DELETE FROM To_book WHERE toBook_show = @idShow ; DELETE FROM Spectator WHERE spectator_id IN (SELECT toBook_spectator FROM To_Book WHERE toBook_show = @idShow ); "; SqlCommand commDelSpec = new SqlCommand(reqDelSpec, connexion); commDelSpec.Parameters.Add(new SqlParameter("@idShow", System.Data.SqlDbType.Int)); commDelSpec.Parameters["@idShow"].Value = idShow; commDelSpec.ExecuteNonQuery(); connexion.Close(); } catch (Exception e) { string error = e.Message; } }
// Modification d'une piece public static void EditTheaterPiece(TheaterPiece unePiece) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqEdit = "UPDATE Theater_piece SET theaterPiece_name = @name, theaterPiece_description = @description, theaterPiece_duration = @duration, theaterPiece_seatsPrice = @seatsPrice, theaterPiece_company = @company, theaterPiece_author = @author, theaterPiece_publicType = @publicType, theaterPiece_theme = @theme WHERE theaterPiece_id = @id;"; SqlCommand commEditPiece = new SqlCommand(reqEdit, connexion); commEditPiece.Parameters.Add(new SqlParameter("@name", System.Data.SqlDbType.VarChar, 255)); commEditPiece.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)); commEditPiece.Parameters.Add(new SqlParameter("@description", System.Data.SqlDbType.VarChar, 255)); commEditPiece.Parameters.Add(new SqlParameter("@duration", System.Data.SqlDbType.Float)); commEditPiece.Parameters.Add(new SqlParameter("@seatsPrice", System.Data.SqlDbType.Float)); commEditPiece.Parameters.Add(new SqlParameter("@company", System.Data.SqlDbType.Int)); commEditPiece.Parameters.Add(new SqlParameter("@author", System.Data.SqlDbType.Int)); commEditPiece.Parameters.Add(new SqlParameter("@publicType", System.Data.SqlDbType.Int)); commEditPiece.Parameters.Add(new SqlParameter("@theme", System.Data.SqlDbType.Int)); commEditPiece.Parameters["@name"].Value = unePiece.TheaterPiece_name; commEditPiece.Parameters["@id"].Value = unePiece.TheaterPiece_id; commEditPiece.Parameters["@description"].Value = unePiece.TheaterPiece_description; commEditPiece.Parameters["@duration"].Value = unePiece.TheaterPiece_duration; commEditPiece.Parameters["@seatsPrice"].Value = unePiece.TheaterPiece_seatsPrice; commEditPiece.Parameters["@company"].Value = unePiece.TheaterPiece_company.Company_id; commEditPiece.Parameters["@author"].Value = unePiece.TheaterPiece_author.Author_id; commEditPiece.Parameters["@publicType"].Value = unePiece.TheaterPiece_publicType.PublicType_id; commEditPiece.Parameters["@theme"].Value = unePiece.TheaterPiece_theme.Theme_id; commEditPiece.ExecuteNonQuery(); connexion.Close(); } catch (Exception e) { //Message box erreur string test = e.ToString(); } }
//suppression d'un représentation public static int DelShow(int IdRep) { int nb; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "DELETE FROM Show WHERE show_id = @idShow;"; //param SqlParameter idShow = new SqlParameter("@idShow", SqlDbType.Int); idShow.Value = IdRep; cmd.Parameters.Add(idShow); //fin param nb = cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); return(nb); }
// suppression d'une piece public static void RemoveTheaterPiece(TheaterPiece unePiece) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqRemove = "DELETE FROM Theater_piece WHERE theaterPiece_id = @id;"; SqlCommand commRemovePiece = new SqlCommand(reqRemove, connexion); commRemovePiece.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)); commRemovePiece.Parameters["@id"].Value = unePiece.TheaterPiece_id; commRemovePiece.ExecuteNonQuery(); connexion.Close(); } catch (Exception e) { //Message box erreur string test = e.ToString(); } }
// Récupère le nombre de places prises pour une représentation public static int GetNbPlacesReservees(Show laRepresentation) { // Initialisation de la variable à un nombre négatif int nbPlacesReservees = -1; try { // Connexion DB SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Requête SQL select nbplaces string reqPlacesRest = "SELECT SUM(seatsBooked) AS 'Nb Places Reservees' FROM To_book, Show WHERE toBook_show = show_id AND show_id = @idShow;"; SqlCommand commPlacesRest = new SqlCommand(reqPlacesRest, connexion); commPlacesRest.Parameters.Add(new SqlParameter("@idShow", System.Data.SqlDbType.Int)); commPlacesRest.Parameters["@idShow"].Value = laRepresentation.Show_id; SqlDataReader readerPlacesRest = null; readerPlacesRest = commPlacesRest.ExecuteReader(); if (readerPlacesRest.HasRows) { while (readerPlacesRest.Read()) { nbPlacesReservees = Int32.Parse(readerPlacesRest["Nb Places Reservees"].ToString()); } } connexion.Close(); } catch (Exception e) { } // Retourne le nombre de places réservées return(nbPlacesReservees); }
// Ajout d'une nouvelle piece public static void AddTheaterPiece(TheaterPiece unePiece) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqAdd = "INSERT INTO Theater_piece (theaterPiece_name, theaterPiece_description, theaterPiece_duration, theaterPiece_seatsPrice, theaterPiece_company, theaterPiece_author, theaterPiece_publicType, theaterPiece_theme) VALUES (@name, @description, @duration, @seatsPrice, @company, @author, @publicType, @theme);"; SqlCommand commAddPiece = new SqlCommand(reqAdd, connexion); commAddPiece.Parameters.Add(new SqlParameter("@name", System.Data.SqlDbType.VarChar, 255)); commAddPiece.Parameters.Add(new SqlParameter("@description", System.Data.SqlDbType.VarChar, 255)); commAddPiece.Parameters.Add(new SqlParameter("@duration", System.Data.SqlDbType.Float)); commAddPiece.Parameters.Add(new SqlParameter("@seatsPrice", System.Data.SqlDbType.Float)); commAddPiece.Parameters.Add(new SqlParameter("@company", System.Data.SqlDbType.Int)); commAddPiece.Parameters.Add(new SqlParameter("@author", System.Data.SqlDbType.Int)); commAddPiece.Parameters.Add(new SqlParameter("@publicType", System.Data.SqlDbType.Int)); commAddPiece.Parameters.Add(new SqlParameter("@theme", System.Data.SqlDbType.Int)); commAddPiece.Parameters["@name"].Value = unePiece.TheaterPiece_name; commAddPiece.Parameters["@description"].Value = unePiece.TheaterPiece_description; commAddPiece.Parameters["@duration"].Value = unePiece.TheaterPiece_duration; commAddPiece.Parameters["@seatsPrice"].Value = unePiece.TheaterPiece_seatsPrice; commAddPiece.Parameters["@company"].Value = unePiece.TheaterPiece_company.Company_id; commAddPiece.Parameters["@author"].Value = unePiece.TheaterPiece_author.Author_id; commAddPiece.Parameters["@publicType"].Value = unePiece.TheaterPiece_publicType.PublicType_id; commAddPiece.Parameters["@theme"].Value = unePiece.TheaterPiece_theme.Theme_id; commAddPiece.ExecuteNonQuery(); connexion.Close(); } catch (Exception e) { //Message box erreur string test = e.ToString(); } }
// Suppression d'une réservation public static string DeleteSpectator(Spectator laReservation) { try { SqlConnection connexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); string reqDelSpec = "DELETE FROM To_book WHERE toBook_spectator = @idSpec ; DELETE FROM Spectator WHERE spectator_id = @idSpec; "; SqlCommand commDelSpec = new SqlCommand(reqDelSpec, connexion); commDelSpec.Parameters.Add(new SqlParameter("@idSpec", System.Data.SqlDbType.Int)); commDelSpec.Parameters["@idSpec"].Value = laReservation.Spectator_id; commDelSpec.ExecuteNonQuery(); connexion.Close(); return("Suppression effectuée"); } catch (Exception e) { return(e.Message); } }
// Renvoie la liste des représentations // Utilise la DAO PiecesTheatres pour avoir la liste des pièces // besoin du taux (et donc des jours) public static List <Show> GetShows() { //variables int idShow = 0; DateTime uneDateHeure = new DateTime(2018, 01, 01, 00, 00, 00); //besoin de date et heure int nbPlaces = 0; TheaterPiece laPiece = null; //besoin de nomPiece, durée PriceRate letaux = null; //calcul du prix pour date, heure, semaine Show uneRepresentation = null; // Création d'une liste vide d'objets lesRepresentations List <Show> lesRepresentations = new List <Show>(); // Récupération de la liste des pièces de théâtre List <TheaterPiece> lesPiecesDeTheatre = PiecesTheatreDAO.GetTheaterPieces(); // Récupération de la liste des taux List <PriceRate> lesTaux = GetPriceRateWeeksDays(); // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; cmd.CommandText = "SELECT * FROM Show"; SqlDataReader monReader = cmd.ExecuteReader(); // Remplissage de la liste while (monReader.Read()) { idShow = Int32.Parse(monReader["show_id"].ToString()); uneDateHeure = (DateTime)monReader["show_dateTime"]; nbPlaces = Int32.Parse(monReader["show_seats"].ToString()); int idDutaux = Convert.ToInt32(monReader["show_priceRate"].ToString()); int idPiece = Convert.ToInt32(monReader["show_theaterPiece"].ToString()); // On trouve dans la liste des pièces de théâtres celle correspondant à l'id bool trouve = false; int i = 0; while (trouve == false && i < lesPiecesDeTheatre.Count) { if (lesPiecesDeTheatre[i].TheaterPiece_id == idPiece) { // Si on l'a, on l'ajoute laPiece = lesPiecesDeTheatre[i]; trouve = true; } else { i++; } } bool trouve2 = false; int i2 = 0; while (trouve2 == false && i2 < lesTaux.Count) { if (lesTaux[i2].PriceRate_id == idDutaux) { // Si on l'a, on l'ajoute letaux = lesTaux[i2]; trouve2 = true; } else { i2++; } } uneRepresentation = new Show(idShow, uneDateHeure, nbPlaces, letaux, laPiece); lesRepresentations.Add(uneRepresentation); } monReader.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesRepresentations); }
public static List <Author> GetAuthors() { Author leAuteur = null; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Création d'une liste vide d'objet TheaterPiece List <Author> lesAuteurs = new List <Author>(); // Commande sql qui récupère les informations de la table Theater_piece SqlCommand cmdPiecesTheatre = new SqlCommand(); cmdPiecesTheatre.Connection = maConnexion; cmdPiecesTheatre.CommandText = "SELECT * FROM Theater_piece"; // Commande sql qui récupère les informations de la table Author SqlCommand cmdAuteur = new SqlCommand(); cmdAuteur.Connection = maConnexion; cmdAuteur.CommandText = "SELECT * FROM Author"; // Commande sql qui récupère les informations de la table Nationality SqlCommand cmdNationalites = new SqlCommand(); cmdNationalites.Connection = maConnexion; cmdNationalites.CommandText = "SELECT * FROM Nationality"; // Commande sql qui récupère les informations de la table To_be_of SqlCommand cmdAuteurNationalite = new SqlCommand(); cmdAuteurNationalite.Connection = maConnexion; cmdAuteurNationalite.CommandText = "SELECT * FROM To_be_of"; // Execution des requetes sql SqlDataReader readerPiecesTheatre = cmdPiecesTheatre.ExecuteReader(); SqlDataReader readerAuteur = cmdAuteur.ExecuteReader(); SqlDataReader readerNationalites = cmdNationalites.ExecuteReader(); SqlDataReader readerAuteurNationalite = cmdAuteurNationalite.ExecuteReader(); // Author while (readerAuteur.Read()) { int idAuteur = Int32.Parse(readerAuteur["author_id"].ToString()); string nomAuteur = readerAuteur["author_lastname"].ToString(); string prenomAuteur = readerAuteur["author_firstname"].ToString(); List <int> lesIdsNationalites = new List <int>(); while (readerAuteurNationalite.Read()) { int idComparerAuteur = Int32.Parse(readerAuteurNationalite["toBeOf_author"].ToString()); if (idAuteur == idComparerAuteur) { int idNatio = Int32.Parse(readerAuteurNationalite["toBeOf_nationality"].ToString()); lesIdsNationalites.Add(idNatio); } } // Fermerure reader readerAuteurNationalite.Close(); readerAuteurNationalite = cmdAuteurNationalite.ExecuteReader(); List <Nationality> lesNationalites = new List <Nationality>(); foreach (int unIdNatio in lesIdsNationalites) { while (readerNationalites.Read()) { int idNationalite = Int32.Parse(readerNationalites["nationality_id"].ToString()); if (unIdNatio == idNationalite) { Nationality laNationalite; string nomNationalite = readerNationalites["nationality_name"].ToString(); laNationalite = new Nationality(idNationalite, nomNationalite); lesNationalites.Add(laNationalite); } } // Fermeture reader readerNationalites.Close(); readerNationalites = cmdNationalites.ExecuteReader(); } leAuteur = new Author(idAuteur, nomAuteur, prenomAuteur, lesNationalites); lesAuteurs.Add(leAuteur); } // Fermeture reader readerAuteur.Close(); readerAuteur = cmdAuteur.ExecuteReader(); // Fermeture reader readerAuteurNationalite.Close(); readerNationalites.Close(); readerAuteur.Close(); readerPiecesTheatre.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesAuteurs); }
// Renvoie la liste des représentations correspondant à la pièce de théatres ayant lieu durant une période passée en paramètres public static List <Show> GetFilterShows(int idTheaterPiece, DateTime dateDebutChoisie, DateTime dateFinChoisie) { //variables int idShow; DateTime uneDateHeure; //besoin de date et heure int nbPlaces; int idTaux; int idPiece; TheaterPiece laPiece = null; //besoin de nomPiece, durée PriceRate letaux = null; //calcul du prix pour date, heure, semaine Show uneRepresentation; // Récupération de la liste des pièces de théâtre List <TheaterPiece> lesPiecesDeTheatre = PiecesTheatreDAO.GetTheaterPieces(); // Récupération de la liste des taux List <PriceRate> lesTaux = GetPriceRateWeeksDays(); // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Création d'une liste vide d'objets lesRepresentations List <Show> lesRepresentations = new List <Show>(); SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; //paramètres SqlParameter paramIdPiece = new SqlParameter("@idPiece", SqlDbType.Int); paramIdPiece.Value = idTheaterPiece; SqlParameter paramDateDeb = new SqlParameter("@dateDeb", SqlDbType.VarChar); string date1; date1 = dateDebutChoisie.ToString("yyyy/MM/dd"); paramDateDeb.Value = date1; SqlParameter paramDateFin = new SqlParameter("@dateFin", SqlDbType.VarChar); string date2; date2 = dateFinChoisie.ToString("yyyy/MM/dd"); paramDateFin.Value = date2; //requête cmd.CommandText = "SELECT show_id,show_dateTime, show_seats, show_priceRate, show_theaterPiece FROM Show, Theater_piece WHERE show_theaterPiece = theaterPiece_id AND theaterPiece_id = @idPiece AND CAST(show_dateTime as DATE) BETWEEN @dateDeb AND @dateFin"; //ajout params cmd.Parameters.Add(paramIdPiece); cmd.Parameters.Add(paramDateDeb); cmd.Parameters.Add(paramDateFin); SqlDataReader monReader = cmd.ExecuteReader(); // Remplissage de la liste while (monReader.Read()) { idShow = Int32.Parse(monReader["show_id"].ToString()); uneDateHeure = (DateTime)monReader["show_dateTime"]; nbPlaces = Int32.Parse(monReader["show_seats"].ToString()); idTaux = Int32.Parse(monReader["show_priceRate"].ToString()); idPiece = Int32.Parse(monReader["show_theaterPiece"].ToString()); bool trouve = false; int i = 0; while (trouve == false && i < lesPiecesDeTheatre.Count) { if (lesPiecesDeTheatre[i].TheaterPiece_id == idPiece) { // Si on l'a, on l'ajoute laPiece = lesPiecesDeTheatre[i]; trouve = true; } else { i++; } } // On trouve dans la liste des pièces de théâtres celle correspondant à l'id bool trouve2 = false; int i2 = 0; while (trouve2 == false && i2 < lesTaux.Count) { if (lesTaux[i2].PriceRate_id == idTaux) { // Si on l'a, on l'ajoute letaux = lesTaux[i2]; trouve2 = true; } else { i2++; } } uneRepresentation = new Show(idShow, uneDateHeure, nbPlaces, letaux, laPiece); lesRepresentations.Add(uneRepresentation); } monReader.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesRepresentations); }
// Renvoie la liste des réservations // Nécessite les représentations et pièces de théâtre // Besoin des tables spectator et toBook public static List <Spectator> GetSpectators() { // Définition des variables List <Spectator> lesReservations = new List <Spectator>(); Spectator uneReservation; int id = 0; string nom = ""; string prenom = ""; string email = ""; string telephone = ""; int nbPlaces = 0; Show laRepresentation = null; SqlConnection maConnexion; // Récupération de la liste des représentations List <Show> lesRepresentations = RepresentationsDAO.GetShows(); // Connexion à la DB maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Initialisation de deux readers SqlDataReader readerSpectators = null; SqlDataReader readerToBook = null; // Initialisation et écriture d'une requête SQL pour récupérer tous les spectators SqlCommand cmdSpectators = new SqlCommand(); cmdSpectators.Connection = maConnexion; cmdSpectators.CommandText = "SELECT * FROM Spectator"; // Initialisation et écriture d'une requête SQL pour récupérer la table To Book SqlCommand cmdToBook = new SqlCommand(); cmdToBook.Connection = maConnexion; cmdToBook.CommandText = "SELECT * FROM To_book"; // Execution du reader spectators readerSpectators = cmdSpectators.ExecuteReader(); readerToBook = cmdToBook.ExecuteReader(); // Verification de la valeur du retour if (readerSpectators.HasRows) { // while reader while (readerSpectators.Read()) { // assignation des valeurs retournées par la requêtes aux variables concernées id = Convert.ToInt32(readerSpectators["spectator_id"].ToString()); nom = readerSpectators["spectator_lastname"].ToString(); prenom = readerSpectators["spectator_firstname"].ToString(); email = readerSpectators["spectator_email"].ToString(); telephone = readerSpectators["spectator_phone"].ToString(); // Déclanchement du reader sur la table To Book pour récupérer la liaison avec le show et le nbPlaces while (readerToBook.Read()) { int idSpect = Convert.ToInt32(readerToBook["toBook_spectator"].ToString()); // Si l'id du spectateur de to book est égale à celui de la requête précédente if (idSpect == id) { // on récupère l'id du show et le nb de places int idShow = Convert.ToInt32(readerToBook["toBook_show"].ToString()); nbPlaces = Convert.ToInt32(readerToBook["seatsBooked"].ToString()); bool trouve = false; int i = 0; // On trouve dans la liste des show celui correspondant à l'id while (trouve == false && i < lesRepresentations.Count) { if (lesRepresentations[i].Show_id == idShow) { // Si on l'a, on l'ajoute laRepresentation = lesRepresentations[i]; trouve = true; } else { i++; } } } } readerToBook.Close(); readerToBook = cmdToBook.ExecuteReader(); // Initialisation d'une nouvelle réservation et ajout dans la liste uneReservation = new Spectator(id, nom, prenom, email, telephone, laRepresentation, nbPlaces); lesReservations.Add(uneReservation); } } readerSpectators.Close(); readerToBook.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesReservations); }
//GetPriceRateWeeksDays renvoie la liste des taux en fonction de la semaine public static List <PriceRate> GetPriceRateWeeksDays() { List <PriceRate> lesTaux = new List <PriceRate>(); List <WeekDays> lesJoursSemaine = new List <WeekDays>(); SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); //récupération de la liste des semaines SqlCommand cmd2 = new SqlCommand(); cmd2.Connection = maConnexion; cmd2.CommandText = "SELECT * FROM Week_days"; SqlDataReader monReader2 = cmd2.ExecuteReader(); int idJour; string nomJour; WeekDays leJour = null; // Remplissage de la liste while (monReader2.Read()) { idJour = Int32.Parse(monReader2["weekDays_id"].ToString()); nomJour = monReader2["weekDays_name"].ToString(); leJour = new WeekDays(idJour, nomJour); lesJoursSemaine.Add(leJour); } monReader2.Close(); //récupération de la liste des priceRate en fonction du jour de la semaine SqlCommand cmd = new SqlCommand(); cmd.Connection = maConnexion; int idTaux; string nomTaux; TimeSpan debutHeure; TimeSpan finHeure; float tauxApplique; PriceRate leTaux; cmd.CommandText = "SELECT * from Price_rate"; SqlCommand cmdConcern = new SqlCommand(); cmdConcern.Connection = maConnexion; cmdConcern.CommandText = "SELECT * FROM To_concern"; SqlDataReader monReader = cmd.ExecuteReader(); while (monReader.Read()) { List <WeekDays> lesJoursTaux = new List <WeekDays>(); idTaux = Int32.Parse(monReader["priceRate_id"].ToString()); nomTaux = monReader["priceRate_name"].ToString(); debutHeure = (TimeSpan)monReader["priceRate_startTime"]; finHeure = (TimeSpan)monReader["priceRate_endTime"]; tauxApplique = float.Parse(monReader["priceRate_rate"].ToString()); SqlDataReader readerConcern = cmdConcern.ExecuteReader(); while (readerConcern.Read()) { int idConcernTaux = Int32.Parse(readerConcern["toConcern_priceRate"].ToString()); if (idTaux == idConcernTaux) { int idConcernJour = Int32.Parse(readerConcern["toConcern_weekDays"].ToString()); bool trouve = false; int ind = 0; while (trouve == false && ind < lesJoursSemaine.Count) { if (lesJoursSemaine[ind].WeekDays_id == idConcernJour) { lesJoursTaux.Add(lesJoursSemaine[ind]); trouve = true; } else { ind++; } } } } readerConcern.Close(); leTaux = new PriceRate(idTaux, nomTaux, debutHeure, finHeure, tauxApplique, lesJoursTaux); lesTaux.Add(leTaux); } monReader.Close(); // Fermeture de la connexion maConnexion.Close(); return(lesTaux); }
public static TheaterPiece GetOneTheaterPiece(string nomPiece) { int id = 0; string nom = ""; string description = ""; float duree = 0; float prix = 0; Company laCompagnie = null; Author leAuteur = null; PublicType leType = null; Theme leTheme = null; TheaterPiece unePieceTheatre = null; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Commande sql qui récupère les informations de la table Theatre_piece SqlCommand cmdPiecesTheatre = new SqlCommand(); cmdPiecesTheatre.Connection = maConnexion; cmdPiecesTheatre.CommandText = "SELECT * FROM Theater_piece"; // Commande sql qui récupère les informations de la table Author SqlCommand cmdAuteur = new SqlCommand(); cmdAuteur.Connection = maConnexion; cmdAuteur.CommandText = "SELECT * FROM Author"; // Commande sql qui récupère les informations de la table Nationality SqlCommand cmdNationalites = new SqlCommand(); cmdNationalites.Connection = maConnexion; cmdNationalites.CommandText = "SELECT * FROM Nationality"; // Commande sql qui récupère les informations de la table To_be_of SqlCommand cmdAuteurNationalite = new SqlCommand(); cmdAuteurNationalite.Connection = maConnexion; cmdAuteurNationalite.CommandText = "SELECT * FROM To_be_of"; // Commande sql qui récupère les informations de la table Theme SqlCommand cmdTheme = new SqlCommand(); cmdTheme.Connection = maConnexion; cmdTheme.CommandText = "SELECT * FROM Theme"; // Commande sql qui récupère les informations de la table Public_Type SqlCommand cmdTypePublic = new SqlCommand(); cmdTypePublic.Connection = maConnexion; cmdTypePublic.CommandText = "SELECT * FROM Public_Type"; // Commande sql qui récupère les informations de la table Company SqlCommand cmdCompagnie = new SqlCommand(); cmdCompagnie.Connection = maConnexion; cmdCompagnie.CommandText = "SELECT * FROM Company"; // Execution des requetes SqlDataReader readerPiecesTheatre = cmdPiecesTheatre.ExecuteReader(); SqlDataReader readerAuteur = cmdAuteur.ExecuteReader(); SqlDataReader readerNationalites = cmdNationalites.ExecuteReader(); SqlDataReader readerTheme = cmdTheme.ExecuteReader(); SqlDataReader readerTypePublic = cmdTypePublic.ExecuteReader(); SqlDataReader readerAuteurNationalite = cmdAuteurNationalite.ExecuteReader(); SqlDataReader readerCompagnie = cmdCompagnie.ExecuteReader(); // Remplissage de la liste // Pieces de theatre while (readerPiecesTheatre.Read()) { nom = readerPiecesTheatre["theaterPiece_name"].ToString(); if (nom == nomPiece) { id = Int32.Parse(readerPiecesTheatre["theaterPiece_id"].ToString()); description = readerPiecesTheatre["theaterPiece_description"].ToString(); duree = float.Parse(readerPiecesTheatre["theaterPiece_duration"].ToString()); prix = float.Parse(readerPiecesTheatre["theaterPiece_seatsPrice"].ToString()); int idDeLAuteur = Int32.Parse(readerPiecesTheatre["theaterPiece_author"].ToString()); int idDeLaCompagnie = Int32.Parse(readerPiecesTheatre["theaterPiece_company"].ToString()); int idDuTypePublic = Int32.Parse(readerPiecesTheatre["theaterPiece_publicType"].ToString()); int idDuTheme = Int32.Parse(readerPiecesTheatre["theaterPiece_theme"].ToString()); // Company while (readerCompagnie.Read()) { int idCompagnie = Int32.Parse(readerCompagnie["company_id"].ToString()); if (idDeLaCompagnie == idCompagnie) { string nomCompagnie = readerCompagnie["company_name"].ToString(); string villeCompagnie = readerCompagnie["company_city"].ToString(); string regionCompagnie = readerCompagnie["company_region"].ToString(); string directeurArtistique = readerCompagnie["company_artisticDirector"].ToString(); laCompagnie = new Company(idCompagnie, nomCompagnie, villeCompagnie, regionCompagnie, directeurArtistique); } } // Fermeture reader readerCompagnie.Close(); readerCompagnie = cmdCompagnie.ExecuteReader(); // Author while (readerAuteur.Read()) { int idAuteur = Int32.Parse(readerAuteur["author_id"].ToString()); if (idDeLAuteur == idAuteur) { string nomAuteur = readerAuteur["author_lastname"].ToString(); string prenomAuteur = readerAuteur["author_firstname"].ToString(); List <int> lesIdsNationalites = new List <int>(); while (readerAuteurNationalite.Read()) { int idComparerAuteur = Int32.Parse(readerAuteurNationalite["toBeOf_author"].ToString()); if (idAuteur == idComparerAuteur) { int idNatio = Int32.Parse(readerAuteurNationalite["toBeOf_nationality"].ToString()); lesIdsNationalites.Add(idNatio); } } // Fermeture reader readerAuteurNationalite.Close(); readerAuteurNationalite = cmdAuteurNationalite.ExecuteReader(); List <Nationality> lesNationalites = new List <Nationality>(); foreach (int unIdNatio in lesIdsNationalites) { while (readerNationalites.Read()) { int idNationalite = Int32.Parse(readerNationalites["nationality_id"].ToString()); if (unIdNatio == idNationalite) { Nationality laNationalite; string nomNationalite = readerNationalites["nationality_name"].ToString(); laNationalite = new Nationality(idNationalite, nomNationalite); lesNationalites.Add(laNationalite); } } // Fermeture reader readerNationalites.Close(); readerNationalites = cmdNationalites.ExecuteReader(); } leAuteur = new Author(idAuteur, nomAuteur, prenomAuteur, lesNationalites); } } // Fermeture reader readerAuteur.Close(); readerAuteur = cmdAuteur.ExecuteReader(); // Public type while (readerTypePublic.Read()) { int idType = Int32.Parse(readerTypePublic["publicType_id"].ToString()); if (idType == idDuTypePublic) { string nomType = readerTypePublic["publicType_name"].ToString(); leType = new PublicType(idType, nomType); } } // Fermeture reader readerTypePublic.Close(); readerTypePublic = cmdTypePublic.ExecuteReader(); // Theme while (readerTheme.Read()) { int idTheme = Int32.Parse(readerTheme["theme_id"].ToString()); if (idTheme == idDuTheme) { string nomTheme = readerTheme["theme_name"].ToString(); leTheme = new Theme(idTheme, nomTheme); } } // Fermeture reader readerTheme.Close(); readerTheme = cmdTheme.ExecuteReader(); unePieceTheatre = new TheaterPiece(id, nom, description, duree, prix, laCompagnie, leAuteur, leType, leTheme); } } // Fermeture reader readerCompagnie.Close(); readerAuteurNationalite.Close(); readerNationalites.Close(); readerAuteur.Close(); readerTypePublic.Close(); readerTheme.Close(); readerPiecesTheatre.Close(); // Fermeture de la connexion maConnexion.Close(); return(unePieceTheatre); }