Пример #1
0
    /// <summary>
    /// Gets and updates answer. Called when the "Get and update answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndUpdateAnswer()
    {
        // Get the answer
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo updateAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Update the properties
                updateAnswer.AnswerText = updateAnswer.AnswerText.ToLower();

                // Save the changes
                PollAnswerInfoProvider.SetPollAnswerInfo(updateAnswer);

                return(true);
            }
        }

        return(false);
    }
Пример #2
0
    /// <summary>
    /// Gets and bulk updates answers. Called when the "Get and bulk update answers" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateAnswers()
    {
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the data
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID);
            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                // Loop through the individual items
                foreach (DataRow answerDr in answers.Tables[0].Rows)
                {
                    // Create object from DataRow
                    PollAnswerInfo modifyAnswer = new PollAnswerInfo(answerDr);

                    // Update the properties
                    modifyAnswer.AnswerText = modifyAnswer.AnswerText.ToUpper();

                    // Save the changes
                    PollAnswerInfoProvider.SetPollAnswerInfo(modifyAnswer);
                }

                return(true);
            }
        }

        return(false);
    }
Пример #3
0
    /// <summary>
    /// Loads new data for this control.
    /// </summary>
    public void LoadData()
    {
        // If working with existing record
        if (ItemID > 0)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
            EditedObject  = pollAnswerObj;

            if (pollAnswerObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    ReloadData();
                }

                // When saved, display info message
                if (Saved)
                {
                    ShowChangesSaved();
                    Saved = false;
                }

                PollId = pollAnswerObj.AnswerPollID;
            }
        }
        // If creating new record
        else
        {
            plcVotes.Visible = false;
            txtVotes.Text    = "0";
        }
    }
Пример #4
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Load current answer object
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
        }
        // Check permission for answer object (global/site poll)
        if (!CheckModifyPermission(this.PollId))
        {
            return;
        }

        string errorMessage = null;

        // Validate the input
        if (txtVotes.Visible)
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage)
                           .IsPositiveNumber(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber"), true)
                           .IsInteger(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber")).Result;
        }
        else
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage).Result;
        }

        if (String.IsNullOrEmpty(errorMessage))
        {
            // If pollAnswer doesn't already exist, create new one
            if (pollAnswerObj == null)
            {
                pollAnswerObj              = new PollAnswerInfo();
                pollAnswerObj.AnswerOrder  = PollAnswerInfoProvider.GetLastAnswerOrder(this.PollId) + 1;
                pollAnswerObj.AnswerCount  = 0;
                pollAnswerObj.AnswerPollID = this.PollId;
            }

            // Set the fields
            pollAnswerObj.AnswerEnabled = chkAnswerEnabled.Checked;
            pollAnswerObj.AnswerText    = txtAnswerText.Text.Trim();
            pollAnswerObj.AnswerCount   = ValidationHelper.GetInteger(this.txtVotes.Text, 0);

            // Save the data
            PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);
            this.Saved  = true;
            this.ItemID = pollAnswerObj.AnswerID;

            // Raise event;
            RaiseOnSaved();
        }
        else
        {
            // Error message - Validation
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        int pollId = QueryHelper.GetInteger("pollid", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        int answerId = QueryHelper.GetInteger("answerId", 0);

        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID = answerId;
        AnswerEdit.PollId = pollId;

        if (answerId > 0)
        {
            // Modifying existing answer
            this.CurrentMaster.Title.HelpTopicName = "answer_edit";
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;
            if (pollAnswerObj != null)
            {
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }
        else
        {
            // Creating new answer - check if parent object exists
            EditedObject = PollInfoProvider.GetPollInfo(pollId);
            this.CurrentMaster.Title.HelpTopicName = "new_answer";
        }

        // Initializes page title control
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("Polls_Answer_Edit.ItemListLink");
        breadcrumbs[0, 1]     = "~/CMSModules/Polls/Tools/Polls_Answer_List.aspx?pollId=" + pollId;
        breadcrumbs[0, 2]     = "";
        breadcrumbs[1, 0]     = currentPollAnswer;
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";
        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        // New item link
        string[,] actions = new string[1, 6];
        actions[0, 0]     = HeaderActions.TYPE_HYPERLINK;
        actions[0, 1]     = GetString("Polls_Answer_List.NewItemCaption");
        actions[0, 2]     = null;
        actions[0, 3]     = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId.ToString());
        actions[0, 4]     = null;
        actions[0, 5]     = GetImageUrl("CMSModules/CMS_Polls/addanswer.png");
        this.CurrentMaster.HeaderActions.Actions = actions;

        AnswerEdit.OnSaved   += new EventHandler(AnswerEdit_OnSaved);
        AnswerEdit.IsLiveSite = false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        int pollId = QueryHelper.GetInteger("pollid", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        int answerId = QueryHelper.GetInteger("answerId", 0);

        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID = answerId;
        AnswerEdit.PollId = pollId;

        if (answerId > 0)
        {
            // Modifying existing answer
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;

            if (pollAnswerObj != null)
            {
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }
        else
        {
            // Creating new answer - check if parent object exists
            EditedObject = PollInfoProvider.GetPollInfo(pollId);
        }

        var poll = EditedObject as PollInfo ?? PollInfoProvider.GetPollInfo(pollId);

        CheckPollsReadPermission(poll.PollSiteID);

        // Create breadcrumbs
        CreateBreadCrumbs(pollId, currentPollAnswer);

        HeaderAction add = new HeaderAction
        {
            Text        = GetString("Polls_Answer_List.NewItemCaption"),
            RedirectUrl = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId),
        };

        CurrentMaster.HeaderActions.AddAction(add);

        AnswerEdit.OnSaved   += AnswerEdit_OnSaved;
        AnswerEdit.IsLiveSite = false;
    }
    /// <summary>
    /// Initializes breadcrumbs items.
    /// </summary>
    private void InitializeBreadcrumbs()
    {
        ucBreadcrumbs.Items.Clear();

        ucBreadcrumbs.AddBreadcrumb(new BreadcrumbItem {
            Text          = GetString("Polls_Answer_Edit.ItemListLink"),
            OnClientClick = ControlsHelper.GetPostBackEventReference(lnkBackHidden) + "; return false;"
        });

        PollAnswerInfo pollAnswerObj = (AnswerEdit.ItemID > 0) ? PollAnswerInfoProvider.GetPollAnswerInfo(AnswerEdit.ItemID) : null;

        ucBreadcrumbs.AddBreadcrumb(new BreadcrumbItem {
            Text = (pollAnswerObj == null) ? GetString("Polls_Answer_Edit.NewItemCaption") : GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString(),
        });
    }
Пример #8
0
    /// <summary>
    /// Loads new data for this control.
    /// </summary>
    public void LoadData()
    {
        // If working with existing record
        if (this.ItemID > 0)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
            EditedObject = pollAnswerObj;

            if (pollAnswerObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    this.ReloadData();
                }

                // When saved, display info message
                if (this.Saved)
                {
                    lblInfo.Visible = true;
                    lblInfo.Text = GetString("General.ChangesSaved");
                    this.Saved = false;
                }
                // Otherwise hide info message
                else
                {
                    lblInfo.Visible = false;
                }

                this.PollId = pollAnswerObj.AnswerPollID;
            }
        }
        // If creating new record
        else
        {
            plcVotes.Visible = false;
            txtVotes.Text = "0";
        }
    }
