예제 #1
0
        public static SurveyOptionsInfo SurveyOptionFromXml(string surveyOptionXml)
        {
            SurveyOptionsInfo surveyOption = null;

            if ((!(string.IsNullOrEmpty(surveyOptionXml))) && (surveyOptionXml != "<SurveyOption />"))
            {
                surveyOption = new SurveyOptionsInfo();
                XmlNode surveyOptionXmlNode = Globals.GetContent(surveyOptionXml, "SurveyOption");
                surveyOption.SurveyOptionID  = Convert.ToInt32(surveyOptionXmlNode.SelectSingleNode("SurveyOptionID").InnerText);
                surveyOption.ViewOrder       = Convert.ToInt32(surveyOptionXmlNode.SelectSingleNode("ViewOrder").InnerText);
                surveyOption.OptionName      = surveyOptionXmlNode.SelectSingleNode("OptionName").InnerText;
                surveyOption.Votes           = Convert.ToInt32(surveyOptionXmlNode.SelectSingleNode("Votes").InnerText);
                surveyOption.IsCorrect       = Convert.ToBoolean(surveyOptionXmlNode.SelectSingleNode("IsCorrect").InnerText);
                surveyOption.CreatedDate     = Convert.ToDateTime(surveyOptionXmlNode.SelectSingleNode("CreatedDate").InnerText);
                surveyOption.CreatedByUserID = Convert.ToInt32(surveyOptionXmlNode.SelectSingleNode("CreatedByUserID").InnerText);
                if ((surveyOptionXmlNode.SelectSingleNode("LastModifiedDate") != null) && (!(String.IsNullOrEmpty(surveyOptionXmlNode.SelectSingleNode("LastModifiedDate").InnerText))))
                {
                    surveyOption.LastModifiedDate = Convert.ToDateTime(surveyOptionXmlNode.SelectSingleNode("LastModifiedDate").InnerText);
                }
                if ((surveyOptionXmlNode.SelectSingleNode("LastModifiedByUserID") != null) && (!(String.IsNullOrEmpty(surveyOptionXmlNode.SelectSingleNode("LastModifiedByUserID").InnerText))))
                {
                    surveyOption.LastModifiedByUserID = Convert.ToInt32(surveyOptionXmlNode.SelectSingleNode("LastModifiedByUserID").InnerText);
                }
            }
            return(surveyOption);
        }
예제 #2
0
        protected void UpdateAnswerButton_Click(object sender, EventArgs e)
        {
            Page.Validate("AnswerValidation");
            if (Page.IsValid)
            {
                LinkButton updateAnswerButton    = (LinkButton)sender;
                List <SurveyOptionsInfo> answers = Answers;
                if (answers == null)
                {
                    answers = new List <SurveyOptionsInfo>();
                }

                if (Request.Form["SurveyOptionID"] != null)
                {
                    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++;
                    }
                }

                if (SurveyOptionID == 0)
                {
                    MaxViewOrder = MaxViewOrder + 1;
                    SurveyOptionsInfo surveyOption = new SurveyOptionsInfo();
                    surveyOption.OptionName      = AnswerTextBox.Text;
                    surveyOption.IsCorrect       = CorrectAnswerCheckBox.Checked;
                    surveyOption.SurveyOptionID  = MaxViewOrder * (-1);
                    surveyOption.ViewOrder       = MaxViewOrder;
                    surveyOption.Votes           = 0;
                    surveyOption.CreatedByUserID = UserId;
                    surveyOption.CreatedDate     = DateTime.Now;
                    answers.Add(surveyOption);
                    answers.OrderBy(so => so.ViewOrder);
                }
                else
                {
                    SurveyOptionsInfo surveyOption = SurveyOption;
                    answers.Remove(answers.Find(so => so.SurveyOptionID == SurveyOptionID));
                    surveyOption.OptionName = AnswerTextBox.Text;
                    surveyOption.IsCorrect  = CorrectAnswerCheckBox.Checked;
                    answers.Add(surveyOption);
                    answers.OrderBy(so => so.ViewOrder);
                    SurveyOptionID             = 0;
                    SurveyOption               = null;
                    AddAnswerButton.Visible    = true;
                    UpdateAnswerButton.Visible = false;
                }
                Answers = answers;
                AnswersGrid.DataSource = Answers;
                AnswersGrid.DataBind();
                AnswerTextBox.Text            = String.Empty;
                CorrectAnswerCheckBox.Checked = false;
            }
        }
