// Ajouter des Reponses a la Question protected void TextBoxReponse_TextChanged(object sender, EventArgs e) { Reporter.Trace("TextBoxReponse_TextChanged"); BloquerQuestionnaire(SessionState.Questionnaire.Bloque); try { TextBox textBox = ( TextBox )sender; DropDownList ddlTypeReponse = ( DropDownList )textBox.Parent.FindControl("DropDownListTypeReponse"); if (textBox.Text.Trim() != "" && ddlTypeReponse.SelectedValue != "-1") { HiddenField hf = new HiddenField(); hf = ( HiddenField )textBox.Parent.FindControl("PollQuestionId"); Guid pollQuestionId = new Guid(hf.Value); PollQuestion question = SessionState.Questions.FindByPollQuestionID(pollQuestionId); PollAnswerCollection reponses = PollAnswerCollection.GetByPollQuestionID(pollQuestionId); CheckBox cbxObligatoire = ( CheckBox )textBox.Parent.FindControl("CheckBoxObligatoire"); if (textBox.Text.Trim().Contains(";")) { int rank = reponses.MaxRank() + 1; // ajouter les reponses a la suite des reponses existantes string[] reponsesSplit = textBox.Text.Trim().Split(';'); foreach (string rep in reponsesSplit) { PollAnswer reponse = new PollAnswer(rep.Trim()); reponse.PollQuestionId = question.PollQuestionId; reponse.TypeReponse = ddlTypeReponse.SelectedValue; reponse.Obligatoire = cbxObligatoire.Checked; reponse.Rank = rank; int status = PollAnswer.Create(reponse); rank += 1; } } else { PollAnswer reponse = new PollAnswer(); reponse.PollQuestionId = question.PollQuestionId; reponse.Answer = textBox.Text.Trim(); reponse.TypeReponse = ddlTypeReponse.SelectedValue; // reponse.Width = reponse.Width; // reponse.Rows = reponse.Rows; // reponse.AlignLeft = reponse.AlignLeft; // reponse.Horizontal = reponse.Horizontal; reponse.Obligatoire = cbxObligatoire.Checked; reponse.Rank = reponses.MaxRank() + 1; // ajouter la reponse a la suite des reponses existantes int status = PollAnswer.Create(reponse); } RebuildDataList(); } if (ddlTypeReponse.SelectedValue == "-1") { textBox.CssClass = "TextBoxListUserQuestionInstructionRedStyle"; textBox.Text = "Choisir un Type de réponse"; } } catch { } }
protected void Page_Load(object sender, System.EventArgs e) { ValidationMessage.Text = ""; if (!User.IsInRole("Administrateur") && !User.IsInRole("Client")) { GridView1.Columns[0].Visible = false; // Edit delete column DetailsView1.Visible = false; } if (Request["PollId"] == null) { if (SessionState.Questionnaire != null) { SessionState.Questions = PollQuestionCollection.GetByQuestionnaire(SessionState.Questionnaire.QuestionnaireID); if (SessionState.Questions.Count > 0) { PollQuestionGUID = SessionState.Questions[0].PollQuestionId; // Il faut prevenir le SqlDataSource que le parametre n'est pas dans la Query ... // <asp:QueryStringParameter Name="pollId" QueryStringField="PollId" /> //SqlDataSource1.SelectParameters.Add( "pollId", PollQuestionGUID.ToString() ); //SqlDataSource1.DataBind() // Cela ne fonctionne pas donc on fait : Response.Redirect("~/Poll/Answers.aspx?PollId=" + PollQuestionGUID.ToString()); } } } else { try { PollQuestionGUID = new Guid(Request["PollId"]); } catch { Response.Redirect("~/Poll/Manage.aspx", true); } } if (PollQuestionGUID == Guid.Empty) { Response.Redirect("~/Poll/Manage.aspx", true); } if (SessionState.Questionnaire != null) { HyperLinkQuestionnaire.Text = SessionState.Questionnaire.Description; } PollQuestion question = PollQuestion.GetQuestion(PollQuestionGUID); HyperLinkRank.Text = question.Rank.ToString(); HyperLinkRank.NavigateUrl = "~/Poll/Questionnaire.aspx?PollQuestionId=" + question.PollQuestionId.ToString() + "&t=1"; HyperLinkModifierQuestion.NavigateUrl = "~/Wizard/Question.aspx?PollQuestionId=" + question.PollQuestionId.ToString(); LabelQuestion.Text = " - " + question.Question; LabelObligatoire.Visible = question.Obligatoire; LabelChoixMultiple.Visible = question.ChoixMultiple; LabelChoixMultipleMinMax.Visible = question.ChoixMultiple && (question.ChoixMultipleMin > 0) && (question.ChoixMultipleMax > 0); LabelChoixMultipleMinMax.Text = "(" + question.ChoixMultipleMin + "/" + question.ChoixMultipleMax + ")"; LabelChoixSimple.Visible = (question.ChoixMultiple == false); LabelFin.Visible = question.Fin; LabelInstruction.Text = question.Instruction; LabelMessage.Text = question.Message; Reponses = PollAnswerCollection.GetByPollQuestionID(PollQuestionGUID); ReponseRankMax = Reponses.MaxRank(); if (Reponses.Count > 0) { Reponse0 = Reponses[0]; } if (Page.IsPostBack == false) { DropDownListTextAlign.DataSource = TextAlign(); DropDownListTextAlign.DataBind(); if (Reponses.Count > 0) { DropDownListTextAlign.SelectedValue = Reponses[0].AlignLeft == true ? ( string )TextAlign()[1] : ( string )TextAlign()[0]; } DropDownListVerticalHorizontal.DataSource = VerticalHorizontal(); DropDownListVerticalHorizontal.DataBind(); if (Reponses.Count > 0) { DropDownListVerticalHorizontal.SelectedValue = Reponses[0].Horizontal == true ? ( string )VerticalHorizontal()[1] : ( string )VerticalHorizontal()[0]; } } }