protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { int index = Convert.ToInt32(e.CommandArgument); GridView gv = ( GridView )e.CommandSource; Guid answerGuid = new Guid(gv.DataKeys[index].Value.ToString()); int status = PollAnswer.Delete(answerGuid); } }
protected void TextBoxQuestion_TextChanged(object sender, EventArgs e) { Reporter.Trace("TextBoxQuestion_TextChanged"); BloquerQuestionnaire(SessionState.Questionnaire.Bloque); try { TextBox textBox = ( TextBox )sender; HiddenField hf = new HiddenField(); hf = ( HiddenField )textBox.Parent.FindControl("PollQuestionId"); Guid pollQuestionId = new Guid(hf.Value); PollQuestion question = SessionState.Questions.FindByPollQuestionID(pollQuestionId); // Mise a jour de la Question if (textBox.Text.Trim() != string.Empty) { question.Question = textBox.Text.Trim(); PollQuestion.Update(question); } else // Suppression de la Question des Reponses et des Votes associes { int status = 0; PollAnswerCollection reponses = PollAnswerCollection.GetByPollQuestionID(question.PollQuestionId); foreach (PollAnswer reponse in reponses) { PollVoteCollection votes = PollVoteCollection.GetVotes(reponse.PollAnswerId); foreach (PollVote vote in votes) { status += PollVote.Delete(vote.VoteId); } status += PollAnswer.Delete(reponse.PollAnswerId); } status += PollQuestion.Delete(question.PollQuestionId); SessionState.Limitations.SupprimerQuestion(); RebuildDataList(); } } catch { } }
protected void ButtonSupprimer_Click(object sender, EventArgs e) { if (Cache["MembreGUID"] == null || ( Guid )Cache["MembreGUID"] == Guid.Empty) { ValidationMessage.Text += "<br/>Choisir un membre à supprimer.<br/>"; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; ValidationMessage.Visible = true; } else { int status = 0; int statusGlobal = 0; ValidationMessage.Text += "<br />-----------------------------------------------------<br />"; ValidationMessage.Text += " Début de la Suppression du Membre <br />"; ValidationMessage.Text += "-----------------------------------------------------<br />"; Reporter.Trace("ButtonSupprimer_Click début"); MemberInfo member = MemberInfo.Get(( Guid )Cache["MembreGUID"]); foreach (Questionnaire questionnaire in (QuestionnaireCollection)Cache["Questionnaires"]) { int QuestionnaireID = questionnaire.QuestionnaireID; ValidationMessage.Text += "--- Suppression du Questionnaire : " + questionnaire.Description + ":" + questionnaire.CodeAcces + " questions : "; PollQuestionCollection questions = PollQuestionCollection.GetByQuestionnaire(QuestionnaireID); ValidationMessage.Text += questions.Count + "<br />"; foreach (PollQuestion question in questions) { PollAnswerCollection reponses = PollAnswerCollection.GetByPollQuestionID(question.PollQuestionId); foreach (PollAnswer reponse in reponses) { PollVoteCollection votes = PollVoteCollection.GetVotes(reponse.PollAnswerId); int nbVotes = PollVoteCollection.NumberOfVotesByAnswer(reponse.PollAnswerId); ValidationMessage.Text += "----- Suppression des votes : " + nbVotes.ToString() + "<br />"; foreach (PollVote vote in votes) { status = PollVote.Delete(vote.VoteId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "---- Suppression de la Réponse : " + reponse.Answer + "<br />"; status = PollAnswer.Delete(reponse.PollAnswerId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "--- Suppression de la Question : " + question.Question + "<br />"; status = PollQuestion.Delete(question.PollQuestionId); SessionState.Limitations.SupprimerQuestion(); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } PersonneCollection personnes = PersonneCollection.GetQuestionnaire(QuestionnaireID); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contacts : " + personnes.Count + "<br />"; foreach (Personne p in personnes) { ValidationMessage.Text += p.Nom + " " + p.Prenom + " " + p.EmailBureau + " " + p.Societe + "<br />"; status = Personne.Delete(p.ID_Personne); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } SessionState.Limitations.SupprimerInterviewes(personnes.Count); WebContentCollection webContents = WebContentCollection.GetWebContents(member.NomUtilisateur, questionnaire.CodeAcces.ToString()); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contenus web pour le Questionnaire : " + webContents.Count + "<br />"; foreach (WebContent wc in webContents) { ValidationMessage.Text += wc.Section + " " + wc.Utilisateur + " " + wc.Visualisateur + "<br />"; status = WebContent.Delete(wc.WebContentID); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des scores : " + (( ScoreCollection )Cache["Scores"]).Count + "<br />"; foreach (Score s in ( ScoreCollection )Cache["Scores"]) { status = Score.Delete(s.ScoreID); statusGlobal = statusGlobal + status; } ValidationMessage.Text += "Suppression du Questionnaire : " + questionnaire.Description + "<br />"; status = Questionnaire.Delete(questionnaire.QuestionnaireID); statusGlobal = statusGlobal + status; SessionState.Limitations.SupprimerQuestionnaire(); ValidationMessage.Text += "status : " + status.ToString() + "<br />"; }// Fin de foreach ( Questionnaire questionnaire in Questionnaires ) Reporter.Trace("foreach ( Questionnaire questionnaire in Questionnaires ) fin"); ValidationMessage.Text += "Suppression des contenus web pour Tout Le Monde : " + (( WebContentCollection )Cache["WebContentsToutLeMonde"]).Count + "<br />"; foreach (WebContent wc in ( WebContentCollection )Cache["WebContentsToutLeMonde"]) { ValidationMessage.Text += wc.Section + " " + wc.Utilisateur + " " + wc.Visualisateur + "<br />"; status = WebContent.Delete(wc.WebContentID); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } MembershipUser user = Membership.GetUser(( Guid )Cache["MembreGUID"]); Reporter.Trace("Directory.Exists( dirStyleWeb ) début"); ValidationMessage.Text += "Suppression des styles web :<br />"; string dirStyleWeb = Server.MapPath("~/App_Data/StyleWeb/" + user.UserName); if (Directory.Exists(dirStyleWeb)) { List <Fichier> fichiers = Tools.GetAllFichiers(dirStyleWeb); if (fichiers.Count <= 0) { ValidationMessage.Text += "-- Pas de style web<br />"; } else { foreach (Fichier f in fichiers) { try { File.Delete(f.Nom); string nomFichier = Tools.GetFileNameWithoutExtension(f.Nom); ValidationMessage.Text += "-- fichier supprimé : " + nomFichier + "<br />"; } catch { string nomFichier = Tools.GetFileNameWithoutExtension(f.Nom); ValidationMessage.Text += "-- ERREUR à la suppression du fichier : " + nomFichier + "<br />"; } } } ValidationMessage.Text += "Suppression du répertoire : " + user.UserName; try { Directory.Delete(dirStyleWeb); } catch (Exception ex) { ValidationMessage.Text += " Erreur : " + ex.Message + "</br>"; } ValidationMessage.Text += "</br>"; } else { ValidationMessage.Text += "-- Pas de style web<br />"; } ValidationMessage.Text += "</br>"; Reporter.Trace("Directory.Exists( dirStyleWeb ) fin"); ValidationMessage.Text += "Suppression du fichier de paramètres :<br />"; string fileName = Server.MapPath("~/App_Data/MemberSettings/" + user.UserName + ".xml"); if (File.Exists(fileName)) { File.Delete(fileName); string nomFichier = Tools.GetFileNameWithoutExtension(fileName); ValidationMessage.Text += "-- fichier supprimé : " + nomFichier + "<br />"; } else { string nomFichier = Tools.GetFileNameWithoutExtension(fileName); ValidationMessage.Text += "-- ERREUR à la suppression du fichier : " + nomFichier + "<br />"; } ValidationMessage.Text += "</br>"; Reporter.Trace("SmtpServer.Get( member.MembreGUID ) début"); SmtpServer stmpServeur = SmtpServer.Get(member.MembreGUID); if (stmpServeur != null) { ValidationMessage.Text += "Suppression du Serveur SMTP :" + stmpServeur.ServerName + "<br />"; status = SmtpServer.Delete(stmpServeur.SmtpServerID); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } Reporter.Trace("SmtpServer.Get( member.MembreGUID ) fin"); ValidationMessage.Text += "Suppression du Membre : " + member.Nom + " " + member.Prenom + " " + user.Email + " " + user.UserName + "<br />"; status = MemberInfo.Delete(( Guid )Cache["MembreGUID"]); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; ValidationMessage.Text += "Suppression de l'Utilisateur : " + user.UserName + "<br />"; bool ok = Membership.DeleteUser(user.UserName, true); if (ok) { status = 0; } else { status = 1; } ValidationMessage.Text += "status : " + status.ToString() + "<br />"; ValidationMessage.Text += "<br />status global : " + statusGlobal.ToString() + "<br />"; ValidationMessage.Visible = true; // Forcer les Questionnaires a se recharger depuis la Base de Donnees SessionState.Questionnaires = null; SessionState.Questionnaire = null; Cache["MembreGUID"] = Guid.Empty; // Si c'est un membre qui supprime sont compte if (User.IsInRole("Administrateur") == false) { // Message de suppression d'un membre a l'admin string sujetEmail2 = "Suppression d'un Membre sur le site : " + Global.SettingsXml.SiteNom; string bodyEmail2 = ""; bodyEmail2 += "Nom d'utilisateur : " + SessionState.MemberInfo.NomUtilisateur + "<br/>"; bodyEmail2 += "Nom : " + SessionState.MemberInfo.Nom + "<br/>"; bodyEmail2 += "Prénom : " + SessionState.MemberInfo.Prenom + "<br/>"; bodyEmail2 += "Société : " + SessionState.MemberInfo.Societe + "<br/>"; bodyEmail2 += "Téléphone : " + SessionState.MemberInfo.Telephone + "<br/>"; bodyEmail2 += "Adresse : " + SessionState.MemberInfo.Adresse + "<br/>"; bodyEmail2 += "Email : " + user.Email + "<br/>"; bodyEmail2 += "<br/>Accès à l'application :<br/>" + string.Format("<a href=\"{0}\" >{1}</a>", Utils.WebSiteUri, Utils.WebSiteUri) + "<br/>"; MemberInfo admin = MemberInfo.GetMemberInfo("admin"); MembershipUser userAdmin = Membership.GetUser(admin.MembreGUID); Courriel.EnvoyerEmailToAssynchrone(admin.MembreGUID, userAdmin.Email, sujetEmail2, bodyEmail2); // Deconnecter l'utilisateur FormsAuthentication.SignOut(); HttpContext.Current.Session.Abandon(); Response.Redirect("~/Member/Login.aspx"); } } }
protected void ButtonSupprimer_Click(object sender, EventArgs e) { if ((int)Cache["QuestionnaireID"] == 0) { ValidationMessage.Text += "<br/>Choisir un questionnaire à supprimer.<br/>"; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; ValidationMessage.Visible = true; } else { int status = 0; int statusGlobal = 0; Questionnaire questionnaire = Questionnaire.GetQuestionnaire(( int )Cache["QuestionnaireID"]); Reporter.Trace("Questionnaire delete"); ValidationMessage.Text += "<br />-----------------------------------------------------<br />"; ValidationMessage.Text += " Début de la Suppression du Questionnaire <br />"; ValidationMessage.Text += "-----------------------------------------------------<br />"; foreach (PollQuestion question in ( PollQuestionCollection )Cache["Questions"]) { PollAnswerCollection reponses = PollAnswerCollection.GetByPollQuestionID(question.PollQuestionId); foreach (PollAnswer reponse in reponses) { PollVoteCollection votes = PollVoteCollection.GetVotes(reponse.PollAnswerId); int nbVotes = PollVoteCollection.NumberOfVotesByAnswer(reponse.PollAnswerId); ValidationMessage.Text += "----- Suppression des votes : " + nbVotes.ToString() + "<br />"; foreach (PollVote vote in votes) { status = PollVote.Delete(vote.VoteId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "---- Suppression de la Réponse : " + reponse.Answer + "<br />"; status = PollAnswer.Delete(reponse.PollAnswerId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "--- Suppression de la Question : " + question.Question + "<br />"; status = PollQuestion.Delete(question.PollQuestionId); statusGlobal = statusGlobal + status; SessionState.Limitations.SupprimerQuestion(); ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } Reporter.Trace("Questionnaire delete fin"); //PersonneCollection personnes = PersonneCollection.GetQuestionnaire( ( int )Cache[ "QuestionnaireID" ] ); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contacts : " + (( PersonneCollection )Cache["Personnes"]).Count + "<br />"; foreach (Personne p in ( PersonneCollection )Cache["Personnes"]) { ValidationMessage.Text += p.Nom + " " + p.Prenom + " " + p.EmailBureau + " " + p.Societe + "<br />"; status = Personne.Delete(p.ID_Personne); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } SessionState.Limitations.SupprimerInterviewes((( PersonneCollection )Cache["Personnes"]).Count); MemberInfo membre = MemberInfo.GetMemberInfo(questionnaire.MembreGUID); //WebContentCollection webContents = WebContentCollection.GetWebContents( membre.NomUtilisateur, questionnaire.CodeAcces.ToString() ); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contenus web : " + (( WebContentCollection )Cache["WebContents"]).Count + "<br />"; foreach (WebContent wc in ( WebContentCollection )Cache["WebContents"]) { ValidationMessage.Text += wc.Section + " " + wc.Utilisateur + " " + wc.Visualisateur + "<br />"; status = WebContent.Delete(wc.WebContentID); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des scores : " + (( ScoreCollection )Cache["Scores"]).Count + "<br />"; foreach (Score s in ( ScoreCollection )Cache["Scores"]) { status = Score.Delete(s.ScoreID); statusGlobal = statusGlobal + status; } ValidationMessage.Text += "Suppression du Questionnaire : " + questionnaire.Description + "<br />"; status = Questionnaire.Delete(questionnaire.QuestionnaireID); statusGlobal = statusGlobal + status; SessionState.Limitations.SupprimerQuestionnaire(); ValidationMessage.Text += "status : " + status.ToString() + "<br />"; ValidationMessage.Text += "<br />status global : " + statusGlobal.ToString() + "<br />"; ValidationMessage.Visible = true; // Forcer les Questionnaires a se recharger depuis la Base de Donnees SessionState.Questionnaires = null; SessionState.Questionnaire = null; Cache["QuestionnaireID"] = 0; // fermer le formulaire // On ne supprime qu'une fois ! ButtonSupprimer.Visible = false; } }