Пример #9
0
    /// <summary>
    /// Loads new data for this control.
    /// </summary>
    public void LoadData()
    {
        // If working with existing record
        if (this.ItemID > 0)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
            EditedObject  = pollAnswerObj;

            if (pollAnswerObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    this.ReloadData();
                }

                // When saved, display info message
                if (this.Saved)
                {
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("General.ChangesSaved");
                    this.Saved      = false;
                }
                // Otherwise hide info message
                else
                {
                    lblInfo.Visible = false;
                }

                this.PollId = pollAnswerObj.AnswerPollID;
            }
        }
        // If creating new record
        else
        {
            plcVotes.Visible = false;
            txtVotes.Text    = "0";
        }
    }
Пример #10
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        this.ClearForm();
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
        }

        if (pollAnswerObj != null)
        {
            // Load the fields
            txtAnswerText.Text       = pollAnswerObj.AnswerText;
            chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
            txtVotes.Text            = pollAnswerObj.AnswerCount.ToString();
            plcVotes.Visible         = true;
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible   = false;
        }
    }
Пример #11
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        // Force reloading of PollAnswer info object if ID changed. The getter does the actual load.
        if ((PollAnswer != null) && (ItemID != PollAnswer.AnswerPollID))
        {
            PollAnswer   = null;
            EditedObject = PollAnswer;
        }

        if ((PollAnswer != null) && (PollAnswer.AnswerPollID > 0))
        {
            // Load the fields
            txtAnswerText.Text        = PollAnswer.AnswerText;
            chkAnswerEnabled.Checked  = PollAnswer.AnswerEnabled;
            txtVotes.Text             = PollAnswer.AnswerCount.ToString();
            plcVotes.Visible          = true;
            pnlGeneralHeading.Visible = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntryManager.IsModuleLoaded(ModuleName.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleName.BIZFORM, SiteContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(PollAnswer.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked  = updPanelForm.Visible = plcOpenAnswerSettings.Visible = PollAnswer.AnswerIsOpenEnded;
                bizFormElem.Value             = PollAnswer.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value     = PollAnswer.AnswerAlternativeForm;
                chkAnswerHideForm.Checked     = PollAnswer.AnswerHideForm;
            }
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible   = false;
        }
    }