예제 #3
0
        protected void EditImage_Click(object sender, EventArgs e)
        {
            DnnImageButton    editImage    = (DnnImageButton)sender;
            SurveyOptionsInfo surveyOption = SurveyOptionsController.Get(Convert.ToInt32(editImage.CommandArgument));

            if (surveyOption != null)
            {
                SurveyOptionID = surveyOption.SurveyOptionID;
                SurveyOption   = surveyOption;

                AnswerTextBox.Text            = surveyOption.OptionName;
                CorrectAnswerCheckBox.Checked = surveyOption.IsCorrect;

                AddAnswerButton.Visible    = false;
                UpdateAnswerButton.Visible = true;
            }
        }
        public void ImportModule(int moduleID, string content, string version, int userID)
        {
            string[] versions = version.Split(new char[] { '.' });

            if (Convert.ToInt32(versions[0]) < 9)
            {
                // Old Xml data sructure by the original core module
                XmlNode surveysNode = Globals.GetContent(content, "surveys");
                foreach (XmlNode surveyNode in surveysNode)
                {
                    SurveysInfo survey = new SurveysInfo();
                    survey.SurveyID   = 0;
                    survey.ModuleID   = moduleID;
                    survey.Question   = surveyNode.SelectSingleNode("question").InnerText;
                    survey.ViewOrder  = Convert.ToInt32(surveyNode.SelectSingleNode("vieworder").InnerText);
                    survey.OptionType = (QuestionType)Convert.ToInt32(surveyNode.SelectSingleNode("optiontype").InnerText);

                    XmlNode surveyOptionsNode = surveyNode.SelectSingleNode("surveyoptions");
                    List <SurveyOptionsInfo> surveyOptions = new List <SurveyOptionsInfo>();
                    foreach (XmlNode surveyOptionNode in surveyOptionsNode)
                    {
                        SurveyOptionsInfo surveyOption = new SurveyOptionsInfo();
                        surveyOption.SurveyOptionID = 0;
                        surveyOption.OptionName     = surveyOptionNode.SelectSingleNode("optionname").InnerText;
                        surveyOption.IsCorrect      = Convert.ToBoolean(surveyOptionNode.SelectSingleNode("iscorrect").InnerText);
                        surveyOption.ViewOrder      = Convert.ToInt32(surveyOptionNode.SelectSingleNode("vieworder").InnerText);
                        surveyOptions.Add(surveyOption);
                    }
                    SurveysController.AddOrChange(survey, XmlDataProvider.SurveyOptionsToXml(surveyOptions), userID);
                }
            }
            else
            {
                XmlNode root         = Globals.GetContent(content, "Survey");
                string  exportString = root.SelectSingleNode("Surveys").OuterXml;
                exportString = exportString.Replace("[MODULE_ID]", moduleID.ToString()).Replace("[CREATED_DATE]", string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now)).Replace("[USER_ID]", userID.ToString());
                List <SurveysInfo> surveys = XmlDataProvider.SurveysFromXml(exportString);
                foreach (SurveysInfo survey in surveys)
                {
                    survey.SurveyID = 0;
                    survey.ModuleID = moduleID;
                    SurveysController.AddOrChange(survey, survey.SurveyOptionsXml, userID);
                }
            }
        }
예제 #5
0
        public static List <SurveyOptionsInfo> SurveyOptionsFromXml(string surveyOptionsXml)
        {
            List <SurveyOptionsInfo> surveyOptions = null;

            if ((!(string.IsNullOrEmpty(surveyOptionsXml))) && (surveyOptionsXml != "<SurveyOptions />"))
            {
                surveyOptions = new List <SurveyOptionsInfo>();
                XmlNode surveyOptionsXmlNode = Globals.GetContent(surveyOptionsXml, "SurveyOptions");

                foreach (XmlNode surveyOptionXmlNode in surveyOptionsXmlNode)
                {
                    SurveyOptionsInfo surveyOption = SurveyOptionFromXml(surveyOptionXmlNode.OuterXml);
                    if (surveyOption != null)
                    {
                        surveyOptions.Add(surveyOption);
                    }
                }
            }
            return(surveyOptions);
        }
예제 #6
0
        public static string SurveyOptionToXml(SurveyOptionsInfo surveyOption, bool forExport)
        {
            StringBuilder surveyOptionBuilder = new StringBuilder();

            if (surveyOption == null)
            {
                surveyOptionBuilder.Append("<SurveyOption />");
            }
            else
            {
                surveyOptionBuilder.Append("<SurveyOption>");
                surveyOptionBuilder.Append(string.Format("<SurveyOptionID>{0}</SurveyOptionID>", (forExport ? 0 : surveyOption.SurveyOptionID)));
                surveyOptionBuilder.Append(string.Format("<ViewOrder>{0}</ViewOrder>", surveyOption.ViewOrder));
                surveyOptionBuilder.Append(string.Format("<OptionName><![CDATA[{0}]]></OptionName>", surveyOption.OptionName));
                surveyOptionBuilder.Append(string.Format("<Votes>{0}</Votes>", (forExport ? 0 : surveyOption.Votes)));
                surveyOptionBuilder.Append(string.Format("<IsCorrect>{0}</IsCorrect>", surveyOption.IsCorrect));
                surveyOptionBuilder.Append(string.Format("<CreatedDate>{0}</CreatedDate>", (forExport ? "[CREATED_DATE]" : string.Format("{0:yyyy - MM - dd hh: mm: ss}", surveyOption.CreatedDate))));
                surveyOptionBuilder.Append(string.Format("<CreatedByUserID>{0}</CreatedByUserID>", (forExport ? "[USER_ID]" : surveyOption.CreatedByUserID.ToString())));
                if ((surveyOption.LastModifiedDate == null) || forExport)
                {
                    surveyOptionBuilder.Append("<LastModifiedDate />");
                }
                else
                {
                    surveyOptionBuilder.Append(string.Format("<LastModifiedDate>{0:yyyy-MM-dd hh:mm:ss}</LastModifiedDate>", surveyOption.LastModifiedDate.Value));
                }
                if ((surveyOption.LastModifiedByUserID == null) || forExport)
                {
                    surveyOptionBuilder.Append("<LastModifiedByUserID />");
                }
                else
                {
                    surveyOptionBuilder.Append(string.Format("<LastModifiedByUserID>{0}</LastModifiedByUserID>", surveyOption.LastModifiedByUserID.Value));
                }
                surveyOptionBuilder.Append("</SurveyOption>");
            }
            return(surveyOptionBuilder.ToString());
        }
예제 #7
0
 public static string SurveyOptionToXml(SurveyOptionsInfo surveyOption)
 {
     return(SurveyOptionToXml(surveyOption, false));
 }
예제 #8
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);
                }
            }
        }