示例#1
0
 public void AddSelection(SurveyQuestionAnswer selection)
 {
     this.Selections.Add(selection);
 }
示例#2
0
        private void ParseQuestionAnaswers(string line, SurveyQuestion question, int question_cnt)
        {
            try
            {
                bool     hasError         = false;
                string[] stringSeparators = new string[] { "  " };
                if (question != null)
                {
                    string        pattern = "[a-z]";
                    List <string> list    = new List <string>();

                    var matchCollection = Regex.Matches(line, pattern);

                    int previousIndex = 0;
                    foreach (Match m in matchCollection)
                    {
                        if (m.Index > previousIndex)
                        {
                            list.Add(line.Substring(previousIndex, m.Index - previousIndex));
                        }

                        previousIndex = m.Index;
                    }

                    if (previousIndex < line.Length - 1)
                    {
                        list.Add(line.Substring(previousIndex));
                    }

                    for (int i = 0; i < list.Count; i++)
                    {
                        string symbol  = list[i].Substring(0, 1).Trim();
                        string content = list[i].Substring(1);
                        if (content.StartsWith("."))
                        {
                            content = content.Substring(1).Trim();
                        }

                        SurveyQuestionAnswer selection = new SurveyQuestionAnswer();
                        selection.AnswerSymbol  = symbol;
                        selection.AnswerContent = content.Trim();

                        if (this.answerList[question_cnt].Contains(symbol))
                        {
                            selection.Is_Answer = true;
                        }
                        else
                        {
                            selection.Is_Answer = false;
                        }

                        question.AddSelection(selection);

                        if (!Regex.IsMatch(list[i], "^[a-z]"))
                        {
                            hasError = true;
                        }
                    }

                    if (question_cnt < this.categoryList.Count)
                    {
                        question.Category = this.categoryList[question_cnt].Category;
                        question.Books    = new List <string>(this.categoryList[question_cnt].Books);
                    }

                    if (hasError)
                    {
                        this.errorText = this.errorText + "\n" + line;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }