private void InitQuestions()
        {
            if (this.uSurvey == null)
                return;
            List<UDT.Question> uQs = DataPool.GetQuestionsBySurveyID(this.uSurvey.UID);
            uQs.ForEach((x) =>
            {
                Question Q = new Question(x);

                this.AddQuestion(Q);
            });
        }
        private void SetAnswers(string answer)
        {
            /// 評鑑做答,格式如下:
            /// <Answers>
            ///     <Question QuestionID="">
            ///         <Answer CaseID="" Score="3">尚可</Answer>
            ///         <Answer CaseID="123" Score="5">很滿意</Answer>
            ///     </Question>
            /// </Answers>
            ///
            XDocument xDocument = XDocument.Parse(answer, LoadOptions.None);
            IEnumerable<XElement> xElements = xDocument.Descendants("Question");
            foreach (XElement xElement in xElements)
            {
                string QuestionID = xElement.Attribute("QuestionID").Value;
                UDT.Question uQ = DataPool.GetUQuestionByID(QuestionID);
                Question Q = new Question(uQ);
                this.Questions.Add(Q);
                IEnumerable<XElement> xAnswers = xElement.Descendants("Answer");
                foreach(XElement xAnswer in xAnswers)
                {
                    Answer Answer = new Answer();

                    if (!string.IsNullOrEmpty(xAnswer.Attribute("CaseID").Value))
                    {
                        UDT.Case uCase = DataPool.GetUCase(xAnswer.Attribute("CaseID").Value);
                        Case Case = new Case(uCase);
                        Answer.Case = Case;
                    }
                    Answer.Score = xAnswer.Attribute("Score").Value;
                    Answer.Content = xAnswer.Value;

                    Q.AddAnswer(Answer);
                }
            }
        }
 protected internal void AddQuestion(Question Q)
 {
     this.Questions.Add(Q);
 }
        private string GetSingleChoiceNoneCaseString(Question q)
        {
            List<QuestionOption> Qos = q.QuestionOptions;
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format(@"<Question ID=""{6}"" No=""{0}"" Content=""{1}"" Type=""{2}"" IsSelfAssessment=""{3}"" IsCase=""{4}"" Score=""{5}"">", q.No, HttpUtility.HtmlEncode(q.Content), q.uQuestion.Type, q.uQuestion.IsSelfAssessment ? "是" : "否", q.uQuestion.IsCase ? "是" : "否", q.Score.HasValue ? q.Score.Value.ToString() : string.Empty, q.uQuestion.UID));
            foreach (QuestionOption Qo in Qos)
                sb.Append(string.Format(@"<Option ID=""{3}"" No=""{0}"" Content=""{1}"" AnswerCount=""{2}"" />", Qo.No, HttpUtility.HtmlEncode(Qo.Content), Qo.AnswerCount, Qo.uQuestionOption.UID));

            return sb.Append("</Question>").ToString();
        }
        private string GetEssayString()
        {
            StringBuilder sb = new StringBuilder();

            //if (this.Replys.Count == 0)
            //    return string.Empty;

            List<UDT.Question> oQs = DataPool.GetQuestionsBySurveyID(this.Survey.uSurvey.UID).Where(x => x.Type == "問答題").ToList();
            List<Question> Qs = new List<Question>();
            this.Replys.ForEach((y) => Qs.AddRange(y.Questions.Where(x=>x.uQuestion.Type == "問答題")));
            Qs = Qs.OrderBy(x=>x.No).ToList();
            Dictionary<string, List<Question>> dicQuestions = new Dictionary<string,List<Question>>();
            Qs.ForEach((x) =>
            {
                if (!dicQuestions.ContainsKey(x.uQuestion.UID))
                    dicQuestions.Add(x.uQuestion.UID, new List<Question>());

                dicQuestions[x.uQuestion.UID].Add(x);
            });
            oQs.ForEach((x) =>
            {
                if (!dicQuestions.ContainsKey(x.UID))
                    dicQuestions.Add(x.UID, new List<Question>());

                Question q = new Question(x);
                dicQuestions[x.UID].Add(q);
            });

            foreach(string key in dicQuestions.Keys.OrderBy(x=>x))
            {
                Question q = dicQuestions[key].ElementAt(0);
                sb.Append(string.Format(@"<Question ID=""{5}"" No=""{0}"" Content=""{1}"" Type=""{2}"" IsSelfAssessment=""{3}"" IsCase=""{4}"">", q.uQuestion.DisplayOrder, HttpUtility.HtmlEncode(q.uQuestion.Title), q.uQuestion.Type, q.uQuestion.IsSelfAssessment ? "是" : "否", q.uQuestion.IsCase ? "是" : "否", q.uQuestion.UID));
                sb.Append("<Answers>");
                List<Answer> Answers = new List<Answer>();
                dicQuestions[key].ForEach((x) =>
                {
                    if (x.Answers != null)
                        Answers.AddRange(x.Answers);
                });
                foreach (Answer answer in Answers)
                {
                    sb.Append(string.Format(@"<Answer>{0}</Answer>", HttpUtility.HtmlEncode(answer.Score)));
                }
                sb.Append("</Answers></Question>");
            }
            return sb.ToString();
        }
        private string GetCaseString(Question q)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format(@"<Question ID=""{5}"" No=""{0}"" Content=""{1}"" Type=""{2}"" IsSelfAssessment=""{3}"" IsCase=""{4}"">", q.No, HttpUtility.HtmlEncode(q.Content), q.uQuestion.Type, q.uQuestion.IsSelfAssessment ? "是" : "否", q.uQuestion.IsCase ? "是" : "否", q.uQuestion.UID));

            List<Case> Cases = q.Cases;
            if (Cases.Count == 0)
                return sb.Append("</Question>").ToString();

            foreach (Case cazz in Cases)
            {
                if (cazz.uCase == null)
                    continue;

                sb.Append(string.Format(@"<Case ID=""{0}"" Content=""{1}"" Score=""{2}"">", cazz.uCase.UID, HttpUtility.HtmlEncode(cazz.Content), cazz.Score.HasValue ? cazz.Score.Value.ToString() : string.Empty));
                List<QuestionOption> CQos = cazz.GetQuestionOptions();
                foreach (QuestionOption Qo in CQos)
                    sb.Append(string.Format(@"<Option ID=""{3}"" No=""{0}"" Content=""{1}"" AnswerCount=""{2}"" />", Qo.No, HttpUtility.HtmlEncode(Qo.Content), Qo.AnswerCount, Qo.uQuestionOption.UID));

                sb.Append("</Case>");
            }

            return sb.Append("</Question>").ToString();
        }