protected void LbtAnswer_Click(object sender, EventArgs e)
        {
            List <int> answers = new List <int>();

            foreach (string key in Request.Form.AllKeys)
            {
                if (!string.IsNullOrEmpty(key))
                {
                    if (key.IndexOf("RblAnswer") > 1)
                    {
                        answers.Add(Convert.ToInt32(Request.Form[key]));
                    }
                    else if (key.IndexOf("CblAnswer") > 1)
                    {
                        int last = key.LastIndexOf("$");
                        answers.Add(Convert.ToInt32(key.Substring(last + 1)));
                    }
                }
            }
            if (answers.Count > 0)
            {
                pollQuestion = DataObjectPollQuestion.Load <DataObjectPollQuestion>(pollQuestion.ObjectID, null, true);

                RenderPoll(DataObjectPollQuestion.AddPollAnswer(UserDataContext.GetUserDataContext(), pollQuestion, answers));
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            pollQuestion = DataObject.Load<DataObjectPollQuestion>(ObjectID, null, true);

            if (pollQuestion.State == ObjectState.Added)
            {
                pollQuestion.ObjectID = ObjectID;
                pollQuestion.Title = GuiLanguage.GetGuiLanguage("Shared").GetString("LabelUnnamed");
                pollQuestion.Description = language.GetString("LabelQuestion");
                pollQuestion.CommunityID = CommunityID;
                pollQuestion.ShowState = ObjectShowState.Draft;
                pollQuestion.StartDate = DateTime.Now.GetStartOfDay();
                pollQuestion.EndDate = pollQuestion.StartDate.AddMonths(1).GetEndOfDay();
                pollQuestion.Insert(UserDataContext.GetUserDataContext());
                pollQuestion.Title = string.Empty;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["TG"]))
                pollQuestion.TagList = Server.UrlDecode(Request.QueryString["TG"]);
            if (!string.IsNullOrEmpty(Request.QueryString["OS"]))
                pollQuestion.Status = (ObjectStatus)int.Parse(Request.QueryString["OS"]);
            if (!string.IsNullOrEmpty(Request.QueryString["SS"]))
                pollQuestion.ShowState = (ObjectShowState)int.Parse(Request.QueryString["SS"]);
            if (!string.IsNullOrEmpty(Request.QueryString["CR"]))
                pollQuestion.Copyright = int.Parse(Request.QueryString["CR"]);
            if (!string.IsNullOrEmpty(Request.QueryString["GC"]))
            {
                string[] geoLatLong = Request.QueryString["GC"].Split(',');
                double geoLat, geoLong = double.MinValue;
                if (geoLatLong.Length == 2)
                {
                    if (double.TryParse(geoLatLong[0], out geoLat) && double.TryParse(geoLatLong[1], out geoLong))
                    {
                        pollQuestion.Geo_Lat = geoLat;
                        pollQuestion.Geo_Long = geoLong;
                    }
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["ZP"]))
                pollQuestion.Zip = Server.UrlDecode(Request.QueryString["ZP"]);
            if (!string.IsNullOrEmpty(Request.QueryString["CI"]))
                pollQuestion.City = Server.UrlDecode(Request.QueryString["CI"]);
            if (!string.IsNullOrEmpty(Request.QueryString["RE"]))
                pollQuestion.Street = Server.UrlDecode(Request.QueryString["RE"]);
            if (!string.IsNullOrEmpty(Request.QueryString["CO"]))
                pollQuestion.CountryCode = Server.UrlDecode(Request.QueryString["CO"]);

            if (!IsPostBack)
                FillAnswers();

            FillEditForm();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            pollQuestion = (DataObjectPollQuestion)dataObject;
            udc          = UserDataContext.GetUserDataContext();

            // Disable tooltip managers by default -> tooltip managers without targets don't work
            this.RTTM.Visible    = false;
            this.RTTMIMG.Visible = false;
            if (pollQuestion != null)
            {
                foreach (string tooltipId in _4screen.CSB.DataAccess.Business.AdWordHelper.GetCampaignObjectIds(pollQuestion.ObjectID.Value))
                {
                    this.RTTM.TargetControls.Add(tooltipId, true);
                    this.RTTM.Visible = true;
                }
            }

            this.DESCLIT.Text = pollQuestion.DescriptionLinked;
            this.LitVon.Text  = pollQuestion.StartDate.ToShortDateString();
            this.LitBis.Text  = pollQuestion.EndDate.ToShortDateString();

            RenderPoll(null);
        }
        private void RenderPoll(DataObjectPollQuestion.AnswerResult?result)
        {
            pollQuestion = DataObjectPollQuestion.Load <DataObjectPollQuestion>(pollQuestion.ObjectID, null, true);

            bool showChart  = false;
            bool showAnswer = false;
            bool hasVoted   = pollQuestion.HasVoted;
            bool showButton = false;

            if (pollQuestion.EndDate >= DateTime.Now.GetEndOfDay() && pollQuestion.StartDate <= DateTime.Now.GetStartOfDay())
            {
                if (udc.IsAuthenticated || pollQuestion.AnonymousAllowed)
                {
                    if (!hasVoted)
                    {
                        showButton = true;
                    }
                }
            }

            if (pollQuestion.EndDate >= DateTime.Now.GetStartOfDay())
            {
                if (udc.IsAuthenticated || pollQuestion.AnonymousAllowed)
                {
                    if (!hasVoted)
                    {
                        showAnswer = true;
                    }
                }
            }
            if (!showAnswer)
            {
                showButton = false;
            }

            if (pollQuestion.StartDate <= DateTime.Now.GetStartOfDay())
            {
                if (pollQuestion.AnswerTotal > 0 && pollQuestion.ShowResult != DataObjectPollQuestion.QuestionShowResult.ShowChartNever)
                {
                    if (pollQuestion.ShowResult == DataObjectPollQuestion.QuestionShowResult.ShowChartAlways)
                    {
                        showChart = true;
                    }
                    else if (hasVoted)
                    {
                        showChart = true;
                    }
                    else if (!udc.IsAuthenticated && !pollQuestion.AnonymousAllowed)
                    {
                        showChart = true;
                    }
                }
            }
            if (pollQuestion.EndDate < DateTime.Now)
            {
                showChart = true;
            }

            LitResult.Visible = false;
            if (result.HasValue)
            {
                if (pollQuestion.CountRightAnswer() > 0)
                {
                    if (result == DataObjectPollQuestion.AnswerResult.Right && pollQuestion.TextRight.Length > 0)
                    {
                        this.LitResult.Text = pollQuestion.TextRight;
                    }
                    else if (result == DataObjectPollQuestion.AnswerResult.Partially && pollQuestion.TextPartially.Length > 0)
                    {
                        LitResult.Text = pollQuestion.TextPartially;
                    }
                    else if (result == DataObjectPollQuestion.AnswerResult.False && pollQuestion.TextFalse.Length > 0)
                    {
                        LitResult.Text = pollQuestion.TextFalse;
                    }
                    else
                    {
                        LitResult.Text = language.GetString("MessagePollThank");
                    }
                }
                else
                {
                    LitResult.Text = language.GetString("MessagePollThank");
                }
                LitResult.Visible = true;
            }

            PnlAnser.Visible  = showAnswer;
            LbtAnswer.Visible = showButton;

            if (showAnswer)
            {
                if (pollQuestion.PollType == DataObjectPollQuestion.QuestionPollType.SingleAnswer && this.RblAnswer.Items.Count == 0)
                {
                    foreach (DataObjectPollQuestion.PollAnswer item in pollQuestion.Answers)
                    {
                        this.RblAnswer.Items.Add(new ListItem(item.Answer, item.Position.ToString()));
                    }
                }
                else if (pollQuestion.PollType == DataObjectPollQuestion.QuestionPollType.MultiAnswer && this.CblAnswer.Items.Count == 0)
                {
                    foreach (DataObjectPollQuestion.PollAnswer item in pollQuestion.Answers)
                    {
                        this.CblAnswer.Items.Add(new ListItem(item.Answer, item.Position.ToString()));
                    }
                }

                RblAnswer.Visible = (RblAnswer.Items.Count > 1);
                CblAnswer.Visible = (CblAnswer.Items.Count > 1);
            }

            PnlResult.Visible = showChart;
            if (showChart)
            {
                Chart.PlotArea.Appearance.FillStyle.FillType        = FillType.Solid;
                Chart.PlotArea.Appearance.FillStyle.MainColor       = Color.FromArgb(0, 0, 0, 0);
                Chart.PlotArea.Appearance.Border.Width              = 0f;
                Chart.PlotArea.Appearance.Dimensions.Margins.Bottom = 0;
                Chart.PlotArea.Appearance.Dimensions.Margins.Left   = 0;
                Chart.PlotArea.Appearance.Dimensions.Margins.Right  = 0;
                Chart.PlotArea.Appearance.Dimensions.Margins.Top    = 0;
                Chart.PlotArea.XAxis.Visible = ChartAxisVisibility.False;
                Chart.PlotArea.YAxis.Visible = ChartAxisVisibility.False;

                int width = 0;
                if (Settings.ContainsKey("Width") && Settings["Width"] != null)
                {
                    int.TryParse(Settings["Width"].ToString(), out width);
                }
                if (width > 0)
                {
                    this.Chart.Width = new System.Web.UI.WebControls.Unit(width);
                }
                if (pollQuestion.PollLayout == DataObjectPollQuestion.QuestionPollLayout.Bar)
                {
                    if (width > 0)
                    {
                        this.Chart.Height = new System.Web.UI.WebControls.Unit(Convert.ToInt32(30 * pollQuestion.Answers.Count));
                    }
                    RenderChartBar();
                }
                else if (pollQuestion.PollLayout == DataObjectPollQuestion.QuestionPollLayout.Pie)
                {
                    if (width > 0)
                    {
                        this.Chart.Height = new System.Web.UI.WebControls.Unit(Convert.ToInt32(width * 0.9));
                    }
                    RenderChartPie();
                }
            }
        }