예제 #1
0
        protected String GetOptionResultText(Object oOptionGuid)
        {
            Guid optionGuid = new Guid(oOptionGuid.ToString());

            PollOption option = new PollOption(optionGuid);

            String orderNumber = String.Empty;
            if (option.Poll.ShowOrderNumbers)
            {
                orderNumber = option.Order.ToString() + ". ";
            }

            String votesText = (option.Votes == 1) ? PollResources.PollVoteText : PollResources.PollVotesText;

            // TODO: Some pattern based resource...
            String text = orderNumber + option.Answer + ", " + option.Votes + " " + votesText;

            if (option.Poll.TotalVotes != 0)
            {
                int percent = (int)((double)option.Votes * 100 / option.Poll.TotalVotes + 0.5);
                text += " (" + percent + " %)";
            }

            return text;
        }
예제 #2
0
파일: Poll.cs 프로젝트: zahedbri/mojoportal
        public bool CopyToNewPoll(out Poll newPoll)
        {
            newPoll = new Poll();
            newPoll.AllowViewingResultsBeforeVoting = allowViewingResultsBeforeVoting;
            newPoll.AnonymousVoting = anonymousVoting;
            newPoll.Question = question;
            newPoll.ShowOrderNumbers = showOrderNumbers;
            newPoll.ShowResultsWhenDeactivated = showResultsWhenDeactivated;
            newPoll.SiteGuid = siteGuid;

            bool result = newPoll.Save();

            if (result)
            {
                PollOption option;
                List<PollOption> pollOptions = PollOption.GetOptionsByPollGuid(pollGuid);
                foreach (PollOption optionToCopy in pollOptions)
                {
                    option = new PollOption();
                    option.Answer = optionToCopy.Answer;
                    option.Order = optionToCopy.Order;
                    option.PollGuid = newPoll.PollGuid;
                    option.Save();
                }
            }

            return result;
        }
예제 #3
0
        public static void AddResultBarToControl(PollOption option, string hexColor, Control ctrl)
        {
            Unit imgWidth = Unit.Percentage(option.VotePercentage == null || option.VotePercentage == 0 ?
                1 : option.VotePercentage.Value);

            Color color = UIHelper.HexStringToColor(hexColor);
            Label lbl = new Label();
            lbl.BackColor = color;
            lbl.Height = Unit.Pixel(10);
            lbl.Width = imgWidth;

            ctrl.Controls.Add(lbl);
        }
예제 #4
0
        private static List <PollOption> LoadListFromReader(IDataReader reader)
        {
            List <PollOption> pollOptionList = new List <PollOption>();

            try
            {
                while (reader.Read())
                {
                    PollOption pollOption = new PollOption();
                    pollOption.optionGuid = new Guid(reader["OptionGuid"].ToString());
                    pollOption.pollGuid   = new Guid(reader["PollGuid"].ToString());
                    pollOption.answer     = reader["Answer"].ToString();
                    pollOption.votes      = Convert.ToInt32(reader["Votes"]);
                    pollOption.order      = Convert.ToInt32(reader["Order"]);
                    pollOptionList.Add(pollOption);
                }
            }
            finally
            {
                reader.Close();
            }

            return(pollOptionList);
        }
예제 #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate("poll");
            if (Page.IsValid)
            {
                Poll poll = new Poll(pollGuid);
                poll.SiteGuid = siteSettings.SiteGuid;
                poll.Question = txtQuestion.Text;
                poll.AnonymousVoting = chkAnonymousVoting.Checked;
                poll.AllowViewingResultsBeforeVoting = chkAllowViewingResultsBeforeVoting.Checked;
                poll.ShowOrderNumbers = chkShowOrderNumbers.Checked;
                poll.ShowResultsWhenDeactivated = chkShowResultsWhenDeactivated.Checked;

                if (dpActiveFrom.Text.Length > 0 && poll.ActiveFrom >= DateTime.UtcNow)
                {
                    // You can't change date if poll has started.

                    // TODO: promt user if invalid format/date

                    DateTime activeFrom;
                    DateTime.TryParse(dpActiveFrom.Text, out activeFrom);

                    if (timeZone != null)
                    {
                        activeFrom = activeFrom.ToUtc(timeZone);
                    }
                    else
                    {
                        activeFrom = activeFrom.AddHours(-timeOffset);
                    }

                    poll.ActiveFrom = activeFrom;
                }

                if (dpActiveTo.Text.Length > 0)
                {
                    // TODO: promt user if invalid format/date
                    DateTime activeTo;
                    DateTime.TryParse(dpActiveTo.Text, out activeTo);

                    if (timeZone != null)
                    {
                        activeTo = activeTo.ToUtc(timeZone);
                    }
                    else
                    {
                        activeTo = activeTo.AddHours(-timeOffset);
                    }

                    // Make time 23:59:59
                    //activeTo = activeTo.AddHours(23).AddMinutes(59).AddSeconds(59);

                    // You can't change to past date.
                    if (activeTo >= DateTime.UtcNow)
                    {
                        poll.ActiveTo = activeTo;
                    }
                }

                if (chkStartDeactivated.Checked)
                {
                    // This only happens when new poll.
                    poll.Deactivate();
                }
                else
                {
                    poll.Activate();
                }

                poll.Save();

                // Get options
                PollOption option;
                int order = 1;
                foreach (ListItem item in lbOptions.Items)
                {
                    if (item.Text == item.Value)
                    {
                        option = new PollOption();
                    }
                    else
                    {
                        if (item.Value.Length == 36)
                        {
                            option = new PollOption(new Guid(item.Value));
                        }
                        else
                        {
                            option = new PollOption();
                        }
                    }

                    option.PollGuid = poll.PollGuid;
                    option.Answer = item.Text;
                    option.Order = order++;
                    option.Save();
                }

                WebUtils.SetupRedirect(this,
                    SiteRoot + "/Poll/PollChoose.aspx"
                    + "?pageid=" + pageId.ToInvariantString()
                    + "&mid=" + moduleId.ToInvariantString()
                    );

            }
        }
