Exemple #1
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    SurveysInfo survey;
                    if (SurveyID == 0)
                    {
                        survey = new SurveysInfo();
                    }
                    else
                    {
                        survey = Survey;
                    }
                    survey.SurveyID      = SurveyID;
                    survey.ModuleID      = ModuleId;
                    survey.Question      = QuestionTextBox.Text;
                    survey.OptionType    = (QuestionType)Convert.ToInt32(QuestionTypeDropDownList.SelectedValue);
                    survey.IsStatistical = (SurveyType == SurveyType.Quiz ? IsStatisticalCheckBox.Checked : (bool?)null);
                    if (survey.OptionType == QuestionType.Text)
                    {
                        int surveyOptionID = 0;
                        if (SurveyID > 0)
                        {
                            surveyOptionID = SurveyOptionsController.GetAll(SurveyID)[0].SurveyOptionID;
                        }
                        Answers = DummyData.LoadDummyForTextAnswer(SurveyID, surveyOptionID, UserId);
                    }
                    else
                    {
                        if (Request.Form["SurveyOptionID"] == null)
                        {
                            // You can't add a single or multiple choice question with no answers...
                            ErrorMessagePanel.Visible = true;
                            ErrorMessageLabel.Text    = Localization.GetString("NoAnswersProvided.Text", LocalResourceFile);
                        }
                        else
                        {
                            //if (SurveyID > 0)
                            //{
                            List <SurveyOptionsInfo> answers = Answers;
                            int[] surveyOptionIDs            = (from p in Request.Form["SurveyOptionID"].Split(',')
                                                                select int.Parse(p)).ToArray();
                            int viewOrder = 1;
                            foreach (int surveyOptionID in surveyOptionIDs)
                            {
                                SurveyOptionsInfo answer = answers.Find(x => x.SurveyOptionID == surveyOptionID);
                                answer.ViewOrder = viewOrder;
                                viewOrder++;
                            }
                            Answers = answers;
                            //}
                            int correctAnswers = Answers.Where(a => a.IsCorrect).Count();
                            if ((SurveyType == SurveyType.Quiz) && (!(IsStatisticalCheckBox.Checked)) && (correctAnswers == 0))
                            {
                                ErrorMessagePanel.Visible = true;
                                ErrorMessageLabel.Text    = Localization.GetString("NoCorrectAnswersProvided.Text", LocalResourceFile);
                            }
                            if ((SurveyType == SurveyType.Quiz) && (!(IsStatisticalCheckBox.Checked)) && (survey.OptionType == QuestionType.RadioButtons) && (correctAnswers > 1))
                            {
                                ErrorMessagePanel.Visible = true;
                                ErrorMessageLabel.Text    = Localization.GetString("OnlyOneCorrectAnswerAllowed.Text", LocalResourceFile);
                            }
                        }
                    }
                    if (!(ErrorMessagePanel.Visible))
                    {
                        survey.RepeatDirection = (RepeatDirection)Convert.ToInt32(RepeatDirectionDropDownList.SelectedValue);
                        survey.RepeatColumns   = (String.IsNullOrEmpty(RepeatColumnsTextBox.Text) ? (int?)null : Convert.ToInt32(RepeatColumnsTextBox.Text));
                        survey.NumberOfRows    = (((String.IsNullOrEmpty(NumberOfRowsTextBox.Text)) || (NumberOfRowsTextBox.Text == "1")) ? (int?)null : Convert.ToInt32(NumberOfRowsTextBox.Text));

                        survey.ChartType = (ChartType)Convert.ToInt32(ChartTypeDropDownList.SelectedValue);

                        SurveysController.AddOrChange(survey, XmlDataProvider.SurveyOptionsToXml(Answers), UserId);
                        Response.Redirect(Globals.NavigateURL(), false);
                    }
                }
                catch (Exception ex)
                {
                    Exceptions.ProcessModuleLoadException(this, ex);
                }
            }
        }