Пример #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            DefaultAnswerBO oDefaultAnswerBO = new DefaultAnswerBO();
            DefaultAnswerBAL oDefaultAnswerBAL = new DefaultAnswerBAL();
            oDefaultAnswerBO.questionID = long.Parse(drpQuestion.SelectedValue);
            DataTable dt = new DataTable();
            dt = oDefaultAnswerBAL.FindDefaultAnswer(oDefaultAnswerBO);

            if (dt.Rows.Count != 0)
            {
                int QTypeId = int.Parse(dt.Rows[0]["QTypeId"].ToString());

                if (QTypeId == 1)
                {
                    oAnswerBO.answer = txtComment.Text;
                }
                else if (QTypeId == 2)
                {
                    string answer = string.Empty;

                    foreach (ListItem listItem in chkMultipleAnswer.Items)
                    {
                        if (listItem.Selected)
                        {
                            answer += listItem.Text + ",";
                        }
                    }
                    if (answer.Length != 0)
                        oAnswerBO.answer = answer.Substring(0, answer.Length - 1);
                    else
                        oAnswerBO.answer = string.Empty;
                }
                else if (QTypeId == 3)
                {
                    string answer = string.Empty;

                    foreach (ListItem listItem in rbtnlOnlyOneAnswer.Items)
                    {
                        if (listItem.Selected)
                        {
                            answer += listItem.Text + ",";
                        }
                    }
                    if (answer.Length != 0)
                        oAnswerBO.answer = answer.Substring(0, answer.Length - 1);
                    else
                        oAnswerBO.answer = string.Empty;
                }
            }
            oAnswerBO.questionID = long.Parse(drpQuestion.SelectedValue);
            oAnswerBO.userID = long.Parse(Session["userID"].ToString());
            oAnswerBAL.InsertAnswer(oAnswerBO);
            BindQuestion();
            BindGrid();
            Clear();
            Panel1.Visible = false;
            Panel2.Visible = false;
            Panel3.Visible = false;
            Panel4.Visible = false;
            Panel5.Visible = false;
            lblMessage.Text = "Record saved.";
        }
        catch (Exception ex)
        {
            ((Label)(Master.FindControl("lblMessage"))).Text = ex.Message.ToString();
        }
    }
Пример #2
0
    protected void drpQuestion_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (int.Parse(drpQuestion.SelectedValue) != 0)
            {
                DefaultAnswerBO oDefaultAnswerBO = new DefaultAnswerBO();
                DefaultAnswerBAL oDefaultAnswerBAL = new DefaultAnswerBAL();
                oDefaultAnswerBO.questionID = long.Parse(drpQuestion.SelectedValue);
                DataTable dt = new DataTable();
                dt = oDefaultAnswerBAL.FindDefaultAnswer(oDefaultAnswerBO);

                if (dt.Rows.Count != 0)
                {
                    int QTypeId = int.Parse(dt.Rows[0]["QTypeId"].ToString());
                    string defaultAnswers = dt.Rows[0]["defaultAnswers"].ToString();
                    string control = dt.Rows[0]["control"].ToString();

                    if (QTypeId == 1)
                    {
                        txtComment.Text = string.Empty;

                        Panel1.Visible = true;
                        Panel2.Visible = false;
                        Panel3.Visible = false;
                        Panel4.Visible = false;
                        Panel5.Visible = false;

                        txtComment.Text = defaultAnswers;
                    }
                    else if (QTypeId == 2)
                    {
                        chkMultipleAnswer.Items.Clear();

                        Panel1.Visible = false;
                        Panel2.Visible = true;
                        Panel3.Visible = false;
                        Panel4.Visible = false;
                        Panel5.Visible = false;

                        string[] str = defaultAnswers.Split(',');
                        for (int i = 0; i < str.Length; i++)
                        {
                            ListItem lst = new ListItem();
                            lst.Value = i.ToString();
                            lst.Text = str[i].ToString();
                            chkMultipleAnswer.Items.Add(lst);
                        }
                    }
                    else if (QTypeId == 3)
                    {
                        rbtnlOnlyOneAnswer.Items.Clear();

                        Panel1.Visible = false;
                        Panel2.Visible = false;
                        Panel3.Visible = true;
                        Panel4.Visible = false;
                        Panel5.Visible = false;

                        string[] str = defaultAnswers.Split(',');
                        for (int i = 0; i < str.Length; i++)
                        {
                            ListItem lst = new ListItem();
                            lst.Value = i.ToString();
                            lst.Text = str[i].ToString();
                            rbtnlOnlyOneAnswer.Items.Add(lst);
                        }
                    }
                    else if (QTypeId == 4)
                    {
                        Panel1.Visible = false;
                        Panel2.Visible = false;
                        Panel3.Visible = false;
                        Panel4.Visible = true;
                        Panel5.Visible = false;

                    }
                }
            }
        }
        catch (Exception ex)
        {
            ((Label)(Master.FindControl("lblMessage"))).Text = ex.Message.ToString();
        }
    }