private void BuildDataList() { DataListQuestion.DataSource = SessionState.QuestionsEnCours; DataListQuestion.DataBind(); // Trouver les Reponses et les Votes foreach (DataListItem dli in DataListQuestion.Items) { DataList dl = new DataList(); dl = ( DataList )dli.FindControl("DataListReponse"); HiddenField hf = new HiddenField(); hf = ( HiddenField )dli.FindControl("PollQuestionId"); Guid pollQuestionId = new Guid(hf.Value); PollAnswerCollection answers = PollAnswerCollection.GetByPollQuestionID(pollQuestionId); dl.DataSource = answers; dl.DataBind(); // Rechercher dans les Votes deja effectues if (answers.Count > 0 && SessionState.Votes != null) { int indexReponse = 0; // Trouver le bon LabelVote dans DataListReponse foreach (PollAnswer answer in answers) { PollVoteCollection pvc = SessionState.Votes.FindByAnswerID(answer.PollAnswerId); if (pvc.Count >= 1) // surement un seul mais bon ... { Label lbl = ( Label )dl.Controls[indexReponse].FindControl("LabelVote"); lbl.Text = "X"; lbl.CssClass = "LabelQuestionEnCoursVoteDejaFaitStyle"; if (TypeReponse.EstTextuelle(answer.TypeReponse)) { Label lblVoteTexte = ( Label )dl.Controls[indexReponse].FindControl("LabelVoteTexte"); lblVoteTexte.Text = pvc[0].Vote; } } indexReponse += 1; } } // Rechercher dans les Votes en Cours if (answers.Count > 0 && SessionState.VotesEnCours != null) { int indexReponse = 0; // Trouver le bon LabelVote dans DataListReponse foreach (PollAnswer answer in answers) { PollVoteCollection pvc = SessionState.VotesEnCours.FindByAnswerID(answer.PollAnswerId); if (pvc.Count >= 1) // surement un seul mais ... { Label lbl = ( Label )dl.Controls[indexReponse].FindControl("LabelVote"); lbl.Text = "X"; if (TypeReponse.EstTextuelle(answer.TypeReponse)) { Label lblVoteTexte = ( Label )dl.Controls[indexReponse].FindControl("LabelVoteTexte"); lblVoteTexte.Text = pvc[0].Vote; } } indexReponse += 1; } } } }
protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) { Trace.Warn("GridView1_RowUpdating"); // Recuperer la Reponse cliquee Guid answerGuid = new Guid(GridView1.DataKeys[e.RowIndex].Value.ToString()); PollAnswer reponse = Reponses.FindByPollAnswerID(answerGuid); e.NewValues["TypeReponse"] = reponse.TypeReponse; // BUG20100407 // Faire comme dans ButtonReponseTextuelleOk_Click if (e.NewValues["Answer"] == null && TypeReponse.EstTextuelle(( string )e.NewValues["TypeReponse"])) { e.NewValues["Answer"] = " "; // reponse textuelle vide } // Si elle est encore nulle c'est qu'elle n'est pas textuelle alors on met une chaine "Réponse ?" if (e.NewValues["Answer"] == null) { e.NewValues["Answer"] = "Réponse ?"; } //if ( string.IsNullOrEmpty( e.NewValues[ "Answer" ].ToString() ) ) //{ // e.NewValues[ "Answer" ] = "Réponse ?"; //} if (TypeReponse.EstTextuelle((string)e.NewValues["TypeReponse"])) { if (e.NewValues["Width"] != null) { try { int i = int.Parse(e.NewValues["Width"].ToString()); if (i < int.Parse(Global.SettingsXml.ReponseTextuelleLargeurMin)) { e.NewValues["Width"] = Global.SettingsXml.ReponseTextuelleLargeurMin; } if (i > int.Parse(Global.SettingsXml.ReponseTextuelleLargeurMax)) { e.NewValues["Width"] = Global.SettingsXml.ReponseTextuelleLargeurMax; } } catch { ValidationMessage.Text += "Largeur est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.NewValues["Width"] = null; } } if (e.NewValues["Rows"] != null) { try { int i = int.Parse(e.NewValues["Rows"].ToString()); if (i > int.Parse(Global.SettingsXml.ReponseTextuelleLigneMax)) { e.NewValues["Rows"] = Global.SettingsXml.ReponseTextuelleLigneMax; } } catch { ValidationMessage.Text += "Lignes est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.NewValues["Rows"] = null; } } } else // Ce n'est pas une reponse textuelle { e.NewValues["Rows"] = null; e.NewValues["Width"] = null; e.NewValues["Obligatoire"] = null; } if (e.NewValues["Rank"] == null) { e.NewValues["Rank"] = 10; } else { try { int i = int.Parse(e.NewValues["Rank"].ToString()); } catch { ValidationMessage.Text += "Rang est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.NewValues["Rank"] = 10; } } if (e.NewValues["Score"] != null) { try { int i = int.Parse(e.NewValues["Score"].ToString()); if (i <= 0) { ValidationMessage.Text += "Score est un entier positif<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.NewValues["Score"] = null; } } catch { ValidationMessage.Text += "Score est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.NewValues["Score"] = null; } } }
private Table CreateReponseTable(Guid pollQuestionID) { PollAnswerCollection answers = SessionState.Reponses.FindByPollQuestionID(pollQuestionID); Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); TableCell cellPix = new TableCell(); cellPix.CssClass = "TableReponseCellPix"; row.Cells.Add(cellPix); cell.Text = "Réponse"; cell.CssClass = "TdHeaderReponseTableStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Vote"; cell.CssClass = "TdHeaderReponseTableStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "%"; cell.CssClass = "TdHeaderReponseTableStyle"; row.Cells.Add(cell); PollVoteCollection pvc = new PollVoteCollection(); TableCell cellDateVote = new TableCell(); if (SelectedPersonneGUID != Guid.Empty) { pvc = SessionState.Votes.FindByPersonneGUID(SelectedPersonneGUID); //cell = new TableCell(); //cell.Text = "A voté"; //cell.CssClass = "TdHeaderReponseTableStyle"; //row.Cells.Add( cell ); //if ( AfficherLaDateDesVotes ) //{ // cellDateVote.Text = "Date"; // cellDateVote.CssClass = "TdHeaderReponseTableStyle"; // row.Cells.Add( cellDateVote ); //} } table.Rows.Add(row); int totalVotant = 0; foreach (Personne p in PersonneVotants) { if (SessionState.Votes.FindIfPersonneHasVoted(pollQuestionID, p.PersonneGUID)) { totalVotant += 1; } } int totalVotes = 0; foreach (PollAnswer answer in answers) { int votes = SessionState.Votes.FindNumberOfVotesByAnswer(answer.PollAnswerId); totalVotes = SessionState.Votes.FindCountTotalVotes(answer.PollQuestionId); decimal percentage = ComputePercentage(votes, totalVotes); row = new TableRow(); cell = new TableCell(); cellPix = new TableCell(); cellPix.CssClass = "TableReponseCellPix"; row.Cells.Add(cellPix); HyperLink hyp = new HyperLink(); hyp.NavigateUrl = "~/Questionnaire/Publication.aspx?PollAnswerID=" + answer.PollAnswerId; hyp.Text = answer.Rank + " - " + answer.Answer; hyp.ToolTip = "Qui a répondu"; hyp.CssClass = "HyperLinkReponseStatAllStyle"; if (TypeReponse.EstTextuelle(answer.TypeReponse)) { hyp.CssClass = "HyperLinkReponseTextuelleStatAllStyle"; } cell.Controls.Add(hyp); if (TypeReponse.EstTextuelle(answer.TypeReponse) && SelectedPersonneGUID != Guid.Empty && AfficherReponseTextuelle) { Label lbl = new Label(); foreach (PollVote pv in pvc) { if (pv.UserGUID == SelectedPersonneGUID && answer.PollAnswerId == pv.PollAnswerId) { lbl.Text = " " + pv.Vote; break; } } cell.Controls.Add(lbl); } cell.CssClass = "CellLinkReponseStatAllStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = votes.ToString(); cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = percentage.ToString(); cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); //if ( SelectedPersonneGUID != Guid.Empty ) //{ // cell = new TableCell(); // if ( AfficherLaDateDesVotes ) // { // cellDateVote = new TableCell(); // } // // A t-il vote pour cette reponse ? // cell.Text = " "; // cellDateVote.Text = " "; // foreach ( PollVote pv in pvc ) // { // if ( pv.UserGUID == SelectedPersonneGUID && answer.PollAnswerId == pv.PollAnswerId ) // { // cell.Text = "X"; // if ( AfficherLaDateDesVotes ) // { // cellDateVote.Text = pv.CreationDate.ToString(); // } // break; // } // } // cell.CssClass = "TdVoteTableStyle"; // row.Cells.Add( cell ); // if ( AfficherLaDateDesVotes ) // { // cellDateVote.CssClass = "TdStatTableDateStyle"; // row.Cells.Add( cellDateVote ); // } //} cell = new TableCell(); System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image(); img.ImageUrl = "~/Images/pixel.png"; img.Height = new Unit(7); img.Width = new Unit(percentage.ToString()); cell.Controls.Add(img); row.Cells.Add(cell); table.Rows.Add(row); } row = new TableRow(); cell = new TableCell(); cell.Text = "Votants : " + totalVotant.ToString(); cell.CssClass = "TdTotalVoteTableStyle"; cell.ColumnSpan = 2; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Votes : " + totalVotes.ToString(); cell.CssClass = "TdTotalVoteTableStyle"; cell.ColumnSpan = 3; row.Cells.Add(cell); table.Rows.Add(row); return(table); }
protected void DetailsView1_ItemInserting(object sender, System.Web.UI.WebControls.DetailsViewInsertEventArgs e) { Trace.Warn("DetailsView1_ItemInserting"); if (e.Values["PollQuestionId"] == null) { e.Values["PollQuestionId"] = PollQuestionGUID; } if (e.Values["PollAnswerId"] == null) { e.Values["PollAnswerId"] = Guid.NewGuid(); } // Recuperer la valeur de DropDownListTypeReponse DropDownList ddlTypeReponse = ( DropDownList )DetailsView1.Rows[columnDropDownListTypeReponse].FindControl("DropDownListTypeReponse"); string valeur = ddlTypeReponse.SelectedItem.Text; e.Values["TypeReponse"] = valeur; if (TypeReponse.EstTextuelle((string)e.Values["TypeReponse"]) == false) { if (e.Values["Width"] != null) { e.Values["Width"] = null; ValidationMessage.Text += "La largeur ne concerne que les Réponses textuelles<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; } if (e.Values["Rows"] != null) { e.Values["Rows"] = null; ValidationMessage.Text += "Le nombre de lignes ne concerne que les Réponses textuelles<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; } if (( bool )e.Values["Obligatoire"] == true) { e.Values["Obligatoire"] = null; ValidationMessage.Text += "Obligatoire ici ne concerne que les Réponses textuelles<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; } } else { if (e.Values["Width"] != null) { try { int i = int.Parse(e.Values["Width"].ToString()); if (i < int.Parse(Global.SettingsXml.ReponseTextuelleLargeurMin)) { e.Values["Width"] = Global.SettingsXml.ReponseTextuelleLargeurMin; } if (i > int.Parse(Global.SettingsXml.ReponseTextuelleLargeurMax)) { e.Values["Width"] = Global.SettingsXml.ReponseTextuelleLargeurMax; } } catch { e.Values["Width"] = null; ValidationMessage.Text += "Largeur est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; } } if (e.Values["Rows"] != null) { try { int i = int.Parse(e.Values["Rows"].ToString()); if (i > int.Parse(Global.SettingsXml.ReponseTextuelleLigneMax)) { e.Values["Rows"] = Global.SettingsXml.ReponseTextuelleLigneMax; } } catch { e.Values["Rows"] = null; ValidationMessage.Text += "Lignes est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; } } } // BUG20100407 // Faire comme dans ButtonReponseTextuelleOk_Click if (e.Values["Answer"] == null && TypeReponse.EstTextuelle(( string )e.Values["TypeReponse"])) { e.Values["Answer"] = " "; // reponse textuelle vide } // Si elle est encore nulle c'est qu'elle n'est pas textuelle alors on met une chaine "Réponse ?" if (e.Values["Answer"] == null) { e.Values["Answer"] = "Réponse ?"; } //if ( string.IsNullOrEmpty( e.Values[ "Answer" ].ToString() ) ) //{ // e.Values[ "Answer" ] = "Réponse ?"; //} if (e.Values["Rank"] == null) { e.Values["Rank"] = ReponseRankMax + 1; } else { try { int i = int.Parse(e.Values["Rank"].ToString()); } catch { ValidationMessage.Text += "Rang est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.Values["Rank"] = ReponseRankMax + 1; } } if (e.Values["Score"] != null) { try { int i = int.Parse(e.Values["Score"].ToString()); if (i <= 0) { ValidationMessage.Text += "Score est un entier positif<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.Values["Rank"] = null; } } catch { ValidationMessage.Text += "Score est un entier<br/>"; ValidationMessage.Visible = true; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; e.Values["Rank"] = null; } } if (e.Values["Obligatoire"] != null) { if (( bool )e.Values["Obligatoire"] == false) { e.Values["Obligatoire"] = null; // effacer } } }
private Table CreateReponseTable(Guid pollQuestionID) { PollAnswerCollection answers = SessionState.Reponses.FindByPollQuestionID(pollQuestionID); Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); TableCell cellPix = new TableCell(); cellPix.CssClass = "TableReponseCellPix"; row.Cells.Add(cellPix); cell.Text = "Réponse"; cell.CssClass = "TdHeaderReponseTableLeftStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Vote"; cell.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "%"; cell.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cell); Label moyenne = new Label(); Style style = new Style(); if (AfficherLaMoyennePonderee) { cell = new TableCell(); cell.Text = "Poid"; cell.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cell); cell = new TableCell(); style.Font.Overline = true; moyenne.ApplyStyle(style); moyenne.Text = "x"; cell.Controls.Add(moyenne); cell.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cell); } PollVoteCollection pvc = new PollVoteCollection(); TableCell cellDateVote = new TableCell(); if (SelectedPersonneGUID != Guid.Empty) { pvc = SessionState.Votes.FindByPersonneGUID(SelectedPersonneGUID); cell = new TableCell(); cell.Text = "A voté"; cell.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cell); if (AfficherLaDateDesVotes) { cellDateVote.Text = "Date"; cellDateVote.CssClass = "TdHeaderReponseTableCenterStyle"; row.Cells.Add(cellDateVote); } } table.Rows.Add(row); int totalVotant = 0; foreach (Personne p in PersonneVotants) { if (SessionState.Votes.FindIfPersonneHasVoted(pollQuestionID, p.PersonneGUID)) { totalVotant += 1; } } double sommePoid = 0; foreach (PollAnswer answer in answers) { sommePoid += answer.Score; } sommePoid = sommePoid == 0 ? 1.0 : sommePoid; // ne pas laisser 0 int totalVotes = 0; double sommePoids = 0.0; foreach (PollAnswer answer in answers) { int votes = SessionState.Votes.FindNumberOfVotesByAnswer(answer.PollAnswerId); totalVotes = SessionState.Votes.FindCountTotalVotes(answer.PollQuestionId); decimal percentage = ComputePercentage(votes, totalVotes); // On ne Score que les Reponses choix double poid = 0.0; if (answer.TypeReponse == TypeReponse.Choix) { poid = votes * (answer.Score == 0 ? 1.0 : answer.Score) / sommePoid; sommePoids += poid; } row = new TableRow(); cell = new TableCell(); cellPix = new TableCell(); cellPix.CssClass = "TableReponseCellPix"; row.Cells.Add(cellPix); if (ModePrint) { Label lbl = new Label(); lbl.Text = answer.Rank + " - " + answer.Answer; if (TypeReponse.EstTextuelle(answer.TypeReponse)) { lbl.CssClass = "HyperLinkReponseTextuelleStatAllStyle"; } cell.Controls.Add(lbl); } else if (ModeExcel) { Label lbl = new Label(); lbl.Text = "r : " + answer.Rank + " - " + answer.Answer; // ajout d'un petit "r:" pour que ce con d'excel ne prenne pas ca pour une date !!! if (TypeReponse.EstTextuelle(answer.TypeReponse)) { lbl.CssClass = "HyperLinkReponseTextuelleStatAllStyle"; } cell.Controls.Add(lbl); } else { HyperLink hyp = new HyperLink(); hyp.NavigateUrl = "~/Poll/QuestionnaireStatAll.aspx?PollAnswerID=" + answer.PollAnswerId; hyp.Text = answer.Rank + " - " + answer.Answer; hyp.ToolTip = "Qui a répondu"; hyp.CssClass = "HyperLinkReponseStatAllStyle"; if (TypeReponse.EstTextuelle(answer.TypeReponse)) { hyp.CssClass = "HyperLinkReponseTextuelleStatAllStyle"; } cell.Controls.Add(hyp); } if (TypeReponse.EstTextuelle(answer.TypeReponse) && SelectedPersonneGUID != Guid.Empty && AfficherReponseTextuelle) { Label lbl = new Label(); foreach (PollVote pv in pvc) { if (pv.UserGUID == SelectedPersonneGUID && answer.PollAnswerId == pv.PollAnswerId) { lbl.Text = " " + pv.Vote; break; } } cell.Controls.Add(lbl); } cell.CssClass = "CellLinkReponseStatAllStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = votes.ToString(); cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = percentage.ToString(); cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); if (AfficherLaMoyennePonderee) { cell = new TableCell(); cell.Text = ""; if (answer.TypeReponse == TypeReponse.Choix) { cell.Text = answer.Score.ToString(); } cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = ""; if (answer.TypeReponse == TypeReponse.Choix) { cell.Text = poid.ToString("##0.###"); } cell.CssClass = "TdStatTableStyle"; row.Cells.Add(cell); } if (SelectedPersonneGUID != Guid.Empty) { cell = new TableCell(); if (AfficherLaDateDesVotes) { cellDateVote = new TableCell(); } // A t-il vote pour cette reponse ? cell.Text = " "; cellDateVote.Text = " "; foreach (PollVote pv in pvc) { if (pv.UserGUID == SelectedPersonneGUID && answer.PollAnswerId == pv.PollAnswerId) { cell.Text = "X"; if (AfficherLaDateDesVotes) { cellDateVote.Text = pv.CreationDate.ToString(); } break; } } cell.CssClass = "TdVoteTableStyle"; row.Cells.Add(cell); if (AfficherLaDateDesVotes) { cellDateVote.CssClass = "TdStatTableDateStyle"; row.Cells.Add(cellDateVote); } } if (ModeExcel == false) { cell = new TableCell(); System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image(); img.ImageUrl = "~/Images/pixel.png"; img.Height = new Unit(7); img.Width = new Unit(percentage.ToString()); cell.Controls.Add(img); row.Cells.Add(cell); } table.Rows.Add(row); } row = new TableRow(); cell = new TableCell(); cell.Text = "Votants : " + totalVotant.ToString(); cell.CssClass = "TdTotalVoteTableStyle"; cell.ColumnSpan = 2; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Votes : " + totalVotes.ToString(); cell.CssClass = "TdTotalVoteTableStyle"; cell.ColumnSpan = 3; row.Cells.Add(cell); if (AfficherLaMoyennePonderee) { moyenne = new Label(); moyenne.ApplyStyle(style); moyenne.Text = "x"; cell = new TableCell(); cell.Controls.Add(moyenne); moyenne = new Label(); moyenne.Text = " : " + sommePoids.ToString("##0.###"); cell.Controls.Add(moyenne); cell.CssClass = "TdTotalVoteTableStyle"; row.Cells.Add(cell); } table.Rows.Add(row); return(table); }