Пример #12
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
        }

        if (pollAnswerObj != null)
        {
            // Load the fields
            txtAnswerText.Text       = pollAnswerObj.AnswerText;
            chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
            txtVotes.Text            = pollAnswerObj.AnswerCount.ToString();
            pnlGeneral.GroupingText  = GetString("general.general");
            plcVotes.Visible         = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleEntry.BIZFORM, CMSContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked  = plcOpenAnswerSettings.Visible = pollAnswerObj.AnswerIsOpenEnded;
                bizFormElem.Value             = pollAnswerObj.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value     = pollAnswerObj.AnswerAlternativeForm;
                chkAnswerHideForm.Checked     = pollAnswerObj.AnswerHideForm;
                pnlAnswerForm.GroupingText    = GetString("polls.answerformsettings");
            }
        }
        else
        {
            txtAnswerText.Text      = String.Empty;
            plcVotes.Visible        = false;
            pnlGeneral.GroupingText = string.Empty;
        }
    }
Пример #13
0
    /// <summary>
    /// Deletes answer. Called when the "Delete answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool DeleteAnswer()
    {
        // Get the poll
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the answer
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo deleteAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Delete the answer
                PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);

                return(deleteAnswer != null);
            }
        }

        return(false);
    }
Пример #14
0
    /// <summary>
    /// Creates answer. Called when the "Create answer" button is pressed.
    /// </summary>
    private bool CreateAnswer()
    {
        // Get the poll
        PollInfo poll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (poll != null)
        {
            // Create new answer object
            PollAnswerInfo newAnswer = new PollAnswerInfo();

            // Set the properties
            newAnswer.AnswerPollID  = poll.PollID;
            newAnswer.AnswerText    = "My new answer";
            newAnswer.AnswerEnabled = true;
            newAnswer.AnswerCount   = 0;

            // Save the answer
            PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);

            return(true);
        }

        return(false);
    }
Пример #15
0
    /// <summary>
    /// On btnVote click event handler.
    /// </summary>
    protected void btnVote_OnClick(object sender, EventArgs e)
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblInfo.CssClass = "ErrorMessage";
            lblInfo.Text = GetString("General.BannedIP");
            return;
        }

        if (pi != null)
        {
            // Indicates whether user voted or not
            bool voted = false;

            // Check if user has already voted
            if ((this.CheckVoted) && (PollInfoProvider.HasVoted(pi.PollID)))
            {
                errMessage = GetString("Polls.UserHasVoted");
                voted = true;
            }
            else if (isOpened)
            {
                // Get poll answers
                DataSet ds = Answers;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    LocalizedCheckBox chkItem = null;
                    LocalizedRadioButton radItem = null;
                    bool selected = false;
                    PollAnswerInfo pai = null;

                    // List of poll answers (in case of multiple answers) for activity logging
                    StringBuilder pollAnswerIDs = new StringBuilder();

                    foreach (DataRow row in rows)
                    {
                        pai = new PollAnswerInfo(row);

                        if ((pai != null) && (pai.AnswerEnabled))
                        {
                            selected = false;

                            // Find specific controls and update pollanswerinfo if controls are checked
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Find checkbox
                                chkItem = (LocalizedCheckBox)this.pnlAnswer.FindControl("chk" + pai.AnswerID);

                                if (chkItem != null)
                                {
                                    selected = chkItem.Checked;
                                }
                            }
                            else
                            {
                                // Find radiobutton
                                radItem = (LocalizedRadioButton)this.pnlAnswer.FindControl("rad" + pai.AnswerID);

                                if (radItem != null)
                                {
                                    selected = radItem.Checked;
                                }
                            }

                            if ((selected) && (pai.AnswerCount < Int32.MaxValue))
                            {
                                // Set the vote
                                PollAnswerInfoProvider.Vote(pai.AnswerID);
                                voted = true;

                                // Save all selected answers (for activity logging)
                                pollAnswerIDs.Append(pai.AnswerID);
                                pollAnswerIDs.Append(ActivityLogProvider.POLL_ANSWER_SEPARATOR);
                            }
                        }
                    }

                    if (voted)
                    {
                        LogActivity(pi, pollAnswerIDs.ToString());
                    }

                    if ((this.CheckVoted) && (voted))
                    {
                        // Create cookie about user's voting
                        PollInfoProvider.SetVoted(pi.PollID);
                    }
                }
            }

            if (voted)
            {
                // Clear cache if it's used
                Answers = null;
                // Reload poll control
                ReloadData(true);

                if (OnAfterVoted != null)
                {
                    OnAfterVoted(this, EventArgs.Empty);
                }
            }
            else
            {
                lblInfo.CssClass = "ErrorMessage";
                lblInfo.Text = GetString("Polls.DidNotVoted");
            }
        }
    }
