protected void AnswerListGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
 {
     try
     {
         e.Cancel = true;
         DBAgent  = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
         DBAgent.AddParameter("@ParamAnswerText", e.NewValues[0]);
         object o = DBAgent.ExecuteScalar("dbo.spAddAnswer");
         if (o != null)
         {
             ViewState["NewAnswerID"] = o;
         }
         AnswerListGridView.CancelEdit();
     }
     catch (Exception ex)
     {
         CommonHelpers.writeLogToFile("AnswerListGridView_RowInserting: EditQuestionnaire.aspx", ex.Message);
     }
 }
        protected void cmdSaveQuestion_Click(object sender, EventArgs e)
        {
            try
            {
                int QuestionID = 0;
                DBAgent = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
                DBAgent.AddParameter("@ParamQuestionText", txtQuestion.Text);
                object o = DBAgent.ExecuteScalar("dbo.spAddQuestion");
                if (o != null)
                {
                    QuestionID = int.Parse(o.ToString());
                    if (QuestionID > 0)
                    {
                        int AnswerSortOrder = 1;
                        foreach (ListEditItem li in lbSelectedAnswers.Items)
                        {
                            DBAgent.ClearParams();
                            DBAgent.AddParameter("@ParamQuestionID", QuestionID);
                            DBAgent.AddParameter("@ParamAnswerID", li.Value);
                            DBAgent.AddParameter("@ParamAnswerSortOrder", AnswerSortOrder);
                            DBAgent.ExecuteNonQuery("dbo.spAddQuestionAnswerMapping");
                            AnswerSortOrder++;
                        }

                        DBAgent.ClearParams();
                        DBAgent.AddParameter("@ParamQuestionnaireID", cmbQuestionnaireList.SelectedItem.Value);
                        DBAgent.AddParameter("@ParamQuestionID", QuestionID);
                        DBAgent.ExecuteNonQuery("dbo.spAddQuestionnaireQuestionMapping");
                        QuestionsGridView.DataBind();
                        RefreshForm();
                    }
                }

                QuestionsGridView.DataBind();
            }
            catch (Exception ex)
            {
                CommonHelpers.writeLogToFile("cmdSaveQuestion_Click: EditQuestionnaire.aspx", ex.Message);
            }
        }
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                CryptoProvider securityAgent   = new CryptoProvider();
                int            QuestionnaireID = 0;
                DBAgent = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
                DBAgent.AddParameter("ParamQuestionnaireName", txtQuestionnaireName.Value);
                object o = DBAgent.ExecuteScalar("spAddEditQuestionnaire", ConfigurationManager.AppSettings["DBName"]);
                if (o != null)
                {
                    QuestionnaireID = int.Parse(o.ToString());
                }

                listDataSource = (BindingList <Record>)Session["ConfigurationValues"];

                if (QuestionnaireID > 0)
                {
                    foreach (Record r in listDataSource)
                    {
                        DBAgent.AddParameter("ParamQuestionnaireID", QuestionnaireID);
                        DBAgent.AddParameter("ParamConfigID", r.ConfigID);
                        DBAgent.AddParameter("ParamMinValue", r.MinValue);
                        DBAgent.AddParameter("ParamMaxValue", r.MaxValue);
                        DBAgent.ExecuteNonQuery("spAddQuestionnaireConfig", ConfigurationManager.AppSettings["DBName"]);
                    }

                    Session["ConfigurationValues"] = null;
                    Response.Redirect("EditQuestionnaire.aspx?QID=" + securityAgent.EncryptText(QuestionnaireID.ToString()));
                }
            }
            catch (Exception ex)
            {
                lblErr.Text    = "There was a problem processing your request. Please contact IT.";
                lblErr.Visible = true;
                CommonHelpers.writeLogToFile("cmdSave_Click: NewQuestionnaire.aspx", ex.Message);
            }
        }