예제 #6
0
        private void btnDeleteOption_Click(Object sender, ImageClickEventArgs e)
        {
            if (lbOptions.SelectedItem == null) return;

            // TODO: What should happen if user deletes options so only 0 or 1 are left,
            // and then presses cancel or something? Better if nothing happens before
            // pressing Save but how to store deleted options for later?

            // If Text == Value option hasn't been saved yet, just remove it from list.
            if (lbOptions.SelectedItem.Text != lbOptions.SelectedItem.Value)
            {
                Guid optionGuid = new Guid(lbOptions.SelectedItem.Value);
                PollOption option = new PollOption(optionGuid);
                option.Delete();
            }

            lbOptions.Items.Remove(lbOptions.SelectedItem);
        }
예제 #7
0
        private static List<PollOption> LoadListFromReader(IDataReader reader)
        {
            List<PollOption> pollOptionList = new List<PollOption>();
            try
            {
                while (reader.Read())
                {
                    PollOption pollOption = new PollOption();
                    pollOption.optionGuid = new Guid(reader["OptionGuid"].ToString());
                    pollOption.pollGuid = new Guid(reader["PollGuid"].ToString());
                    pollOption.answer = reader["Answer"].ToString();
                    pollOption.votes = Convert.ToInt32(reader["Votes"]);
                    pollOption.order = Convert.ToInt32(reader["Order"]);
                    pollOptionList.Add(pollOption);

                }
            }
            finally
            {
                reader.Close();
            }

            return pollOptionList;
        }
예제 #8
0
        private void dlResults_ItemCreated(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header) return;
            if (e.Item.ItemType == ListItemType.Footer) return;

            Control spnResultImage = e.Item.FindControl("spnResultImage");
            Guid optionGuid = new Guid(dlResults.DataKeys[e.Item.ItemIndex].ToString());
            PollOption option = new PollOption(optionGuid);

            PollUIHelper.AddResultBarToControl(option, resultBarColor, spnResultImage);
        }
예제 #9
0
        void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header) return;
            if (e.Item.ItemType == ListItemType.Footer) return;

            Control spnResultImage = e.Item.FindControl("spnResultImage");
            HiddenField hdnID = (HiddenField)e.Item.FindControl("hdnID");
            PollOption option = new PollOption(new Guid(hdnID.Value));

            PollUIHelper.AddResultBarToControl(option, resultBarColor, spnResultImage);
        }
예제 #10
0
        private void rblOptions_SelectedIndexChanged(object sender, EventArgs e)
        {
            // this is where the actual voting happens

            if (String.IsNullOrEmpty(rblOptions.SelectedValue)) return;

            LoadPoll();
            userHasVoted = true;
            Guid selectedOptionGuid = new Guid(rblOptions.SelectedValue);
            PollOption selectedOption = new PollOption(selectedOptionGuid);

            Guid userGuid = Guid.Empty;

            if (currentUser != null)
            {
                userGuid = currentUser.UserGuid;
            }
            else
            {
                // Set a cookie and use it to keep anonymous polls from being too easy
                // to skew. Of course they can still do it
                if (poll.AnonymousVoting)
                {
                    CookieHelper.SetCookie(poll.PollGuid.ToString(), poll.PollGuid.ToString(), true);

                }

            }

            selectedOption.IncrementVotes(userGuid);

            ShowResult();
            pnlPollUpdate.Update();
        }
예제 #11
0
        public bool CopyToNewPoll(out Poll newPoll)
        {
            newPoll = new Poll();
            newPoll.AllowViewingResultsBeforeVoting = allowViewingResultsBeforeVoting;
            newPoll.AnonymousVoting = anonymousVoting;
            newPoll.Question = question;
            newPoll.ShowOrderNumbers = showOrderNumbers;
            newPoll.ShowResultsWhenDeactivated = showResultsWhenDeactivated;
            newPoll.SiteGuid = siteGuid;

            bool result = newPoll.Save();

            if (result)
            {
                PollOption option;
                List<PollOption> pollOptions = PollOption.GetOptionsByPollGuid(pollGuid);
                foreach (PollOption optionToCopy in pollOptions)
                {
                    option = new PollOption();
                    option.Answer = optionToCopy.Answer;
                    option.Order = optionToCopy.Order;
                    option.PollGuid = newPoll.PollGuid;
                    option.Save();
                }
            }

            return result;
        }