Пример #16
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Load current answer object
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
        }
        // Check permission for answer object (global/site poll)
        if (!CheckModifyPermission(PollId))
        {
            return;
        }

        string errorMessage = null;

        // Validate the input
        if (txtVotes.Visible)
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage)
                           .IsPositiveNumber(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber"), true)
                           .IsInteger(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber")).Result;
        }
        else
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage).Result;
        }

        if (String.IsNullOrEmpty(errorMessage))
        {
            // If pollAnswer doesn't already exist, create new one
            if (pollAnswerObj == null)
            {
                pollAnswerObj              = new PollAnswerInfo();
                pollAnswerObj.AnswerOrder  = PollAnswerInfoProvider.GetLastAnswerOrder(PollId) + 1;
                pollAnswerObj.AnswerCount  = 0;
                pollAnswerObj.AnswerPollID = PollId;
            }

            // Set the fields
            pollAnswerObj.AnswerEnabled = chkAnswerEnabled.Checked;
            pollAnswerObj.AnswerText    = txtAnswerText.Text.Trim();
            pollAnswerObj.AnswerCount   = ValidationHelper.GetInteger(txtVotes.Text, 0);

            if (plcOpenAnswer.Visible)
            {
                string answerForm = ValidationHelper.GetString(bizFormElem.Value, string.Empty);
                if (chkAnswerIsOpenEnded.Checked && string.IsNullOrEmpty(answerForm))
                {
                    ShowError(GetString("Polls_Answer_Edit.SelectForm"));
                    return;
                }
                pollAnswerObj.AnswerForm            = answerForm;
                pollAnswerObj.AnswerAlternativeForm = ValidationHelper.GetString(alternativeFormElem.Value, string.Empty);
                pollAnswerObj.AnswerHideForm        = chkAnswerHideForm.Checked;
            }

            // Save the data
            PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);
            Saved  = true;
            ItemID = pollAnswerObj.AnswerID;

            // Raise event;
            RaiseOnSaved();
        }
        else
        {
            // Error message - Validation
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        // Force reloading of PollAnswer info object if ID changed. The getter does the actual load.
        if ((PollAnswer != null) && (ItemID != PollAnswer.AnswerPollID))
        {
            PollAnswer = null;
            EditedObject = PollAnswer;
        }

        if ((PollAnswer != null) && (PollAnswer.AnswerPollID > 0))
        {
            // Load the fields
            txtAnswerText.Text = PollAnswer.AnswerText;
            chkAnswerEnabled.Checked = PollAnswer.AnswerEnabled;
            txtVotes.Text = PollAnswer.AnswerCount.ToString();
            plcVotes.Visible = true;
            pnlGeneralHeading.Visible = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntryManager.IsModuleLoaded(ModuleName.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleName.BIZFORM, SiteContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(PollAnswer.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked = updPanelForm.Visible = plcOpenAnswerSettings.Visible = PollAnswer.AnswerIsOpenEnded;
                bizFormElem.Value = PollAnswer.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value = PollAnswer.AnswerAlternativeForm;
                chkAnswerHideForm.Checked = PollAnswer.AnswerHideForm;
            }
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible = false;
        }
    }
Пример #18
0
    /// <summary>
    /// Creates answer. Called when the "Create answer" button is pressed.
    /// </summary>
    private bool CreateAnswer()
    {
        // Get the poll
        PollInfo poll = PollInfoProvider.GetPollInfo("MyNewPoll", CMSContext.CurrentSiteID);

        if (poll != null)
        {
            // Create new answer object
            PollAnswerInfo newAnswer = new PollAnswerInfo();

            // Set the properties
            newAnswer.AnswerPollID = poll.PollID;
            newAnswer.AnswerText = "My new answer";
            newAnswer.AnswerEnabled = true;
            newAnswer.AnswerCount = 0;

            // Save the answer
            PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);

            return true;
        }

        return false;
    }
