Пример #1
0
        //Tìm danh sách các bài luyện tập của 1 bài học dựa vào course id và tên bài học
        public static List <DTO_LessonSection> SearchSections(XmlDocument xd, int courseId, string lessonName)
        {
            List <DTO_LessonSection> sections = new List <DTO_LessonSection>();

            //TODO: Chuyển sang dùng id
            XmlNodeList coursesNodeList = xd.GetElementsByTagName("Course");  // Tìm danh sách các khoá học

            foreach (XmlElement courseNode in coursesNodeList)
            {
                if (courseNode.GetAttribute("Id") == courseId.ToString())                    // Tìm khoá học có id trùng với courseId
                {
                    XmlNodeList lessonsNodeList = courseNode.GetElementsByTagName("Lesson"); // Tìm danh sách các bài học trong khoá học
                    foreach (XmlElement lessonNode in lessonsNodeList)
                    {
                        if (lessonNode.GetAttribute("Name") == lessonName)                             // Tìm bài học có tên là lessonName
                        {
                            XmlNodeList sectionsNodeList = lessonNode.GetElementsByTagName("Section"); // Tìm danh sách các bài luyện tập của bài học
                            foreach (XmlElement sectionNode in sectionsNodeList)                       //Thêm các bài luyện tập vào List sections
                            {
                                DTO_LessonSection section = new DTO_LessonSection();

                                section.Name   = sectionNode.GetAttribute("Name");
                                section.Type   = sectionNode.GetElementsByTagName("Type")[0].InnerText;
                                section.Time   = int.Parse(sectionNode.GetElementsByTagName("Time")[0].InnerText);
                                section.Detail = sectionNode.GetElementsByTagName("Detail")[0].InnerText;
                                sections.Add(section);
                            }
                        }
                    }
                }
            }

            return(sections);
        }
Пример #2
0
        static public DTO_Exercise CreateExercise(DTO_LessonSection section)
        {
            DTO_Exercise exercise = new DTO_Exercise();

            exercise.Title        = section.Name;
            exercise.Time         = section.Time;
            exercise.ExerciseType = section.Type;
            exercise.Timeleft     = section.Time;
            exercise.IsLesson     = true;

            exercise.ExerciseText = DAO_LessonSection.ReadExerciseDetailFromSection(section);

            return(exercise);
        }
Пример #3
0
        public static List <string> ReadExerciseDetailFromSection(DTO_LessonSection section) //Đọc nội dung file text trong detail
        {
            string exerciseFilePath = Path.Combine(Environment.CurrentDirectory, "Database", "Lessons", section.Detail);

            List <string> detail = new List <string>();
            string        line   = "";

            StreamReader reader = new StreamReader(exerciseFilePath);

            while (reader.Peek() >= 0) //Read to End-of-file
            {
                line = reader.ReadLine();

                if (line != "")
                {
                    detail.Add(line);
                }
            }

            reader.Close();
            return(detail);
        }