/// <summary> /// Ajoute une séance. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="seanceDTO">Représente la séance qui sera ajoutée.</param> public void Add(string connectionString, SeanceDTO seanceDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { //idActivite, idEntraineur, idSalle, limitePlace, nbPlace, dateSeance, heureDebut, heureFin connection.Open(); MySqlCommand addPreparedStatement = new MySqlCommand(SeanceDAO.ADD_REQUEST, connection); addPreparedStatement.Parameters.AddWithValue("@idActivite", seanceDTO.Activite.IdActivite); addPreparedStatement.Parameters.AddWithValue("@idEntraineur", seanceDTO.Entraineur.IdEntraineur); addPreparedStatement.Parameters.AddWithValue("@idSalle", seanceDTO.Salle.IdSalle); addPreparedStatement.Parameters.AddWithValue("@limitePlace", seanceDTO.LimitePlace); addPreparedStatement.Parameters.AddWithValue("@nbPlace", seanceDTO.NbPlaces); addPreparedStatement.Parameters.AddWithValue("@dateSeance", seanceDTO.DateSeance); addPreparedStatement.Parameters.AddWithValue("@heureDebut", seanceDTO.HeureDebut); addPreparedStatement.Parameters.AddWithValue("@heureFin", seanceDTO.HeureFin); addPreparedStatement.Prepare(); addPreparedStatement.ExecuteNonQuery(); } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } }
public void CreerSeanceMusculation(string connectionString, SeanceDTO seanceDTO) { try { this.seanceService.CreerSeanceMusculation(connectionString, seanceDTO); } catch (ServiceException serviceException) { throw new FacadeException(serviceException.Message, serviceException); } }
public void Inscrire(string connectionString, MembreDTO membreDTO, SeanceDTO seanceDTO) { try { inscriptionService.Inscrire(connectionString, membreDTO, seanceDTO); } catch (ServiceException serviceException) { throw new FacadeException(serviceException.Message, serviceException); } }
public void Add(string connectionString, SeanceDTO seanceDTO) { try { this.seanceDAO.Add(connectionString, seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
public void AnnulerSeance(string connectionString, SeanceDTO seanceDTO) { try { seanceService.AnnulerSeance(connectionString, seanceDTO); } catch (ServiceException serviceException) { throw new FacadeException(serviceException.Message, serviceException); } }
public SeanceDTO GetSelectedSeance(GestionSport gestionSport) { SeanceDTO seanceSelected = null; var currentRow = this.CurrentRow; if (!currentRow.IsNewRow) //Si la row clické n'est pas la dernière qui est toujours vide. { int seanceId = Convert.ToInt32(this.Rows[currentRow.Index].Cells["idSeance"].Value); SeanceDTO seanceDTO = new SeanceDTO(); seanceDTO.IdSeance = seanceId; seanceSelected = gestionSport.SeanceFacade.RechercherSeance(gestionSport.ConnectionString, seanceDTO); } return seanceSelected; }
/// <summary> /// Recherche d'une inscription. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="inscriptionDTO">Rerpésente l'inscription qui sera recherché.</param> /// <returns>Une inscription si elle existe, sinon null.</returns> public InscriptionDTO Find(string connectionString, InscriptionDTO inscriptionDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } InscriptionDTO uneInscriptionDTO = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand findPreparedStatement = new MySqlCommand(InscriptionDAO.FIND_REQUEST, connection); findPreparedStatement.Parameters.AddWithValue("@idInscription", inscriptionDTO.IdInscription); findPreparedStatement.Prepare(); using (MySqlDataReader dataReader = findPreparedStatement.ExecuteReader()) { if (dataReader.Read()) { uneInscriptionDTO = new InscriptionDTO(); uneInscriptionDTO.IdInscription = dataReader.GetInt32(0); MembreDTO membreDTO = new MembreDTO(); membreDTO.IdMembre = dataReader.GetInt32(1); uneInscriptionDTO.Membre = membreDTO; SeanceDTO seanceDTO = new SeanceDTO(); seanceDTO.IdSeance = dataReader.GetInt32(2); uneInscriptionDTO.Seance = seanceDTO; uneInscriptionDTO.DateInscription = dataReader.GetDateTime(3); uneInscriptionDTO.FlagPaiement = dataReader.GetBoolean(4); uneInscriptionDTO.FlagSupprime = dataReader.GetBoolean(5); } } } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } return uneInscriptionDTO; }
/// <summary> /// Remplit tous les champs qui sont dédiés à visualier les informations d'une séance. /// </summary> /// <param name="seance">Représente les informations sur la séance qui sera affichée.</param> private void FillFieldsSeance(SeanceDTO seance) { if (seance != null) { lblIdSeance.Text = seance.IdSeance.ToString(); //Trouve l'activite dans le comboBox for (int i = 0; i < cbActiviteSeance.Items.Count; i++) { if ((cbActiviteSeance.Items[i] as ComboboxItem).Value == seance.Activite.IdActivite) { cbActiviteSeance.SelectedIndex = i; break; } } //Trouve l'entraineur dans le comboBox for (int i = 0; i < cbEntraineurSeance.Items.Count; i++) { if ((cbEntraineurSeance.Items[i] as ComboboxItem).Value == seance.Entraineur.IdEntraineur) { cbEntraineurSeance.SelectedIndex = i; break; } } //trouve la salle dans le comboBox for (int i = 0; i < cbSalleSeance.Items.Count; i++) { if ((cbSalleSeance.Items[i] as ComboboxItem).Value == seance.Salle.IdSalle) { cbSalleSeance.SelectedIndex = i; break; } } txtLimitePlacesSeance.Text = seance.LimitePlace.ToString(); txtNombrePlacesSeance.Text = seance.NbPlaces.ToString(); dateTimePickerDateSeance.Value = seance.DateSeance; dateTimePickerDateSeance.Value.ToString(Constantes.DATE_FORMAT); txtHeureDebutSeance.Text = seance.HeureDebut.ToString(); txtHeureFinSeance.Text = seance.HeureFin.ToString(); } }
public SeanceDTO RechercherSeance(string connectionString, SeanceDTO seanceDTO) { SeanceDTO seanceRecherche = null; if (seanceDTO == null) { throw new ServiceException("Le membre ne peut pas être null."); } try { seanceRecherche = Find(connectionString, seanceDTO); if (seanceRecherche == null) { throw new ServiceException("La seance " + seanceDTO.IdSeance + " n'existe pas."); } return seanceRecherche; } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
public void ModifierSeance(string connectionString, SeanceDTO seanceDTO) { if (seanceDTO == null) { throw new ServiceException("La séance ne peut être null."); } if (seanceDTO.DateSeance == null) { throw new ServiceException("La date de la séance n'a pas été spécifié."); } if (seanceDTO.DateSeance.CompareTo(DateTime.Now) < 0) { throw new ServiceException("La date de la séance ne peut pas être une date qui a déjà été passé."); } if (seanceDTO.Entraineur == null) { throw new ServiceException("L'entraineur n'a pas été spécifé."); } if (seanceDTO.Salle == null) { throw new ServiceException("La salle n'a pas été spécifié."); } if (seanceDTO.Activite == null) { throw new ServiceException("L'activité n'a pas été spécifié."); } try { EntraineurDTO entraineurDTO = this.entraineurDAO.Find(connectionString, seanceDTO.Entraineur); SalleDTO salleDTO = this.salleDAO.Find(connectionString, seanceDTO.Salle); ActiviteDTO activiteDTO = this.activiteDAO.Find(connectionString, seanceDTO.Activite); if (entraineurDTO == null) { throw new ServiceException("L'entraineur spécifié n'existe pas."); } if (salleDTO == null) { throw new ServiceException("La salle choisit n'existe pas."); } if (activiteDTO == null) { throw new ServiceException("L'activité choisit n'existe pas"); } SeanceDTO seanceExistante = this.seanceDAO.FindByMoment(connectionString, seanceDTO); if (seanceExistante != null && seanceExistante.IdSeance != seanceDTO.IdSeance) { throw new ServiceException("Une séance à déjà lieu à la même heure, au même local et à la même date."); } List<SeanceDTO> listeSeancesCourantes = ReadAll(connectionString); if (listeSeancesCourantes != null && listeSeancesCourantes.Any()) { foreach (var seance in listeSeancesCourantes) { if (seance.IdSeance != seanceDTO.IdSeance && seance.DateSeance == seanceDTO.DateSeance) { float heureDebutDeLaNouvelleSeance = seanceDTO.HeureDebut; float heureDebutSeance = seance.HeureDebut; float heureFinSeance = seance.HeureFin; if (seance.Entraineur.IdEntraineur == entraineurDTO.IdEntraineur) { if (heureDebutDeLaNouvelleSeance >= heureDebutSeance && heureDebutDeLaNouvelleSeance < heureFinSeance) { throw new ServiceException("L'entraineur choisit travail déjà dans la la plage horaire d'une autre séance."); } } else if (seance.Salle.IdSalle == seanceDTO.Salle.IdSalle && (heureDebutDeLaNouvelleSeance >= heureDebutSeance && heureDebutDeLaNouvelleSeance < heureFinSeance)) { throw new ServiceException("Une séance est en cours pendant la plage horaire donnée."); } } } } Update(connectionString, seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
/// <summary> /// Remplit tous les champs qui sont dédiés à visualier les informations d'une séance. /// </summary> /// <param name="seance">Représente les informations sur la séance qui sera affichée.</param> private void FillFieldsSeanceInscription(SeanceDTO seance) { if (seance != null) { txtIdSeanceInscription.Text = seance.IdSeance.ToString(); txtLimitePlaceInscription.Text = seance.LimitePlace.ToString(); txtNbPlacesInscription.Text = seance.NbPlaces.ToString(); dateTimePickerDateSeanceInscription.Value = seance.DateSeance; // dateTimePickerDateSeance.Value.ToString(Constantes.DATE_FORMAT); } }
/// <inheritedoc/> public List<InscriptionDTO> FindBySeance(string connectionString, SeanceDTO seanceDTO) { List<InscriptionDTO> listeInscription = null; try { listeInscription = inscriptionDAO.FindBySeance(connectionString,seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } return listeInscription; }
/// <summary> /// Liste tous les inscriptions en lien avec une séance. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="horarieDTO">Représente la séance qui sera recherché dans les inscriptions.</param> /// <returns>Une liste de tous les inscriptions associé à une séance s'il y en a, sinon null.</returns> public List<InscriptionDTO> FindBySeance(string connectionString, SeanceDTO seanceDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } List<InscriptionDTO> listeIncriptions = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand findBySeancePreparedStatement = new MySqlCommand(InscriptionDAO.FIND_BY_SEANCE_REQUEST, connection); findBySeancePreparedStatement.Parameters.AddWithValue("@idSeance", seanceDTO.IdSeance); findBySeancePreparedStatement.Prepare(); using (MySqlDataReader dataReader = findBySeancePreparedStatement.ExecuteReader()) { if (dataReader.HasRows) { listeIncriptions = new List<InscriptionDTO>(); while (dataReader.Read()) { InscriptionDTO uneInscriptionDTO = new InscriptionDTO(); uneInscriptionDTO.IdInscription = dataReader.GetInt32(0); MembreDTO unMembreDTO = new MembreDTO(); unMembreDTO.IdMembre = dataReader.GetInt32(1); uneInscriptionDTO.Membre = unMembreDTO; SeanceDTO uneSeanceDTO = new SeanceDTO(); uneSeanceDTO.IdSeance = dataReader.GetInt32(2); uneInscriptionDTO.Seance = uneSeanceDTO; uneInscriptionDTO.DateInscription = dataReader.GetDateTime(3); uneInscriptionDTO.FlagPaiement = dataReader.GetBoolean(4); uneInscriptionDTO.FlagSupprime = dataReader.GetBoolean(5); listeIncriptions.Add(uneInscriptionDTO); } } } } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } return listeIncriptions; }
public SeanceDTO RechercherSeance(string connectionString, SeanceDTO seanceDTO) { SeanceDTO seanceRecherche = null; try { seanceRecherche = seanceService.RechercherSeance(connectionString, seanceDTO); } catch (ServiceException serviceException) { throw new FacadeException(serviceException.Message, serviceException); } return seanceRecherche; }
public void ExecuteCommand(string line) { string message = ""; try { var argumentList = line.Split(' '); if (line.StartsWith("-")) { message = "-\n"; } else if (line.StartsWith("*")) { message = line + "\n"; } else if (line.StartsWith("creerMembre")) { MembreDTO membre = new MembreDTO(); membre.Nom = argumentList[1]; membre.Prenom = argumentList[2]; membre.Adresse = argumentList[3]; membre.Ville = argumentList[4]; membre.Telephone = argumentList[5]; membre.Email = argumentList[6]; membre.Sexe = argumentList[7]; membre.DateNaissance = Convert.ToDateTime(argumentList[8]); message = "création d'un membre.\n"; gestionSport.MembreFacade.EnregistrerMembre(gestionSport.ConnectionString, membre); } else if (line.StartsWith("abonnerMembre")) { var abonnement = new AbonnementGymDTO(); var membre = new MembreDTO(); membre.IdMembre = Convert.ToInt32(argumentList[1]); abonnement.Membre = membre; abonnement.Duree = Convert.ToInt32(argumentList[2]); abonnement.Cout = float.Parse(argumentList[3]); message = "abonnement d'un membre.\n"; gestionSport.AbonnementGymFacade.AbonnerUnMembre(gestionSport.ConnectionString, abonnement); } else if (line.StartsWith("desabonnerMembre")) { var abonnement = new AbonnementGymDTO(); abonnement.IdAbonnement = Convert.ToInt32(argumentList[1]); message = "désabonnement de l'abonnement " + abonnement.IdAbonnement + "\n"; gestionSport.AbonnementGymFacade.TerminerUnAbonnement(gestionSport.ConnectionString, abonnement); } else if (line.StartsWith("creerEntraineur")) { var entraineur = new EntraineurDTO(); entraineur.Nom = argumentList[1]; entraineur.Prenom = argumentList[2]; entraineur.Adresse = argumentList[3]; entraineur.Ville = argumentList[4]; entraineur.Telephone = argumentList[5]; entraineur.Email = argumentList[6]; entraineur.Sexe = argumentList[7]; entraineur.DateNaissance = Convert.ToDateTime(argumentList[8]); message = "création d'un entraineur.\n"; gestionSport.EntraineurFacade.EnregistrerEntraineur(gestionSport.ConnectionString, entraineur); } else if (line.StartsWith("creerActivite")) { var activite = new ActiviteDTO(); activite.Nom = argumentList[1]; activite.Cout = float.Parse(argumentList[2]); activite.Duree = Convert.ToInt32(argumentList[3]); activite.Description = argumentList[4]; message = "création d'une activité\n"; gestionSport.ActiviteFacade.CreerActivite(gestionSport.ConnectionString, activite); } else if (line.StartsWith("creerSalle")) { var salle = new SalleDTO(); salle.Numero = Convert.ToInt32(argumentList[1]); salle.Etage = Convert.ToInt32(argumentList[2]); salle.Bloc = argumentList[3]; message = "création d'une salle\n"; gestionSport.SalleFacade.CreerSalle(gestionSport.ConnectionString, salle); } else if (line.StartsWith("creerSeance")) { var seance = new SeanceDTO(); var activite = new ActiviteDTO(); activite.IdActivite = Convert.ToInt32(argumentList[1]); seance.Activite = activite; var entraineur = new EntraineurDTO(); entraineur.IdEntraineur = Convert.ToInt32(argumentList[2]); seance.Entraineur = entraineur; var salle = new SalleDTO(); salle.IdSalle = Convert.ToInt32(argumentList[3]); seance.Salle = salle; seance.NbPlaces = 0; seance.LimitePlace = Convert.ToInt32(argumentList[4]); seance.DateSeance = Convert.ToDateTime(argumentList[5]); var heureDebut = float.Parse(argumentList[6].Replace(':', '.'), CultureInfo.InvariantCulture); var heureFin = float.Parse(argumentList[7].Replace(':', '.'), CultureInfo.InvariantCulture); seance.HeureDebut = heureDebut; seance.HeureFin = heureFin; message = "création d'une séance\n"; gestionSport.SeanceFacade.CreerSeance(gestionSport.ConnectionString, seance); } else if (line.StartsWith("inscrire")) { var membre = new MembreDTO(); membre.IdMembre = Convert.ToInt32(argumentList[1]); var seance = new SeanceDTO(); seance.IdSeance = Convert.ToInt32(argumentList[2]); message = "Inscription du membre: " + membre.IdMembre + " à la séance: " + seance.IdSeance + "\n"; gestionSport.InscriptionFacade.Inscrire(gestionSport.ConnectionString, membre, seance); } else if (line.StartsWith("enregistrerUtilisateur")) { var utilisateur = new UtilisateurDTO(); utilisateur.NomUtilisateur = argumentList[1]; utilisateur.Nom = argumentList[2]; utilisateur.Prenom = argumentList[3]; utilisateur.MotDePasse = argumentList[4]; utilisateur.Statut = argumentList[5]; message = "Enregistrement d'un utilisateur\n"; gestionSport.UtilisateurFacade.EnregistrerUtilisateur(gestionSport.ConnectionString, utilisateur); } else if (line.StartsWith("effacerUtilisateur")) { var utilisateur = new UtilisateurDTO(); utilisateur.IdUtilisateur = Convert.ToInt32(argumentList[1]); message = "effacement de l'utilisateur : " + utilisateur.IdUtilisateur + "\n"; gestionSport.UtilisateurFacade.EffacerUtilisateur(gestionSport.ConnectionString, utilisateur); } else if (line.StartsWith("enregistrerVisite")) { var visite = new VisiteDTO(); var membre = new MembreDTO(); membre.IdMembre = Convert.ToInt32(argumentList[1]); visite.Membre = membre; message = "Enregistrement d'une visite\n"; gestionSport.VisiteFacade.EnregistrerVisite(gestionSport.ConnectionString, visite); } else if (line.StartsWith("desinscrire")) { var inscription = new InscriptionDTO(); inscription.IdInscription = Convert.ToInt32(argumentList[1]); message = "désinscription de l'inscription : " + inscription.IdInscription + "\n"; gestionSport.InscriptionFacade.Desinscrire(gestionSport.ConnectionString, inscription); } else if (line.StartsWith("listerActivite")) { List<ActiviteDTO> listeActivite = gestionSport.ActiviteFacade.ListerActivite(gestionSport.ConnectionString); message = "Liste des activités : \nIdActivite\tNom\tCout\tDescription\tDuree\tFlagSupprime\n"; if (listeActivite != null && listeActivite.Any()) { foreach(ActiviteDTO activite in listeActivite) { message += activite.ToString(); } } } else if (line.StartsWith("listerMembre")) { List<MembreDTO> listeMembre = gestionSport.MembreFacade.ListerMembre(gestionSport.ConnectionString); message = "Liste des membres : \nIdMembre\tPrenom\tNom\tAdresse\tVille\tTelephone\tEmail\tSexe\tDateNaissance\n"; if (listeMembre != null && listeMembre.Any()) { foreach(MembreDTO membre in listeMembre) { message += membre.ToString(); } } } else if (line.StartsWith("listerSeance")) { List<SeanceDTO> listeSeance = gestionSport.SeanceFacade.ListerSeance(gestionSport.ConnectionString); message = "Liste des seances : \nIdSeance\tIdActivite\tIdEntraineur\tIdSalle\tLimitePlace\tNbPlace\tDateSeance\tHeureDebut\tHeureFin\tFlagSupprime\n"; if (listeSeance != null && listeSeance.Any()) { foreach (SeanceDTO seance in listeSeance) { message += seance.ToString(); } } } else if (line.StartsWith("listerSalle")) { List<SalleDTO> listeSalle = gestionSport.SalleFacade.ListerSalle(gestionSport.ConnectionString); message = "Liste des salles : \nIdSalle\tNumero\tEtage\tBloc\n"; if (listeSalle != null && listeSalle.Any()) { foreach (SalleDTO salle in listeSalle) { message += salle.ToString(); } } } else if (line.StartsWith("listerEntraineur")) { List<EntraineurDTO> listeEntraineur = gestionSport.EntraineurFacade.ListerEntraineur(gestionSport.ConnectionString); message = "Liste des entraineurs : \nIdMembre\tPrenom\tNom\tAdresse\tVille\tTelephone\tEmail\tSexe\tDateNaissance\n"; if (listeEntraineur != null && listeEntraineur.Any()) { foreach (EntraineurDTO entraineur in listeEntraineur) { message += entraineur.ToString(); } } } else if (line.StartsWith("listerAbonnements")) { List<AbonnementGymDTO> listeAbonnements = gestionSport.AbonnementGymFacade.ListerAbonnements(gestionSport.ConnectionString); message = "Liste des abonnements : \nIdAbonnement\tidMemebre\tDuree\tCout\tDateAbonnement\tFlagSupprime\n"; if (listeAbonnements != null && listeAbonnements.Any()) { foreach (AbonnementGymDTO abonnement in listeAbonnements) { message += abonnement.ToString(); } } } else if (line.StartsWith("listerInscriptions")) { List<InscriptionDTO> listeInscriptions = gestionSport.InscriptionFacade.ListerInscriptions(gestionSport.ConnectionString); message = "Liste des inscriptions : \nIdInscription\tidMemebre\tidSeance\tDateInscription\tFlagPaiement\tFlagSupprime\n"; if (listeInscriptions != null && listeInscriptions.Any()) { foreach (InscriptionDTO inscription in listeInscriptions) { message += inscription.ToString(); } } } else if (line.StartsWith("listerUtilisateurs")) { List<UtilisateurDTO> listeUtilisateurs = gestionSport.UtilisateurFacade.ListerUtilisateurs(gestionSport.ConnectionString); message = "Liste des utilisateurs : \nIdUtilisateur\tNomUtilisateur\tNom\tPrenom\tEmail\tMotdePasse\tStatut\tFlagSupprime\n"; if (listeUtilisateurs != null && listeUtilisateurs.Any()) { foreach (UtilisateurDTO utilisateur in listeUtilisateurs) { message += utilisateur.ToString(); } } } else if (line.StartsWith("listerVisites")) { List<VisiteDTO> listeVisites = gestionSport.VisiteFacade.ListerVisites(gestionSport.ConnectionString); message = "Liste des visites : \nIdVisite\tIdMembre\tDateVisite\n"; if (listeVisites != null && listeVisites.Any()) { foreach (VisiteDTO visite in listeVisites) { message += visite.ToString(); } } } else if (line.StartsWith("rechercherMembreParNom")) { message = "recherche du membre possèdant le nom: " + argumentList[1] + "\n"; var membre = new MembreDTO(); membre.Nom = argumentList[1]; var listeMembre = gestionSport.MembreFacade.RechercherMembreParNom(gestionSport.ConnectionString, membre); } else if (line.StartsWith("rechercherMembre")) { var membre = new MembreDTO(); membre.IdMembre = Convert.ToInt32(argumentList[1]); var membreRecherche = gestionSport.MembreFacade.RechercherMembre(gestionSport.ConnectionString, membre); message = "Recherche d'un membre : " + membreRecherche.ToString(); } else if (line.StartsWith("rechercherSeance")) { var seance = new SeanceDTO(); seance.IdSeance = Convert.ToInt32(argumentList[1]); var seanceRecherche = gestionSport.SeanceFacade.RechercherSeance(gestionSport.ConnectionString, seance); message = "Recherche d'une séance : " + seanceRecherche.ToString(); } else if (line.StartsWith("rechercherInscription")) { var inscription = new InscriptionDTO(); inscription.IdInscription = Convert.ToInt32(argumentList[1]); var inscriptionRecherche = gestionSport.InscriptionFacade.RechercherInscription(gestionSport.ConnectionString, inscription); message = "Recherche d'une inscription : " + inscriptionRecherche.ToString(); } else if (line.StartsWith("rechercherActivite")) { var activite = new ActiviteDTO(); activite.IdActivite = Convert.ToInt32(argumentList[1]); var activiteRecherche = gestionSport.ActiviteFacade.RechercherActivite(gestionSport.ConnectionString, activite); message = "Recherche d'une activite : " + activiteRecherche.ToString(); } else if (line.StartsWith("rechercherEntraineur")) { var entraineur = new EntraineurDTO(); entraineur.IdEntraineur = Convert.ToInt32(argumentList[1]); var entraineurRecherche = gestionSport.EntraineurFacade.RechercherEntraineur(gestionSport.ConnectionString, entraineur); message = "Recherche d'un entraineur : " + entraineurRecherche.ToString(); } else if (line.StartsWith("rechercherAbonnement")) { var abonnement = new AbonnementGymDTO(); abonnement.IdAbonnement = Convert.ToInt32(argumentList[1]); var abonnementRecherche = gestionSport.AbonnementGymFacade.RechercherAbonnement(gestionSport.ConnectionString, abonnement); message = "Recherche de l'abonnement: " + abonnementRecherche.ToString(); } else { message = "commande inconnue\n"; } } catch (Exception exception) { message += exception.Message + "\n"; } richTextBox1.Text += message; }
/// <summary> /// Bouton qui permet de modifier les informations d'une séance dans la base de données /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnModifierSeance_Click(object sender, EventArgs e) { if (lblIdSeance.Text != "") { SeanceDTO nouvelleSeance = new SeanceDTO(); string idSeance = lblIdSeance.Text; string activite = cbActiviteSeance.Text; string entraineur = cbEntraineurSeance.Text; string salle = cbSalleSeance.Text; string limitePlace = txtLimitePlacesSeance.Text; string nbPlaces = txtNombrePlacesSeance.Text; DateTime dateSeance = dateTimePickerDateSeance.Value; string heureDebut = txtHeureDebutSeance.Text; string heureFin = txtHeureFinSeance.Text; nouvelleSeance.IdSeance = Int32.Parse(idSeance); ActiviteDTO activiteSeance = new ActiviteDTO(); activiteSeance.IdActivite = (cbActiviteSeance.SelectedItem as ComboboxItem).Value; nouvelleSeance.Activite = activiteSeance; EntraineurDTO entraineurSeance = new EntraineurDTO(); entraineurSeance.IdEntraineur = (cbEntraineurSeance.SelectedItem as ComboboxItem).Value; nouvelleSeance.Entraineur = entraineurSeance; SalleDTO salleSeance = new SalleDTO(); salleSeance.IdSalle = (cbSalleSeance.SelectedItem as ComboboxItem).Value; nouvelleSeance.Salle = salleSeance; nouvelleSeance.LimitePlace = Int32.Parse(limitePlace); nouvelleSeance.NbPlaces = Int32.Parse(nbPlaces); nouvelleSeance.DateSeance = dateSeance; nouvelleSeance.HeureDebut = float.Parse(heureDebut); nouvelleSeance.HeureFin = float.Parse(heureFin); nouvelleSeance.FlagSupprime = false; if (SeanceIsValid(nouvelleSeance)) { try { if (activite == "musculation") { gestionSportApp.SeanceFacade.ModifierSeanceMusculation(gestionSportApp.ConnectionString, nouvelleSeance); } else { gestionSportApp.SeanceFacade.ModifierSeance(gestionSportApp.ConnectionString, nouvelleSeance); } dataGridViewSeance.Refresh(); ResetFieldsSeance(); this.dataGridViewSeance.Clear(); LoadSeance(); } catch (FacadeException facadeException) { MessageBox.Show(facadeException.Message); } } } else { lblErrorSeance.Text = "Veuillez sélectionner une séance"; } }
/// <summary> /// Vérifie si les données saisie par l'utilisateur sont suffisantes et respectent les règles. /// </summary> /// <param name="seance">La séance dont les données doivent être validées.</param> /// <returns>Vrai si les champs de la séance sont valides, sinon false.</returns> private bool SeanceIsValid(SeanceDTO seance) { bool isValid = true; if (seance.Activite == null) { isValid = false; lblErrorSeance.Text = "Erreur, il n'y a pas d'activité"; } else if (seance.Entraineur == null) { isValid = false; lblErrorSeance.Text = "Erreur, il n'y a pas d'entraineur"; } else if (seance.Salle == null) { isValid = false; lblErrorSeance.Text = "Erreur, il n'y a pas de salle"; } else if (string.IsNullOrEmpty(seance.LimitePlace.ToString())) { isValid = false; lblErrorSeance.Text = "Erreur, vous devez spécifié la limite de places"; } else if (string.IsNullOrEmpty(seance.NbPlaces.ToString())) { isValid = false; lblErrorSeance.Text = "Erreur, vous devez spécifié le nombre de places"; } else if (seance.DateSeance == null) { isValid = false; lblErrorSeance.Text = "Erreur, vous devez spécifié la date de la séance"; } else if (string.IsNullOrEmpty(seance.HeureDebut.ToString())) { isValid = false; lblErrorSeance.Text = "Erreur, vous devez spécifié l'heure de fin"; } else if (string.IsNullOrEmpty(seance.HeureFin.ToString())) { isValid = false; lblErrorSeance.Text = "Erreur, vous devez spécifié l'heure de début"; } return isValid; }
/// <summary> /// Liste tous les inscriptions. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <returns>Une liste de tous les inscriptions s'il y en a, sinon null.</returns> public List<InscriptionDTO> ReadAll(string connectionString) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } List<InscriptionDTO> listeInscriptionDTO = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand readAllPreparedStatement = new MySqlCommand(InscriptionDAO.READ_ALL_REQUEST, connection); readAllPreparedStatement.Prepare(); using (MySqlDataReader dataReader = readAllPreparedStatement.ExecuteReader()) { if (dataReader.HasRows) { listeInscriptionDTO = new List<InscriptionDTO>(); while (dataReader.Read()) { InscriptionDTO uneInscriptionDTO = new InscriptionDTO(); uneInscriptionDTO.IdInscription = dataReader.GetInt32(0); MembreDTO membreDTO = new MembreDTO(); membreDTO.IdMembre = dataReader.GetInt32(1); uneInscriptionDTO.Membre = membreDTO; SeanceDTO seanceDTO = new SeanceDTO(); seanceDTO.IdSeance = dataReader.GetInt32(2); uneInscriptionDTO.Seance = seanceDTO; uneInscriptionDTO.DateInscription = dataReader.GetDateTime(3); uneInscriptionDTO.FlagPaiement = dataReader.GetBoolean(4); uneInscriptionDTO.FlagSupprime = dataReader.GetBoolean(5); listeInscriptionDTO.Add(uneInscriptionDTO); } } } } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } return listeInscriptionDTO; }
/// <summary> /// Efface une séance. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="seanceDTO">Représente la séance qui sera supprimée.</param> public void Delete(string connectionString, SeanceDTO seanceDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand deletePreparedStatement = new MySqlCommand(SeanceDAO.DELETE_REQUEST, connection); deletePreparedStatement.Parameters.AddWithValue("@idSeance", seanceDTO.IdSeance); deletePreparedStatement.Prepare(); deletePreparedStatement.ExecuteNonQuery(); } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } }
/// <inheritedoc/> public void Inscrire(string connectionString, MembreDTO membreDTO, SeanceDTO seanceDTO) { if (membreDTO == null) { throw new ServiceException("Le membre ne peut être null"); } if (seanceDTO == null) { throw new ServiceException("La séance ne peut être null"); } try { MembreDTO unMembreDTO = membreDAO.Find(connectionString, membreDTO); if (unMembreDTO == null) { throw new ServiceException("Le membre passé en paramètre n'existe pas"); } SeanceDTO uneSeanceDTO = seanceDAO.Find(connectionString, seanceDTO); if (uneSeanceDTO == null) { throw new ServiceException("La séance passée en paramètre n'existe pas"); } // Si la date d'inscription est plus grande que la date limite pour s'inscrire à la séance DateTime dateInscription = DateTime.Now; if (dateInscription.CompareTo(uneSeanceDTO.DateSeance) > 0) { throw new ServiceException("La date d'inscription est dépassée"); } // Si le membre est déjà inscrit à la séance à laquelle il veut s'inscrire ou // Si le membre est déjà inscrit à une autre séance qui se déroule en même temps List<InscriptionDTO> ListeInscriptionDTO = inscriptionDAO.FindByMembre(connectionString, membreDTO); if (ListeInscriptionDTO != null && ListeInscriptionDTO.Any()) { foreach (InscriptionDTO inscription in ListeInscriptionDTO) { if (inscription.Membre.IdMembre == unMembreDTO.IdMembre && inscription.Seance.IdSeance == uneSeanceDTO.IdSeance && !inscription.FlagSupprime) { throw new ServiceException("Le membre est déjà inscrit à la séance à laquelle il veut s'inscrire"); } if (inscription.Seance.DateSeance.Equals(uneSeanceDTO.DateSeance) && inscription.Seance.HeureDebut == uneSeanceDTO.HeureDebut) { throw new ServiceException("Le membre est déjà inscrit à une autre séance au même moment"); } } } // Si la limite de place pour une séance est atteinte if (uneSeanceDTO.NbPlaces == uneSeanceDTO.LimitePlace) { throw new ServiceException("La limite de place est atteinte pour cette séance"); } // Si le membre a un retard de paiement; À implémenter au besoin InscriptionDTO uneInscriptionDTO = new InscriptionDTO(); uneInscriptionDTO.Membre = unMembreDTO; uneInscriptionDTO.Seance = uneSeanceDTO; uneInscriptionDTO.DateInscription = dateInscription; Add(connectionString, uneInscriptionDTO); uneSeanceDTO.NbPlaces++; this.seanceDAO.Update(connectionString, uneSeanceDTO); //On incrémente le nombre de personne dans le cours. } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
/// <summary> /// Recherche une séance selon une date, une heure de debut et de fin et une salle. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="seanceDTO">Représente la séance à chercher.</param> /// <returns>La séance s'il y en a, sinon null.</returns> public SeanceDTO FindByMoment(string connectionString, SeanceDTO seanceDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } SeanceDTO seanceRecherche = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand findByMomentPreparedStatement = new MySqlCommand(SeanceDAO.FIND_BY_MOMENT, connection); findByMomentPreparedStatement.Parameters.AddWithValue("@dateSeance", seanceDTO.DateSeance); findByMomentPreparedStatement.Parameters.AddWithValue("@heureDebut", seanceDTO.HeureDebut); findByMomentPreparedStatement.Parameters.AddWithValue("@heureFin", seanceDTO.HeureFin); findByMomentPreparedStatement.Parameters.AddWithValue("@idSalle", seanceDTO.Salle.IdSalle); findByMomentPreparedStatement.Prepare(); using (MySqlDataReader dataReader = findByMomentPreparedStatement.ExecuteReader()) { if (dataReader.Read()) { seanceRecherche = new SeanceDTO(); seanceRecherche.IdSeance = dataReader.GetInt32(0); //Activite ActiviteDTO activiteDTO = new ActiviteDTO(); activiteDTO.IdActivite = dataReader.GetInt32(1); seanceRecherche.Activite = activiteDTO; //Entraineur. EntraineurDTO entraineurDTO = new EntraineurDTO(); entraineurDTO.IdEntraineur = dataReader.GetInt32(2); seanceRecherche.Entraineur = entraineurDTO; //Salle. SalleDTO salleDTO = new SalleDTO(); salleDTO.IdSalle = dataReader.GetInt32(3); seanceRecherche.Salle = salleDTO; seanceRecherche.LimitePlace = dataReader.GetInt32(4); seanceRecherche.NbPlaces = dataReader.GetInt32(5); seanceRecherche.DateSeance = dataReader.GetDateTime(6); seanceRecherche.HeureDebut = dataReader.GetFloat(7); seanceRecherche.HeureFin = dataReader.GetFloat(8); seanceRecherche.FlagSupprime = dataReader.GetBoolean(9); } } } } catch (InvalidCastException invalidCastException) { throw new DAOException(invalidCastException.Message, invalidCastException); } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } return seanceRecherche; }
public SeanceDTO Find(string connectionString, SeanceDTO seanceDTO) { SeanceDTO seanceRecherche = null; try { seanceRecherche = seanceDAO.Find(connectionString, seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } return seanceRecherche; }
/// <summary> /// Recherhe les seances à l'aide d'une salle. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="seanceDTO">Représente la séance à trouver.</param> /// <returns>S'il y a des séances, une liste de celles-ci, sinon null.</returns> public List<SeanceDTO> FindBySalle(string connectionString, SalleDTO salleDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } List<SeanceDTO> listeSeance = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand findByEntraineurPreparedStatement = new MySqlCommand(SeanceDAO.FIND_BY_SALLE, connection); findByEntraineurPreparedStatement.Parameters.AddWithValue("@idSalle", salleDTO.IdSalle); using (MySqlDataReader dataReader = findByEntraineurPreparedStatement.ExecuteReader()) { if (dataReader.HasRows) // Si la requête n'est pas vide { listeSeance = new List<SeanceDTO>(); while (dataReader.Read()) { SeanceDTO seanceRecherche = new SeanceDTO(); seanceRecherche.IdSeance = dataReader.GetInt32(0); //Activite ActiviteDTO activiteRecherche = new ActiviteDTO(); activiteRecherche.IdActivite = dataReader.GetInt32(1); seanceRecherche.Activite = activiteRecherche; //Entraineur. EntraineurDTO entraineurRecherche = new EntraineurDTO(); entraineurRecherche.IdEntraineur = dataReader.GetInt32(2); seanceRecherche.Entraineur = entraineurRecherche; //Salle. SalleDTO salleRecherche = new SalleDTO(); salleRecherche.IdSalle = dataReader.GetInt32(3); seanceRecherche.Salle = salleRecherche; seanceRecherche.LimitePlace = dataReader.GetInt32(4); seanceRecherche.NbPlaces = dataReader.GetInt32(5); seanceRecherche.DateSeance = dataReader.GetDateTime(6); seanceRecherche.HeureDebut = dataReader.GetFloat(7); seanceRecherche.HeureFin = dataReader.GetFloat(8); seanceRecherche.FlagSupprime = dataReader.GetBoolean(9); listeSeance.Add(seanceRecherche); } } } } } catch (MySqlException mySqlException) { throw new DAOException(mySqlException.Message, mySqlException); } return listeSeance; }
public void ModifierSeanceMusculation(string connectionString, SeanceDTO seanceDTO) { if (seanceDTO == null) { throw new ServiceException("La séance ne peut être null."); } if (seanceDTO.DateSeance == null) { throw new ServiceException("La date de la séance n'a pas été spécifié."); } if (seanceDTO.DateSeance.CompareTo(DateTime.Now) < 0) { throw new ServiceException("La date de la séance ne peut pas être une date qui a déjà été passé."); } if (seanceDTO.Entraineur == null) { throw new ServiceException("L'entraineur n'a pas été spécifé."); } try { EntraineurDTO entraineurDTO = this.entraineurDAO.Find(connectionString, seanceDTO.Entraineur); if (entraineurDTO == null) { throw new ServiceException("L'entraineur spécifié n'existe pas."); } List<SeanceDTO> listeSeancesCourantes = ReadAll(connectionString); if (listeSeancesCourantes != null && listeSeancesCourantes.Any()) { foreach (var seance in listeSeancesCourantes) { if (seance.IdSeance != seanceDTO.IdSeance && seance.DateSeance == seanceDTO.DateSeance) { float heureDebutDeLaNouvelleSeance = seanceDTO.HeureDebut; float heureDebutSeance = seance.HeureDebut; float heureFinSeance = seance.HeureFin; if (seance.Entraineur.IdEntraineur == entraineurDTO.IdEntraineur) { if (heureDebutDeLaNouvelleSeance >= heureDebutSeance && heureDebutDeLaNouvelleSeance < heureFinSeance) { throw new ServiceException("L'entraineur choisit travail déjà dans la la plage horaire d'une autre séance."); } } } } } Update(connectionString, seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
/// <summary> /// Lit tous les séances. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <returns>Une liste de tous les seances, s'il y en a, sinon null.</returns> public List<SeanceDTO> ReadAll(string connectionString) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } List<SeanceDTO> listeSeance = null; try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand readAllPreparedStatement = new MySqlCommand(SeanceDAO.READ_ALL_REQUEST, connection); readAllPreparedStatement.Prepare(); using (MySqlDataReader dataReader = readAllPreparedStatement.ExecuteReader()) { if (dataReader.HasRows) //S'il y a des rows. { listeSeance = new List<SeanceDTO>(); //On initialise la liste. //idActivite, idEntraineur, idSalle, limitePlace, nbPlace, dateSeance, heureDebut, heureFin, flagSupprime while (dataReader.Read()) { SeanceDTO seanceDTO = new SeanceDTO(); seanceDTO.IdSeance = dataReader.GetInt32(0); //Activite ActiviteDTO activiteDTO = new ActiviteDTO(); activiteDTO.IdActivite = dataReader.GetInt32(1); seanceDTO.Activite = activiteDTO; //Entraineur. EntraineurDTO entraineurDTO = new EntraineurDTO(); entraineurDTO.IdEntraineur = dataReader.GetInt32(2); seanceDTO.Entraineur = entraineurDTO; //Salle. SalleDTO salleDTO = new SalleDTO(); salleDTO.IdSalle = dataReader.GetInt32(3); seanceDTO.Salle = salleDTO; seanceDTO.LimitePlace = dataReader.GetInt32(4); seanceDTO.NbPlaces = dataReader.GetInt32(5); seanceDTO.DateSeance = dataReader.GetDateTime(6); seanceDTO.HeureDebut = dataReader.GetFloat(7); seanceDTO.HeureFin = dataReader.GetFloat(8); seanceDTO.FlagSupprime = dataReader.GetBoolean(9); listeSeance.Add(seanceDTO); } } } } } catch (InvalidCastException invalidCastException) { throw new DAOException(invalidCastException.Message, invalidCastException); } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } return listeSeance; }
public void Update(string connectionString, SeanceDTO seanceDTO) { try { seanceDAO.Update(connectionString, seanceDTO); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
/// <summary> /// Met à jour une séance. /// </summary> /// <param name="connectionString">Les paramètres de connexion à la base de données.</param> /// <param name="seanceDTO">Représente la séance qui sera mise à jour.</param> public void Update(string connectionString, SeanceDTO seanceDTO) { if (string.IsNullOrEmpty(connectionString)) { throw new DAOException("Les paramètres de connexion n'ont pas été initialisé."); } try { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand updatePreparedStatement = new MySqlCommand(SeanceDAO.UPDATE_REQUEST, connection); updatePreparedStatement.Parameters.AddWithValue("@idSeance", seanceDTO.IdSeance); updatePreparedStatement.Parameters.AddWithValue("@idActivite", seanceDTO.Activite.IdActivite); updatePreparedStatement.Parameters.AddWithValue("@idEntraineur", seanceDTO.Entraineur.IdEntraineur); updatePreparedStatement.Parameters.AddWithValue("@idSalle", seanceDTO.Salle.IdSalle); updatePreparedStatement.Parameters.AddWithValue("@limitePlace", seanceDTO.LimitePlace); updatePreparedStatement.Parameters.AddWithValue("@nbPlace", seanceDTO.NbPlaces); updatePreparedStatement.Parameters.AddWithValue("@dateSeance", seanceDTO.DateSeance); updatePreparedStatement.Parameters.AddWithValue("@heureDebut", seanceDTO.HeureDebut); updatePreparedStatement.Parameters.AddWithValue("@heureFin", seanceDTO.HeureFin); updatePreparedStatement.Parameters.AddWithValue("@flagSupprime", seanceDTO.FlagSupprime); //On s'assure que se soit seulement 0 (false) ou 1 (true). updatePreparedStatement.Prepare(); updatePreparedStatement.ExecuteNonQuery(); } } catch (SqlException sqlException) { throw new DAOException(sqlException.Message, sqlException); } }
public void AnnulerSeance(string connectionString, SeanceDTO seanceDTO) { if (seanceDTO == null) { throw new ServiceException("La séance passé en paramètre n'a pas été choisi."); } try { SeanceDTO seanceRecherche = Find(connectionString, seanceDTO); if (seanceRecherche == null) { throw new ServiceException("La séance choisi n'existe pas."); } if (seanceRecherche.FlagSupprime) { throw new ServiceException("La séance a déjà été supprimé"); } if (seanceRecherche.DateSeance.CompareTo(DateTime.Now) < 0) { throw new ServiceException("La date de la séance a déjà été dépassé."); } List<InscriptionDTO> listeInscriptionParSeance = inscriptionDAO.FindBySeance(connectionString, seanceRecherche); if (listeInscriptionParSeance != null && listeInscriptionParSeance.Any()) { throw new ServiceException("Il y a déjà des inscriptions qui ont étés faites pour cette séance, veuillez les effacer pour annuler la séance"); } seanceRecherche.FlagSupprime = true; Update(connectionString, seanceRecherche); } catch (DAOException daoException) { throw new ServiceException(daoException.Message, daoException); } }
/// <summary> /// bouton qui permet de supprimer une seance (change le flag) /// </summary> private void button6_Click(object sender, EventArgs e) { try { if (lblIdSeance.Text != "") { SeanceDTO seanceDTO = new SeanceDTO(); seanceDTO.IdSeance = Int32.Parse(lblIdSeance.Text); GestionSportApp.SeanceFacade.AnnulerSeance(GestionSportApp.ConnectionString, seanceDTO); dataGridViewSeance.Clear(); ResetFieldsSeance(); LoadSeance(); } else { lblErrorSeance.Text = "Veuillez sélectionner une séance"; } } catch (FacadeException facadeException) { MessageBox.Show(facadeException.Message); } }