Пример #19
0
    /// <summary>
    /// Gets and bulk updates answers. Called when the "Get and bulk update answers" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateAnswers()
    {
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", CMSContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the data
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID);
            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                // Loop through the individual items
                foreach (DataRow answerDr in answers.Tables[0].Rows)
                {
                    // Create object from DataRow
                    PollAnswerInfo modifyAnswer = new PollAnswerInfo(answerDr);

                    // Update the properties
                    modifyAnswer.AnswerText = modifyAnswer.AnswerText.ToUpper();

                    // Save the changes
                    PollAnswerInfoProvider.SetPollAnswerInfo(modifyAnswer);
                }

                return true;
            }
        }

        return false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        pollId   = QueryHelper.GetInteger("pollId", 0);
        answerId = QueryHelper.GetInteger("answerId", 0);
        groupId  = QueryHelper.GetInteger("groupId", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        // Initialize AnswerEdit control
        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID              = answerId;
        AnswerEdit.PollId              = pollId;
        AnswerEdit.OnSaved            += AnswerEdit_OnSaved;
        AnswerEdit.OnCheckPermissions += AnswerEdit_OnCheckPermissions;

        if (answerId > 0)
        {
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;
            if (pollAnswerObj != null)
            {
                // Check that poll belongs to the specified group
                if ((pollAnswerObj.AnswerPollID > 0) && (groupId > 0))
                {
                    PollInfo poll = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);

                    // Answer not found or doesn't belong to specified group
                    if ((poll == null) || (poll.PollGroupID != groupId))
                    {
                        RedirectToAccessDenied(GetString("community.group.pollnotassigned"));
                    }
                }

                // Set control
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }

        // Validate
        EditedObject = PollInfoProvider.GetPollInfo(pollId);

        // Initialize breadcrumbs
        PageBreadcrumbs.Items.Add(new BreadcrumbItem
        {
            Text        = GetString("Polls_Answer_Edit.ItemListLink"),
            RedirectUrl = ResolveUrl("~/CMSModules/Groups/Tools/Polls/Polls_Edit_Answer_List.aspx?pollId=" + pollId + "&groupId=" + groupId),
        });
        PageBreadcrumbs.Items.Add(new BreadcrumbItem
        {
            Text = currentPollAnswer,
        });

        // New item link
        HeaderAction add = new HeaderAction
        {
            Text        = GetString("Polls_Answer_List.NewItemCaption"),
            RedirectUrl = ResolveUrl("Polls_Edit_Answer_Edit.aspx?pollId=" + pollId.ToString() + "&groupId=" + groupId)
        };

        CurrentMaster.HeaderActions.AddAction(add);
    }
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        ClearForm();
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
        }

        if (pollAnswerObj != null)
        {
            // Load the fields
            txtAnswerText.Text = pollAnswerObj.AnswerText;
            chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
            txtVotes.Text = pollAnswerObj.AnswerCount.ToString();
            pnlGeneral.GroupingText = GetString("general.general");
            plcVotes.Visible = true;

            // Check if bizform module is available (for open-ended answers).
            if (ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleEntry.BIZFORM, CMSContext.CurrentSiteName))
            {
                // Show open-ended answer settings only for site poll
                PollInfo pi = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);
                plcOpenAnswer.Visible = (pi != null) && (pi.PollSiteID > 0) && (pi.PollGroupID == 0);

                chkAnswerIsOpenEnded.Checked = plcOpenAnswerSettings.Visible = pollAnswerObj.AnswerIsOpenEnded;
                bizFormElem.Value = pollAnswerObj.AnswerForm;
                alternativeFormElem.ClassName = "BizForm." + bizFormElem.Text;
                alternativeFormElem.Value = pollAnswerObj.AnswerAlternativeForm;
                chkAnswerHideForm.Checked = pollAnswerObj.AnswerHideForm;
                pnlAnswerForm.GroupingText = GetString("polls.answerformsettings");
            }
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible = false;
            pnlGeneral.GroupingText = string.Empty;
        }
    }
