Ejemplo n.º 1
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;
        }
    }
Ejemplo n.º 2
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);
        }
    }