public static PollReaction Fill(DataRow r)
    {
        PollReaction o = new PollReaction();

        o.ReactionId   = (Guid)(r["ReactionId"]);
        o.UserId       = ( Guid )(r["UserId"]);
        o.CreationDate = DateTime.Parse(r["CreationDate"].ToString());
        o.Reaction     = r["Reaction"].ToString();
        o.PollId       = (Guid)(r["PollId"]);

        return(o);
    }
    public static int Update(PollReaction o)
    {
        SqlConnection myConnection = new SqlConnection(Tools.DatabaseConnectionString);

        SqlCommand myCommand = new SqlCommand("PollReactionUpdate", myConnection);

        myCommand.CommandType = CommandType.StoredProcedure;

        AddParameters(o, ref myCommand);

        myConnection.Open();
        int iStatusCode = Convert.ToInt32(myCommand.ExecuteScalar());

        myConnection.Close();

        return(iStatusCode);
    }
    protected void UpdateButton_Click(object sender, System.EventArgs e)
    {
        Guid   uGuid    = new Guid(Membership.GetUser().ProviderUserKey.ToString());
        string reaction = HttpUtility.HtmlEncode(ReactionTextBox.Text.Trim());

        ////hack to preserve at least some formatting in a post
        //reaction = Regex.Replace( reaction, "" + char( 13 ) + "" + Chr( 10 ) + "", "<br />", RegexOptions.IgnoreCase | RegexOptions.Multiline );
        //reaction = Regex.Replace( reaction, "&lt;br /&gt;", "<br />", RegexOptions.IgnoreCase | RegexOptions.Multiline );

        //suggest you get an html editor type input box instead
        //if you do, you'll need to sanitize the input here to check for malicious html and script junk
        PollReaction pr = new PollReaction();

        pr.Reaction = reaction;
        pr.PollId   = PollId;
        pr.UserId   = uGuid;
        PollReaction.Create(pr);
        Response.Redirect(string.Format("~/Poll/View.aspx?pollId={0}", PollId.ToString()), true);
    }
        public static List <PollReaction> GetQuestions()
        {
            DataSet ds = new DataSet();

            ds = SqlDataProvider.ExecuteDataset
                 (
                Tools.DatabaseConnectionString,
                CommandType.StoredProcedure,
                "GetPollReactionAll"
                 );

            List <PollReaction> oc = new List <PollReaction>();

            foreach (DataRow r in ds.Tables[0].Rows)
            {
                PollReaction o = PollReaction.Fill(r);
                oc.Add(o);
            }
            return(oc);
        }
    private static void AddParameters(PollReaction o, ref SqlCommand cmd)
    {
        SqlParameter param = new SqlParameter();

        param       = new SqlParameter("@ReactionId", SqlDbType.UniqueIdentifier);
        param.Value = o.ReactionId;
        cmd.Parameters.Add(param);

        param       = new SqlParameter("@UserId", SqlDbType.UniqueIdentifier);
        param.Value = o.UserId;
        cmd.Parameters.Add(param);

        param       = new SqlParameter("@CreationDate", SqlDbType.DateTime);
        param.Value = o.CreationDate;
        cmd.Parameters.Add(param);

        param       = new SqlParameter("@Reaction", SqlDbType.NVarChar);
        param.Value = o.Reaction;
        cmd.Parameters.Add(param);

        param       = new SqlParameter("@PollId", SqlDbType.UniqueIdentifier);
        param.Value = o.PollId;
        cmd.Parameters.Add(param);
    }
Пример #6
0
        private void CreateControls()
        {
            if (SessionState.Questions == null)
            {
                Label noPollAvailableLabel = new Label();
                noPollAvailableLabel.Text = "Il n'y a pas de question pour ce questionnaire !";
                this.Controls.Add(new LiteralControl("<i>"));
                this.Controls.Add(noPollAvailableLabel);
                this.Controls.Add(new LiteralControl("</i>"));
                return; // TODO: might not be correct. Was : Exit Sub
            }
            else
            {
            }

            //Hyperlink
            HyperLink hyp = new HyperLink();

            hyp.NavigateUrl = "~/Poll/List.aspx?QuestionnaireID=" + SessionState.Question.QuestionnaireID;
            hyp.Text        = "Liste des Questions";

            this.Controls.Add(hyp);
            this.Controls.Add(new LiteralControl("<br/>"));
            this.Controls.Add(new LiteralControl("<br/>"));

            //Question
            Label questionLabel = new Label();

            questionLabel.Text = SessionState.Question.Question;
            questionLabel.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
            this.Controls.Add(questionLabel);

            this.Controls.Add(new LiteralControl("<br/>"));

            //Me.Controls.Add(New LiteralControl("<ul>"))
            this.Controls.Add(new LiteralControl("<ul>"));

            //The Label answers
            foreach (PollAnswer row in SessionState.Reponses)
            {
                decimal percentage = ComputePercentage(PollVoteCollection.NumberOfVotesByAnswer(row.PollAnswerId));

                this.Controls.Add(new LiteralControl("<li>"));

                Label answerLabel = new Label();
                answerLabel.Text = string.Format("{0}   ", row.Answer);
                this.Controls.Add(answerLabel);

                //this.Controls.Add( new LiteralControl( "<br/>" ) );

                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());
                this.Controls.Add(img);

                Label percentageLabel = new Label();
                percentageLabel.Text = string.Format(" ({0}%)", percentage.ToString());
                this.Controls.Add(percentageLabel);

                this.Controls.Add(new LiteralControl("</li>"));

                this.Controls.Add(new LiteralControl("</ul>"));

                //The summary
                HyperLink summaryLink = new HyperLink();
                string    ttlvotes    = PollVoteCollection.CountTotalVotes(SessionState.Question.PollQuestionId).ToString();
                if (ttlvotes == "1")
                {
                    summaryLink.Text = string.Format("{0} vote", ttlvotes);
                }
                else
                {
                    summaryLink.Text = string.Format("{0} votes", ttlvotes);
                }

                summaryLink.NavigateUrl = "~/poll/View.aspx?PollId=" + SessionState.Question.PollQuestionId.ToString();
                this.Controls.Add(summaryLink);

                this.Controls.Add(new LiteralControl("<br/>"));

                HyperLink totalReactionsLink = new HyperLink();
                string    ttlrxns            = PollReaction.CountTotalReactions(SessionState.Question.PollQuestionId).ToString();
                if (ttlrxns == "1")
                {
                    totalReactionsLink.Text = string.Format("{0} réaction", ttlrxns);
                }
                else
                {
                    totalReactionsLink.Text = string.Format("{0} réactions", ttlrxns);
                }

                totalReactionsLink.NavigateUrl = "~/poll/View.aspx?PollId=" + SessionState.Question.PollQuestionId.ToString();
                this.Controls.Add(totalReactionsLink);
                this.Controls.Add(new LiteralControl("<p>&nbsp</p>"));
            }

            // Question suivante
            this.Controls.Add(new LiteralControl("<br/>"));
            RolloverButton rlb = new RolloverButton();

            rlb.Text   = "Suivante";
            rlb.Click += new EventHandler(QuestionSuivante_Click);
            this.Controls.Add(rlb);
        }