Пример #22
0
    /// <summary>
    /// On btnVote click event handler.
    /// </summary>
    protected void btnVote_OnClick(object sender, EventArgs e)
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblInfo.CssClass = "ErrorMessage";
            lblInfo.Text     = GetString("General.BannedIP");
            return;
        }

        if (pi != null)
        {
            // Indicates whether user voted or not
            bool voted = false;

            // Check if user has already voted
            if ((this.CheckVoted) && (PollInfoProvider.HasVoted(pi.PollID)))
            {
                errMessage = GetString("Polls.UserHasVoted");
                voted      = true;
            }
            else if (isOpened)
            {
                // Get poll answers
                DataSet ds = Answers;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    LocalizedCheckBox    chkItem = null;
                    LocalizedRadioButton radItem = null;
                    bool           selected      = false;
                    PollAnswerInfo pai           = null;

                    // List of poll answers (in case of multiple answers) for activity logging
                    StringBuilder pollAnswerIDs = new StringBuilder();

                    foreach (DataRow row in rows)
                    {
                        pai = new PollAnswerInfo(row);

                        if ((pai != null) && (pai.AnswerEnabled))
                        {
                            selected = false;

                            // Find specific controls and update pollanswerinfo if controls are checked
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Find checkbox
                                chkItem = (LocalizedCheckBox)this.pnlAnswer.FindControl("chk" + pai.AnswerID);

                                if (chkItem != null)
                                {
                                    selected = chkItem.Checked;
                                }
                            }
                            else
                            {
                                // Find radiobutton
                                radItem = (LocalizedRadioButton)this.pnlAnswer.FindControl("rad" + pai.AnswerID);

                                if (radItem != null)
                                {
                                    selected = radItem.Checked;
                                }
                            }

                            if ((selected) && (pai.AnswerCount < Int32.MaxValue))
                            {
                                // Set the vote
                                PollAnswerInfoProvider.Vote(pai.AnswerID);
                                voted = true;

                                // Save all selected answers (for activity logging)
                                pollAnswerIDs.Append(pai.AnswerID);
                                pollAnswerIDs.Append(ActivityLogProvider.POLL_ANSWER_SEPARATOR);
                            }
                        }
                    }

                    if (voted)
                    {
                        LogActivity(pi, pollAnswerIDs.ToString());
                    }

                    if ((this.CheckVoted) && (voted))
                    {
                        // Create cookie about user's voting
                        PollInfoProvider.SetVoted(pi.PollID);
                    }
                }
            }

            if (voted)
            {
                // Clear cache if it's used
                Answers = null;
                // Reload poll control
                ReloadData(true);

                if (OnAfterVoted != null)
                {
                    OnAfterVoted(this, EventArgs.Empty);
                }
            }
            else
            {
                lblInfo.CssClass = "ErrorMessage";
                lblInfo.Text     = GetString("Polls.DidNotVoted");
            }
        }
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Load current answer object
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
        }
        // Check permission for answer object (global/site poll)
        if (!CheckModifyPermission(PollId))
        {
            return;
        }

        string errorMessage = null;
        // Validate the input
        if (txtVotes.Visible)
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage)
                .IsPositiveNumber(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber"), true)
                .IsInteger(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber")).Result;
        }
        else
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage).Result;
        }

        if (String.IsNullOrEmpty(errorMessage))
        {
            // If pollAnswer doesn't already exist, create new one
            if (pollAnswerObj == null)
            {
                pollAnswerObj = new PollAnswerInfo();
                pollAnswerObj.AnswerOrder = PollAnswerInfoProvider.GetLastAnswerOrder(PollId) + 1;
                pollAnswerObj.AnswerCount = 0;
                pollAnswerObj.AnswerPollID = PollId;
            }

            // Set the fields
            pollAnswerObj.AnswerEnabled = chkAnswerEnabled.Checked;
            pollAnswerObj.AnswerText = txtAnswerText.Text.Trim();
            pollAnswerObj.AnswerCount = ValidationHelper.GetInteger(txtVotes.Text, 0);

            if (plcOpenAnswer.Visible)
            {
                string answerForm = ValidationHelper.GetString(bizFormElem.Value, string.Empty);
                if (chkAnswerIsOpenEnded.Checked && string.IsNullOrEmpty(answerForm))
                {
                    ShowError(GetString("Polls_Answer_Edit.SelectForm"));
                    return;
                }
                pollAnswerObj.AnswerForm = answerForm;
                pollAnswerObj.AnswerAlternativeForm = ValidationHelper.GetString(alternativeFormElem.Value, string.Empty);
                pollAnswerObj.AnswerHideForm = chkAnswerHideForm.Checked;
            }

            // Save the data
            PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);
            Saved = true;
            ItemID = pollAnswerObj.AnswerID;

            // Raise event;
            RaiseOnSaved();
        }
        else
        {
            // Error message - Validation
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Loads new data for this control.
    /// </summary>
    public void LoadData()
    {
        // If working with existing record
        if (ItemID > 0)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(ItemID);
            EditedObject = pollAnswerObj;

            if (pollAnswerObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    ReloadData();
                }

                // When saved, display info message
                if (Saved)
                {
                    ShowChangesSaved();
                    Saved = false;
                }

                PollId = pollAnswerObj.AnswerPollID;
            }
        }
        // If creating new record
        else
        {
            plcVotes.Visible = false;
            txtVotes.Text = "0";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get AnswerID and PollID from querystring
        pollId   = QueryHelper.GetInteger("pollId", 0);
        answerId = QueryHelper.GetInteger("answerId", 0);
        groupId  = QueryHelper.GetInteger("groupId", 0);

        string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");

        // Initialize AnswerEdit control
        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            AnswerEdit.Saved = true;
        }
        AnswerEdit.ItemID              = answerId;
        AnswerEdit.PollId              = pollId;
        AnswerEdit.OnSaved            += new EventHandler(AnswerEdit_OnSaved);
        AnswerEdit.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(AnswerEdit_OnCheckPermissions);

        if (answerId > 0)
        {
            CurrentMaster.Title.HelpTopicName = "answer_edit";
            PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(answerId);
            EditedObject = pollAnswerObj;
            if (pollAnswerObj != null)
            {
                // Check that poll belongs to the specified group
                if ((pollAnswerObj.AnswerPollID > 0) && (groupId > 0))
                {
                    PollInfo poll = PollInfoProvider.GetPollInfo(pollAnswerObj.AnswerPollID);

                    // Answer not found or doesn't belong to specified group
                    if ((poll == null) || (poll.PollGroupID != groupId))
                    {
                        RedirectToAccessDenied(GetString("community.group.pollnotassigned"));
                    }
                }

                // Set control
                currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                pollId            = pollAnswerObj.AnswerPollID;
            }
        }
        else
        {
            CurrentMaster.Title.HelpTopicName = "new_answer";
        }

        // Validate
        EditedObject = PollInfoProvider.GetPollInfo(pollId);

        // Initializes page title control
        string[,] breadcrumbs           = new string[2, 3];
        breadcrumbs[0, 0]               = GetString("Polls_Answer_Edit.ItemListLink");
        breadcrumbs[0, 1]               = "~/CMSModules/Groups/Tools/Polls/Polls_Edit_Answer_List.aspx?pollId=" + pollId + "&groupId=" + groupId;
        breadcrumbs[0, 2]               = "";
        breadcrumbs[1, 0]               = currentPollAnswer;
        breadcrumbs[1, 1]               = "";
        breadcrumbs[1, 2]               = "";
        CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        // New item link
        HeaderAction add = new HeaderAction()
        {
            ControlType = HeaderActionTypeEnum.Hyperlink,
            Text        = GetString("Polls_Answer_List.NewItemCaption"),
            RedirectUrl = ResolveUrl("Polls_Edit_Answer_Edit.aspx?pollId=" + pollId.ToString() + "&groupId=" + groupId),
            ImageUrl    = GetImageUrl("Objects/Polls_PollAnswer/add.png")
        };

        CurrentMaster.HeaderActions.AddAction(add);
    }
