private void RechargerParticipation() { ParticipationsBLL partBLL = new ParticipationsBLL(); ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); ListeIdeesCadeaux liste = new ListeIdeesCadeaux(); Personne cadeauPour = new Personne(); Evenement evt = new Evenement(); Personne participationDe = new Personne(); participationDe.id_personne = int.Parse(Session["personneID"].ToString()); cadeauPour.id_personne = int.Parse(listeParticipantAyantListe.SelectedItem.Value.ToString()); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); liste = listeBLL.getListeIdeesCadeaux(cadeauPour, evt); Participation participation = partBLL.getParticipation(liste, participationDe); if (participation != null) { lblValeurParticipationListe.Text = "Votre participation est de : " + participation.participation.ToString() + " €"; } else { lblValeurParticipationListe.Text = "Votre participation est de : 0 €"; } }
protected void listePersonnes_onIndexChanged(object sender, EventArgs e) { Personne personneSelection = new Personne(); personneSelection.id_personne = int.Parse(listePersonnes.SelectedItem.Value); chargerCadeauxPersonne(personneSelection); if (listePersonnes.SelectedItem.Value != "0") { Evenement evt = new Evenement(); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); ListeIdeesCadeaux liste = listeBLL.getListeIdeesCadeaux(personneSelection, evt); ParticipationsBLL partBLL = new ParticipationsBLL(); long totalParticipation = partBLL.getTotalParticipation(liste); lbl_participationTotale.Text = totalParticipation + " €"; chargerDetailsParticipation(liste); updatePanel_totalParticipation.Visible = true; } else { updatePanel_totalParticipation.Visible = false; } updatePanel_detailCadeau.Visible = false; }
/// <summary> /// Action effectuée lorsque l'on clique sur le bouton ajout des participants /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAjouterParticipant_Click(object sender, EventArgs e) { //L'utilisateur a confirmé l'ajout des participants sélectionnés if ("Y".Equals(hiddenFieldAjouterParticipant.Value)) { List <Participant> listeParticipantsAAjouter = new List <Participant>(); ProjetCadeaux_Entites.Evenement evt = new ProjetCadeaux_Entites.Evenement(); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); foreach (GridViewRow row in gridViewPersonnesRecherche.Rows) { CheckBox cbChoixPersonne = ((CheckBox)row.FindControl("cbChoixPersonne")); if (cbChoixPersonne.Checked) { CheckBox cbHasListe = ((CheckBox)row.FindControl("cbChoixListe")); String id = gridViewPersonnesRecherche.DataKeys[row.RowIndex]["id_personne"].ToString(); String nomSelect = row.Cells[3].Text; String prenomSelect = row.Cells[4].Text; Participant part = new Participant(); part.hasListe = cbHasListe.Checked; part.nom_participant = nomSelect + " " + prenomSelect; part.id_personne = int.Parse(id); part.id_evenement = int.Parse(ViewState["evenementId"].ToString()); listeParticipantsAAjouter.Add(part); } } gridViewPersonnesRecherche.DataSource = null; gridViewPersonnesRecherche.DataBind(); ParticipantBLL partBLL = new ParticipantBLL(); ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); Boolean retour = partBLL.ajouterListeParticipant(listeParticipantsAAjouter) && listeService.creerListeIdeesCadeaux(listeParticipantsAAjouter, evt); if (!retour) { FailureText.Text = "Tous les participants n'ont pas pû être ajoutés"; } else { SuccessText.Text = "Les participants ont été ajoutés"; } btnAjouterParticipant.Visible = false; RechargerGridViewParticipants(); } }
private void RechargerParticipation() { ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); ListeIdeesCadeaux liste = new ListeIdeesCadeaux(); Personne cadeauPour = new Personne(); liste = listeBLL.getListeIdeesCadeaux(personneListe, evenement); participation = participationBLL.getParticipation(liste, personneConnectee); }
private void RecupererListeCadeaux() { if (Session["connecte"] != null) { ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); listeCadeaux = listeBLL.getIdeesCadeauxByPersonneAndEvenement(personneListe, evenement); } else { Response.Redirect("~/"); } }
protected void btnAjouterIdee_Click(object sender, EventArgs e) { btnAjoutSuggestionListe.Enabled = false; Boolean retour = true; IdeesCadeauxProposes ideeCadeau = new IdeesCadeauxProposes(); ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); Evenement evt = new Evenement(); Personne pers = new Personne(); IdeeCadeau idee = new IdeeCadeau(); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); String titre = TitreCadeau.Text; String description = Description.Text; String prix = Prix.Text; String personne = listeParticipantAyantListe.SelectedItem.Value.ToString(); String priorite = Priorite.Text; string ideeCadeau_id = ideeCadeau.ajouterIdeeCadeau(titre, description, prix, priorite, personne, Session["personneID"].ToString(), tb_lien1.Text, tb_lien2.Text, tb_lien3.Text, tb_lien4.Text, tb_lien5.Text); pers.id_personne = int.Parse(personne); idee.id_ideeCadeau = int.Parse(ideeCadeau_id); if (ideeCadeau_id != null) { retour = listeService.ajouterCadeauToListe(pers, evt, idee); } viderSuggestionForm(); RechargerListeIdeesCadeauxSuggeres(); btnAjoutSuggestionListe.Enabled = true; if (retour) { FailureText.Text = ""; SuccessText.Text = "La suggestion a bien été ajoutée."; } else { SuccessText.Text = ""; FailureText.Text = "Erreur lors de l'ajout de la suggestion."; } }
protected void btnAjouterIdee_Click(object sender, EventArgs e) { IdeesCadeaux ideeCadeau = new IdeesCadeaux(); ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); Evenement evt = new Evenement(); Personne pers = new Personne(); IdeeCadeau idee = new IdeeCadeau(); Boolean retour = true; String titre = TitreCadeau.Text; String description = Description.Text; String prix = Prix.Text; String personne = Session["personneID"].ToString(); String priorite = Priorite.Text; String evenementId = ViewState["evenementIdSelection"].ToString(); String ideeCadeau_id = ideeCadeau.ajouterIdeeCadeau(titre, description, prix, priorite, personne, tb_lien1.Text, tb_lien2.Text, tb_lien3.Text, tb_lien4.Text, tb_lien5.Text); evt.id_evenement = int.Parse(evenementId); pers.id_personne = int.Parse(personne); idee.id_ideeCadeau = int.Parse(ideeCadeau_id); if (ideeCadeau_id != null) { retour = listeService.ajouterCadeauToListe(pers, evt, idee); } if (retour) { viderForm(); FailureText.Text = ""; SuccesText.Text = "L'idée a bien été ajoutée."; } else { SuccesText.Text = ""; FailureText.Text = "L'idée n'a pas été correctement ajoutée."; } }
private void Refresh() { if (Session["connecte"] != null) { if (ddl_choixEvenement.DataValueField != null) { Personne pers = new Personne(); Evenement evt = new Evenement(); evt.id_evenement = int.Parse(ddl_choixEvenement.SelectedValue); pers.id_personne = int.Parse(Session["personneID"].ToString()); ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); ListeIdeesCadeaux listeRetour = listeService.getListeIdeesCadeauxPasSuggere(pers, evt); if (listeRetour != null) { gridViewMesCadeaux.DataSource = listeRetour.listeDeCadeaux; gridViewMesCadeaux.DataBind(); } else { gridViewMesCadeaux.DataSource = null; gridViewMesCadeaux.DataBind(); } } else { gridViewMesCadeaux.DataSource = null; gridViewMesCadeaux.DataBind(); } } else { Response.Redirect("~/"); } }
protected void btnAjouterParticipation_Click(object sender, EventArgs e) { ParticipationsBLL partBLL = new ParticipationsBLL(); ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); ListeIdeesCadeaux liste = new ListeIdeesCadeaux(); Personne cadeauPour = new Personne(); Evenement evt = new Evenement(); Personne participationDe = new Personne(); participationDe.id_personne = int.Parse(Session["personneID"].ToString()); cadeauPour.id_personne = int.Parse(listeParticipantAyantListe.SelectedItem.Value.ToString()); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); liste = listeBLL.getListeIdeesCadeaux(cadeauPour, evt); Participation part = new Participation(); part.id_liste = liste.id_listeIdeesCadeaux; part.id_personne = int.Parse(Session["personneID"].ToString()); Boolean isParticipationCorrecte = true; try { part.participation = long.Parse(tbParticipation.Text); } catch (Exception) { isParticipationCorrecte = false; lbPbParticipation.Text = "Vous devez saisir un nombre dans participation. (exemple: 20)"; SuccessText.Text = ""; } //Si l'utilisateur a bien saisi une participation correcte, on peut modifier if (isParticipationCorrecte) { if (partBLL.getParticipation(liste, participationDe) == null) { if (partBLL.ajouterParticipation(part)) { tbParticipation.Text = ""; lbPbParticipation.Text = ""; SuccessText.Text = "Vous avez bien ajouté votre participation à cette liste !"; RechargerParticipation(); afficherGroupeModificationParticipation(false); } else { lbPbParticipation.Text = "Erreur dans l'enregistrement de la participation. Vous devez saisir un nombre. (exemple: 20)"; SuccessText.Text = ""; } } else { if (partBLL.modifierParticipation(part)) { lbPbParticipation.Text = ""; SuccessText.Text = "Votre participation a été modifiée."; RechargerParticipation(); afficherGroupeModificationParticipation(false); } else { lbPbParticipation.Text = "Erreur dans l'enregistrement de la participation. Vous devez saisir un nombre. (exemple: 20)"; SuccessText.Text = ""; } } } }
/// <summary> /// Charge l'ensemble des participations dans la datagrid /// </summary> /// <param name="p"></param> public void chargerTableauParticipations(string evenementId) { List <ListeIdeesCadeaux> listeIdeesCadeaux = null; List <Participation> listeParticipation = null; try { //Récupérer l'ensemble des listes actives pour cet évènement Evenement evt = new Evenement(); evt.id_evenement = int.Parse(evenementId); ListeIdeesCadeauxBLL listeBLL = new ListeIdeesCadeauxBLL(); listeIdeesCadeaux = listeBLL.getAllListeIdeesCadeaux(evt); //Récupérer l'ensemble des participations de la personne connectée pour cet évènement Participation parti = new Participation(); parti.id_personne = int.Parse(Session["personneID"].ToString()); ParticipationsBLL partService = new ParticipationsBLL(); listeParticipation = partService.getAllParticipations(parti, evt); //Merger les deux infos dans une DataTable pour s'en servir de DataSource DataTable dtMerge = new DataTable(); dtMerge = preparerTable(dtMerge); //Représente la liste des responsables avec l'argent que la personne connectée doit Dictionary <int, long> mapDette = new Dictionary <int, long>(); //Représente la liste des sous que doivent les personnes pour les listes où l'utilisateur connecté est responsable Dictionary <int, long> mapCredit = new Dictionary <int, long>(); //Représente la liste des noms par id, pour éviter de refaire une requête Dictionary <int, string> mapNoms = new Dictionary <int, string>(); HashSet <int> setCle = new HashSet <int>(); //On parcourt les listes actives foreach (ListeIdeesCadeaux liste in listeIdeesCadeaux) { ResponsablesBLL respoService = new ResponsablesBLL(); //On cherche le responsable de la liste Personne responsable = respoService.getInfosResponsableDe(liste.listeIdeesCadeauxPour, liste.listePourEvenement); if (responsable != null) { //Si on est responsable de cette liste, on va ajouter les participations des autres if (responsable.id_personne == int.Parse(Session["personneID"].ToString())) { List <Participation> listeParticipationAListe = new List <Participation>(); listeParticipationAListe = partService.getListeParticipation(liste); foreach (Participation particAListe in listeParticipationAListe) { //S'il ne s'agit pas de notre propre participation if (particAListe.id_personne != responsable.id_personne) { //Si la personne devant de l'argent n'existait pas encore, on la créé avec la participation if (!mapCredit.ContainsKey(particAListe.id_personne)) { mapCredit.Add(particAListe.id_personne, particAListe.participation); setCle.Add(particAListe.id_personne); if (!mapNoms.ContainsKey(particAListe.id_personne)) { mapNoms.Add(particAListe.id_personne, particAListe.personne.prenom + " " + particAListe.personne.nom.ToUpper()); } } //si on devait de l'argent au responsable, on ajoute la nouvelle participation else { mapCredit[particAListe.id_personne] = mapCredit[particAListe.id_personne] + particAListe.participation; } } } } //Si on n'est pas responsable, on ajoute ce qu'on doit au responsable else { foreach (Participation part in listeParticipation) { if (part.id_liste == liste.id_listeIdeesCadeaux) { //Si le responsable n'existait pas encore, on le créé avec la participation if (!mapDette.ContainsKey(responsable.id_personne)) { mapDette.Add(responsable.id_personne, part.participation); setCle.Add(responsable.id_personne); if (!mapNoms.ContainsKey(responsable.id_personne)) { mapNoms.Add(responsable.id_personne, responsable.prenom + " " + responsable.nom.ToUpper()); } } //si on devait de l'argent au responsable, on ajoute la nouvelle participation else { mapDette[responsable.id_personne] = mapDette[responsable.id_personne] + part.participation; } } } } } } foreach (int key in setCle) { DataRow row = dtMerge.NewRow(); row["id"] = key; row["personne"] = mapNoms[key]; row["jedois"] = mapDette.ContainsKey(key) ? mapDette[key] : 0; row["onmedoit"] = mapCredit.ContainsKey(key) ? mapCredit[key] : 0; dtMerge.Rows.Add(row); } //ATTENTION : Penser qu'on doit l'argent au responsable de la liste, et pas à celui pour qui est la liste ! gridView_listeDettes.DataSource = dtMerge; gridView_listeDettes.DataBind(); } catch (Exception e) { FailureText.Text = "Erreur dans la récupération du tableau"; SuccessText.Text = ""; } }
protected void RowCommand_click(object sender, GridViewCommandEventArgs e) { #region action suppression if (e.CommandName == "supprimer") { int index = Convert.ToInt32(e.CommandArgument); ListeIdeesCadeauxBLL idee = new ListeIdeesCadeauxBLL(); String cle = gridViewMesCadeaux.DataKeys[index].Value.ToString(); IdeeCadeauPourListe ideeCadeau = new IdeeCadeauPourListe(); ideeCadeau.id_ideeCadeau = int.Parse(cle); idee.supprimerCadeauFromListe(ideeCadeau); Refresh(); } #endregion #region action modification else if (e.CommandName == "modifier") { int index = Convert.ToInt32(e.CommandArgument); IdeesCadeaux idee = new IdeesCadeaux(); Liens lien = new Liens(); String cle = gridViewMesCadeaux.DataKeys[index].Value.ToString(); ViewState["cleIdeeCadeauModification"] = cle; viderForm(); updatePanelAjoutCadeaux.Visible = true; updatePanelIdeesCadeaux.Visible = false; btn_AjouterCadeau.Visible = false; btn_ModifierCadeau.Visible = true; DataTable dt = idee.getIdeeCadeauById(cle); TitreCadeau.Text = dt.Rows[0].ItemArray.GetValue(1).ToString(); Description.Text = dt.Rows[0].ItemArray.GetValue(2).ToString(); Prix.Text = dt.Rows[0].ItemArray.GetValue(3).ToString(); Priorite.Text = dt.Rows[0].ItemArray.GetValue(0).ToString(); DataTable dt2 = lien.getInfosLiensByIdeeCadeau(cle); for (int i = 0; i < dt2.Rows.Count; i++) { switch (i) { case 0: tb_lien1.Text = dt2.Rows[i].ItemArray.GetValue(0).ToString(); break; case 1: tb_lien2.Text = dt2.Rows[i].ItemArray.GetValue(0).ToString(); break; case 2: tb_lien3.Text = dt2.Rows[i].ItemArray.GetValue(0).ToString(); break; case 3: tb_lien4.Text = dt2.Rows[i].ItemArray.GetValue(0).ToString(); break; case 4: tb_lien5.Text = dt2.Rows[i].ItemArray.GetValue(0).ToString(); break; } } } #endregion }
/// <summary> /// Action effectuée lorsque l'on clique sur le bouton enregistrer les modifications /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnModifierParticipant_Click(object sender, EventArgs e) { List <Participant> listeParticipantsAModifier = new List <Participant>(); List <Participant> listeParticipants = new List <Participant>(); ParticipantBLL partService = new ParticipantBLL(); Participant partTemp = new Participant(); foreach (GridViewRow row in gridViewParticipants.Rows) { String id = gridViewParticipants.DataKeys[row.RowIndex]["id_participant"].ToString(); Participant part = new Participant(); part.id_participant = int.Parse(id); part.id_evenement = int.Parse(ViewState["evenementId"].ToString()); part.hasListe = ((CheckBox)row.FindControl("cbHasListe")).Checked; //On récupère l'id de la personne partTemp = partService.getAllInfosByParticipant(part); if (partTemp != null) { part.id_personne = partTemp.id_personne; } listeParticipants.Add(part); } //Ne garder que les participants modifiés int cle = int.Parse(ViewState["evenementId"].ToString()); EvenementBLL evtBLL = new EvenementBLL(); ParticipantBLL ptcpBLL = new ParticipantBLL(); Evenement evt = evtBLL.getEvenementById(cle); List <Participant> listeParticipantsBefore = ptcpBLL.getAllParticipantByEvenement(evt); if (listeParticipants.Count == listeParticipantsBefore.Count) { for (int i = 0; i < listeParticipants.Count; i++) { if (listeParticipants[i].id_participant == listeParticipantsBefore[i].id_participant && listeParticipants[i].hasListe != listeParticipantsBefore[i].hasListe) { listeParticipantsAModifier.Add(listeParticipants[i]); } } } //Modifier les participants if (listeParticipantsAModifier.Count > 0) { ParticipantBLL partBLL = new ParticipantBLL(); ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); Boolean retour = partBLL.modifierHasListesListeParticipants(listeParticipantsAModifier) && listeService.updateActiveListe(listeParticipantsAModifier, evt); if (retour) { SuccessText.Text = "Les modifications ont bien été prises en compte"; } else { FailureText.Text = "Les modifications n'ont pas pu être prises en compte"; } RechargerGridViewParticipants(); } }
/// <summary> /// Action de suppression des participants sélectionnés /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSupprimerParticipant_Click(object sender, EventArgs e) { //L'utilisateur a confirmé la suppression des participants if ("Y".Equals(supprimerParticipants.Value)) { Boolean connecteEstParticipantASupprimer = false; List <Participant> listeParticipantsASupprimer = new List <Participant>(); ParticipantBLL partService = new ParticipantBLL(); Participant partTemp = new Participant(); foreach (GridViewRow row in gridViewParticipants.Rows) { CheckBox cbChoixParticipant = ((CheckBox)row.FindControl("cbChoix")); if (cbChoixParticipant.Checked) { String id = gridViewParticipants.DataKeys[row.RowIndex]["id_participant"].ToString(); if (id.Equals(Session["personneID"].ToString())) { connecteEstParticipantASupprimer = true; } Participant part = new Participant(); part.id_participant = int.Parse(id); part.id_evenement = int.Parse(ViewState["evenementId"].ToString()); partTemp = partService.getAllInfosByParticipant(part); if (partTemp != null) { part.id_personne = partTemp.id_personne; } listeParticipantsASupprimer.Add(part); } } if (!connecteEstParticipantASupprimer) { ListeIdeesCadeauxBLL listeService = new ListeIdeesCadeauxBLL(); ProjetCadeaux_Entites.Evenement evt = new ProjetCadeaux_Entites.Evenement(); evt.id_evenement = int.Parse(ViewState["evenementId"].ToString()); Boolean retour = partService.supprimerListeParticipants(listeParticipantsASupprimer) && listeService.desactiverListe(listeParticipantsASupprimer, evt); if (retour) { SuccessText.Text = "Tous les participants sélectionnés ont pu être supprimés"; } else { FailureText.Text = "Les participants n'ont pas pu être supprimés"; } RechargerGridViewParticipants(); } else { FailureText.Text = "Vous ne pouvez supprimer l'administrateur de l'évènement"; } } }
protected void btnAjouterEvt_Click(object sender, EventArgs e) { int idPersonne = int.Parse(Session["personneID"].ToString()); ProjetCadeaux_Entites.Evenement evt = new ProjetCadeaux_Entites.Evenement(); evt.libelle = TitreEvenementTb.Text; evt.dateEvenement = DateTime.Parse(dateEvenementTb.Text); evt.dateButoir = DateTime.Parse(dateButoirTb.Text); evt.id_admin = idPersonne; Participant participant = new Participant(); participant.dateAjout = DateTime.Now; participant.id_personne = idPersonne; participant.hasListe = hasListeCb.Checked; EvenementBLL evtBLL = new EvenementBLL(); ProjetCadeaux_Entites.Evenement evtRetour = evtBLL.creerEvenement(evt, participant); ListeIdeesCadeauxBLL listeIdeesService = new ListeIdeesCadeauxBLL(); if (evtRetour != null) { ListeIdeesCadeaux listeRetour = listeIdeesService.creerListeIdeesCadeaux(participant, evtRetour, hasListeCb.Checked); if (listeRetour != null) { SuccessText.Text = "L'évènement a bien été créé."; FailureText.Text = null; TitreEvenementTb.Text = ""; dateEvenementTb.Text = ""; dateButoirTb.Text = ""; hasListeCb.Checked = false; Page_Load(sender, e); } else { TitreEvenementTb.Text = ""; dateEvenementTb.Text = ""; dateButoirTb.Text = ""; hasListeCb.Checked = false; SuccessText.Text = null; FailureText.Text = "L'évènement a été créé, mais la liste n'a pas été créée."; Page_Load(sender, e); } } else { TitreEvenementTb.Text = ""; dateEvenementTb.Text = ""; dateButoirTb.Text = ""; hasListeCb.Checked = false; SuccessText.Text = null; FailureText.Text = "L'évènement n'a pas pu être créé."; Page_Load(sender, e); } }