Exemplo n.º 1
0
    /// <summary>
    /// Handles events that occur when an edit operation is requested, but before the Update Answers ListView item is put in edit mode.
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Provides data for the ItemEditing event, which occurs when an edit operation is requested but before the ListView item is put in edit mode.</param>
    protected void UpdateAnswersListView_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        //hide message user control
        MessageUserControl.Visible = false;

        //hide datapager
        DataPager pager = UpdateAnswersListView.FindControl("ActiveDataPager") as DataPager;

        pager.Visible = false;
    }
Exemplo n.º 2
0
    /// <summary>
    /// Populates and updates the subquestions list view based on the selected question
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Represents the base class for classes that contain event data, and provides a value to use for events that do not include event data.</param>
    protected void FetchAnswersButton_Click(object sender, EventArgs e)
    {
        //if user selects the "Select a question..." option in the dropdown list, do the following actions:
        if (QuestionsWithAnswersDropDownList.SelectedValue == "0")
        {
            //show error message
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfoError("No Question Selected", "Please select a question.");

            //highlight the dropdown list and refresh the answers listview
            QuestionsWithAnswersDropDownList.Focus();
            UpdateAnswersListView.DataBind();
        }
        else
        {
            //show informational message
            MessageUserControl.ShowInfo("Answers Displayed", "Answers associated under the selected question are now displayed.");
            UpdateAnswersListView.DataBind();
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Handles the actions executed by command buttons found in the Answers list view
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Provides data for the ItemCommand event, which occurs when a button in a ListView is clicked.</param>
    protected void UpdateAnswersListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        //If the Edit button is clicked, do the following actions:
        if (e.CommandName.Equals("Edit"))
        {
            //show informational message
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Edit Mode Active", "The answer text in the selected row can now be edited.");

            //disable drop-down list and fetch button to prevent editing of answers to other questions
            QuestionsWithAnswersDropDownList.Enabled = false;
            FetchAnswersButton.Enabled = false;
        }
        //If the Change button is clicked, do the following actions:
        else if (e.CommandName.Equals("Change"))
        {
            //capture the answer Id of the selected row
            int answerId = int.Parse(e.CommandArgument.ToString());
            //capture the row index of the selected row
            int i = e.Item.DisplayIndex;

            //find the answer textbox in the selected row
            TextBox answerTextBox = UpdateAnswersListView.Items[i].FindControl("descriptionTextBox") as TextBox;

            //capture the answer text from the textbox
            string answerText = answerTextBox.Text;

            //handle null values and white-space-only values
            if (string.IsNullOrEmpty(answerText) || string.IsNullOrWhiteSpace(answerText))
            {
                //show error message
                MessageUserControl.Visible = true;
                MessageUserControl.ShowInfoError("Processing Error", "Answer is required.");

                //highlight the answer textbox in the row that caused the error
                answerTextBox.Focus();
            }
            //if user-entered value is not null or just a white space, do the the following actions:
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    //check if user entered invalid values
                    Utility utility = new Utility();
                    utility.checkValidString(answerText);

                    //update the answer text of the selected row
                    AnswerController sysmgr = new AnswerController();
                    sysmgr.Answer_Update(answerText, answerId);
                    UpdateAnswersListView.DataBind();
                    UpdateAnswersListView.EditIndex = -1;
                }, "Success", "Answer has been updated.");
            }

            //show success/error message
            MessageUserControl.Visible = true;

            //show datapager
            DataPager pager = UpdateAnswersListView.FindControl("ActiveDataPager") as DataPager;
            pager.Visible = true;

            //enable drop-down list and fetch button to allow editing of other answers to other questions
            QuestionsWithAnswersDropDownList.Enabled = true;
            FetchAnswersButton.Enabled = true;
        }
        //If the Cancel button is clicked, do the following actions:
        else if (e.CommandName.Equals("Cancel"))
        {
            //show informational message
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Update canceled", "No changes to the selected answer were saved.");

            //show datapager
            DataPager pager = UpdateAnswersListView.FindControl("ActiveDataPager") as DataPager;
            pager.Visible = true;

            //enable drop-down list and fetch button to allow editing of other answers to other questions
            QuestionsWithAnswersDropDownList.Enabled = true;
            FetchAnswersButton.Enabled = true;
        }
    }