Пример #26
0
    /// <summary>
    /// Deletes answer. Called when the "Delete answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool DeleteAnswer()
    {
        // Get the poll
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", CMSContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the answer
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo deleteAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Delete the answer
                PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);

                return (deleteAnswer != null);
            }
        }

        return false;
    }
Пример #27
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Load current answer object
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
        }
        // Check permission for answer object (global/site poll)
        if (!CheckModifyPermission(this.PollId))
        {
            return;
        }

        string errorMessage = null;
        // Validate the input
        if (txtVotes.Visible)
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage)
                .IsPositiveNumber(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber"), true)
                .IsInteger(txtVotes.Text, GetString("Polls_Answer_Edit.VotesNotNumber")).Result;
        }
        else
        {
            errorMessage = new Validator().NotEmpty(txtAnswerText.Text, rfvAnswerText.ErrorMessage).Result;
        }

        if (String.IsNullOrEmpty(errorMessage))
        {
            // If pollAnswer doesn't already exist, create new one
            if (pollAnswerObj == null)
            {
                pollAnswerObj = new PollAnswerInfo();
                pollAnswerObj.AnswerOrder = PollAnswerInfoProvider.GetLastAnswerOrder(this.PollId) + 1;
                pollAnswerObj.AnswerCount = 0;
                pollAnswerObj.AnswerPollID = this.PollId;
            }

            // Set the fields
            pollAnswerObj.AnswerEnabled = chkAnswerEnabled.Checked;
            pollAnswerObj.AnswerText = txtAnswerText.Text.Trim();
            pollAnswerObj.AnswerCount = ValidationHelper.GetInteger(this.txtVotes.Text, 0);

            // Save the data
            PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);
            this.Saved = true;
            this.ItemID = pollAnswerObj.AnswerID;

            // Raise event;
            RaiseOnSaved();
        }
        else
        {
            // Error message - Validation
            lblError.Visible = true;
            lblError.Text = errorMessage;
        }
    }
Пример #28
0
    /// <summary>
    /// Gets and updates answer. Called when the "Get and update answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndUpdateAnswer()
    {
        // Get the answer
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", CMSContext.CurrentSiteID);

        if (updatePoll != null)
        {
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo updateAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Update the properties
                updateAnswer.AnswerText = updateAnswer.AnswerText.ToLower();

                // Save the changes
                PollAnswerInfoProvider.SetPollAnswerInfo(updateAnswer);

                return true;
            }
        }

        return false;
    }
