Пример #1
0
    /// <summary>
    /// Handles events that occur when an edit operation is requested, but before the Update Questions 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 UpdateQuestionsListView_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        //hide message user control
        MessageUserControl.Visible = false;

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

        pager.Visible = false;
    }
Пример #2
0
    /// <summary>
    /// Handles events that occur when a button in the Questions list view is clicked.
    /// </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 UpdateQuestionsListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        //hide message user control
        MessageUserControl.Visible = false;

        //If the Edit button is clicked, show informational message
        if (e.CommandName.Equals("Edit"))
        {
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Edit Mode Active", "The question text in the selected row can now be edited.");
        }
        //If the Change button is clicked, do the following actions:
        else if (e.CommandName.Equals("Change"))
        {
            int i = e.Item.DisplayIndex;

            //Capture and store the question text on the selected index
            TextBox questionTextBox = UpdateQuestionsListView.Items[i].FindControl("questionTextTextBox") as TextBox;
            string  questionText    = questionTextBox.Text;

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

                //highlight the question textbox that handled the error
                questionTextBox.Focus();
            }
            //if user-entered value is not null or just a white space, do the the following actions:
            else
            {
                //find the question Id repeater that stores the question Ids associated with the edited question text
                Repeater questionIdRepeater = UpdateQuestionsListView.Items[i].FindControl("QuestionIdListRepeater") as Repeater;

                //loop through the question Id repeater
                foreach (RepeaterItem item in questionIdRepeater.Items)
                {
                    //capture the question Id
                    int questionId = int.Parse(((Label)item.FindControl("questionIdLabel")).Text);

                    MessageUserControl.TryRun(() =>
                    {   //check if user entered invalid values
                        Utility utility = new Utility();
                        utility.checkValidString(questionText);

                        //Update the selected question(s)
                        QuestionController sysmgr = new QuestionController();
                        sysmgr.Question_Update(questionText, questionId);

                        //turn off edit mode and refresh the listview
                        UpdateQuestionsListView.EditIndex = -1;
                        UpdateQuestionsListView.DataBind();
                    }, "Success", "Question has been updated.");
                }

                //show success/error message captured by message user control's try run method
                MessageUserControl.Visible = true;

                //reset update subquestions tab
                QuestionsWithSubQuestionsDropDownList.Items.Clear();
                QuestionsWithSubQuestionsDropDownList.Items.Add(new ListItem("Select a question...", "0"));
                QuestionsWithSubQuestionsDropDownList.DataBind();
                QuestionsWithSubQuestionsDropDownList.Enabled = true;
                FetchSubQuestionsButton.Enabled = true;

                //reset update answers tab
                QuestionsWithAnswersDropDownList.Items.Clear();
                QuestionsWithAnswersDropDownList.Items.Add(new ListItem("Select a question...", "0"));
                QuestionsWithAnswersDropDownList.DataBind();
                QuestionsWithAnswersDropDownList.Enabled = true;
                FetchAnswersButton.Enabled = true;

                //show datapager
                DataPager pager = UpdateQuestionsListView.FindControl("ActiveDataPager") as DataPager;
                pager.Visible = true;
            }
        }
        //If the Cancel button is clicked, show informational message
        else if (e.CommandName.Equals("Cancel"))
        {
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Update Cancelled", "No changes to the selected question were saved.");

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