Beispiel #1
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);
    }
Beispiel #2
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);
    }
Beispiel #3
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;
        }
    }
Beispiel #4
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);
    }
    /// <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);
        }
    }