Пример #29
0
    /// <summary>
    /// Reloads answer data.
    /// </summary>
    public override void ReloadData()
    {
        this.ClearForm();
        if (pollAnswerObj == null)
        {
            pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(this.ItemID);
        }

        if (pollAnswerObj != null)
        {
            // Load the fields
            txtAnswerText.Text = pollAnswerObj.AnswerText;
            chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
            txtVotes.Text = pollAnswerObj.AnswerCount.ToString();
            plcVotes.Visible = true;
        }
        else
        {
            txtAnswerText.Text = String.Empty;
            plcVotes.Visible = false;
        }
    }
    /// <summary>
    /// On btnVote click event handler.
    /// </summary>
    protected void btnVote_OnClick(object sender, EventArgs e)
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblInfo.CssClass = "ErrorMessage";
            lblInfo.Text     = GetString("General.BannedIP");
            return;
        }

        if (pi != null)
        {
            // Indicates whether user voted or not
            bool voted = false;

            // Indicates wheter all forms of all open-ended answers can be saved
            bool       formsAreValid   = true;
            List <int> selectedAnswers = new List <int>();

            // Check if user has already voted
            if ((CheckVoted) && (PollInfoProvider.HasVoted(pi.PollID)))
            {
                errMessage = GetString("Polls.UserHasVoted");
                voted      = true;
            }
            else if (isOpened)
            {
                // Get poll answers
                DataSet ds = Answers;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    CMSCheckBox    chkItem  = null;
                    CMSRadioButton radItem  = null;
                    bool           selected = false;
                    PollAnswerInfo pai      = null;
                    BizForm        bizItem  = null;

                    foreach (DataRow row in rows)
                    {
                        pai = new PollAnswerInfo(row);

                        if ((pai != null) && (pai.AnswerEnabled))
                        {
                            selected = false;

                            // Find specific controls and update pollanswerinfo if controls are checked
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Find checkbox
                                chkItem = (CMSCheckBox)pnlAnswer.FindControl("chk" + pai.AnswerID);

                                if (chkItem != null)
                                {
                                    selected = chkItem.Checked;
                                }
                            }
                            else
                            {
                                // Find radiobutton
                                radItem = (CMSRadioButton)pnlAnswer.FindControl("rad" + pai.AnswerID);

                                if (radItem != null)
                                {
                                    selected = radItem.Checked;
                                }
                            }

                            if ((selected) && (pai.AnswerCount < Int32.MaxValue))
                            {
                                bool canBeSaved = false;
                                bizItem = (BizForm)pnlAnswer.FindControl("frm" + pai.AnswerID);

                                if (bizItem == null)
                                {
                                    canBeSaved = true;
                                }
                                else if (bizItem != null)
                                {
                                    // Validate form data
                                    canBeSaved = bizItem.ValidateData();
                                }

                                if (canBeSaved)
                                {
                                    selectedAnswers.Add(pai.AnswerID);
                                }
                                else
                                {
                                    formsAreValid = false;
                                }
                            }
                        }
                    }

                    if (formsAreValid)
                    {
                        if (selectedAnswers.Count > 0)
                        {
                            foreach (int aid in selectedAnswers)
                            {
                                // Set the vote
                                PollAnswerInfoProvider.Vote(aid);
                                // Save the bizform data
                                bizItem = (BizForm)pnlAnswer.FindControl("frm" + aid);
                                if (bizItem != null)
                                {
                                    if (bizItem != null)
                                    {
                                        bizItem.SaveData(null, false);
                                    }
                                }
                            }
                            voted = true;
                        }
                        else
                        {
                            // Set error message if no answer selected
                            lblInfo.CssClass = "ErrorMessage";
                            lblInfo.Text     = GetString("Polls.DidNotVoted");
                        }
                    }

                    if (voted)
                    {
                        LogActivity(pi, selectedAnswers);
                    }

                    if ((CheckVoted) && (voted))
                    {
                        // Create cookie about user's voting
                        PollInfoProvider.SetVoted(pi.PollID);
                    }
                }
            }

            if (voted)
            {
                // Clear cache if it's used
                Answers = null;
                // Reload poll control
                ReloadData(true);

                if (OnAfterVoted != null)
                {
                    OnAfterVoted(this, EventArgs.Empty);
                }
            }
        }
    }
Пример #31
0
    /// <summary>
    /// Displays appropriate controls regarding set properties.
    /// </summary>
    private void DisplayControls(string selectedPage, bool forceReload)
    {
        PollProperties.Visible      = false;
        AnswerList.Visible          = false;
        PollSecurity.Visible        = false;
        PollView.Visible            = false;
        PollView.StopProcessing     = true;
        headerLinks.Visible         = false;
        pnlPollsBreadcrumbs.Visible = false;
        pnlPollsLinks.Visible       = false;
        AnswerEdit.Visible          = false;
        btnResetAnswers.Visible     = true;
        imgResetAnswers.Visible     = true;

        if (forceReload)
        {
            selectedPage        = "0";
            tabMenu.SelectedTab = 0;
        }

        // Display appropriate tab
        switch (selectedPage)
        {
        // Poll properties
        case "0":
        default:
            PollProperties.Visible = true;
            PollProperties.ItemID  = ItemID;

            PollProperties.ReloadData();
            break;

        // Answer list
        case "1":
            AnswerList.Visible = true;
            AnswerList.PollId  = ItemID;
            AnswerList.ReloadData(true);
            headerLinks.Visible   = true;
            pnlPollsLinks.Visible = true;
            break;

        // Answer edit
        case "answersedit":
            headerLinks.Visible         = true;
            pnlPollsBreadcrumbs.Visible = true;
            pnlPollsLinks.Visible       = true;
            AnswerEdit.Visible          = true;
            AnswerEdit.PollId           = ItemID;
            AnswerEdit.ReloadData();
            btnResetAnswers.Visible = false;
            imgResetAnswers.Visible = false;
            AnswerEditSelected      = true;

            // Initialize breadcrumbs
            string currentPollAnswer = GetString("Polls_Answer_Edit.NewItemCaption");
            if (AnswerEdit.ItemID > 0)
            {
                PollAnswerInfo pollAnswerObj = PollAnswerInfoProvider.GetPollAnswerInfo(AnswerEdit.ItemID);
                if (pollAnswerObj != null)
                {
                    currentPollAnswer = GetString("Polls_Answer_Edit.AnswerLabel") + " " + pollAnswerObj.AnswerOrder.ToString();
                }
            }
            lblAnswer.Text = currentPollAnswer;
            break;

        // Poll security
        case "2":
            PollSecurity.Visible = true;
            PollSecurity.ItemID  = ItemID;
            PollSecurity.ReloadData();
            break;

        // Poll view
        case "3":
            PollView.Visible = true;
            InitPollView(ItemID);
            PollView.StopProcessing = false;
            PollView.ReloadData(false);
            break;
        }
    }