예제 #1
0
        /// <summary>
        /// Sets the parameterss of the courses and adds them to the courses list.
        /// </summary>
        /// <param name="reader">The CsvReader.</param>
        /// <returns>courseList</returns>
        private static List <Course> parseRecordsForCourse(CsvHelper.CsvReader reader)
        {
            // make sure not at header or end of file
            List <Course> courseList = new List <Course>();
            Regex         rgx        = new Regex(@"(\S*,.*?)\s*\(\d*\)");
            Match         match;
            string        NewInstructor;

            while ((fileHasMoreRecords = reader.Read()) && courseHasMoreRecords(reader))
            {
                Course course = reader.GetRecord <Course>();
                course.SetAllDerivedProperties();
                NewInstructor = "";
                match         = rgx.Match(course.Instructor);
                while (match.Success)
                {
                    NewInstructor += match.Groups[1].Value + "; ";
                    match          = match.NextMatch();
                }
                if (NewInstructor != "")
                {
                    course.Instructor = NewInstructor.Substring(0, NewInstructor.Length - 2);
                }

                courseList.Add(course);                 //add course to course list.
            }

            return(courseList);
        }
예제 #2
0
        /// <summary>
        /// Search for the list of teachers when typing in text box.
        /// </summary>
        /// <param name="sender">A reference to the control/object that raised the event.</param>
        /// <param name="e">State information and event data associated with a routed event.</param>
        private void Teacher_Search_Click(object sender, RoutedEventArgs e)
        {
            string[]      multi = { "" };
            string        delim = "; ";
            List <string> listOfTeachers;

            listOfTeachers = new List <string>();
            List <string> tempDuplicates;

            tempDuplicates = new List <string>();
            List <string> listOfDistinctTeachers;

            listOfDistinctTeachers = new List <string>();
            output = new List <string>();

            ViewModel.CurrentTeacher = SuggestedTeacherlistBox.SelectedItems.ToString();

            Regex  rgx = new Regex(@"(\S*,.*?)\s*\(\d*\)");
            Match  match;
            string NewInstructor;

            NewInstructor = TeacherSearch.Text;
            ObservableCollection <Course> Courses = new ObservableCollection <Course>(ViewModel.CourseRepo.Courses);

            /*This for loop removes the (ID) at the end of each teacher's name, I only included it for testing on my branch*/
            /*Comment it out or remove it when merging back into the master*/
            foreach (var course in Courses)
            {
                NewInstructor = "";
                match         = rgx.Match(course.Instructor);
                while (match.Success)
                {
                    NewInstructor += match.Groups[1].Value + "; ";
                    match          = match.NextMatch();
                }
                if (NewInstructor != "")
                {
                    course.Instructor = NewInstructor.Substring(0, NewInstructor.Length - 2);
                }
            }

            /*Loop through the list of teachers and return the possible suggestions that match the input*/
            foreach (var course3 in Courses)
            {
                if (course3.Instructor.Contains(';') == false)
                {
                    listOfTeachers.Add(course3.Instructor);
                }
            }

            /*Collect all of the teachers names in the courses with multiple teachers*/
            foreach (var course4 in Courses)
            {
                if (course4.Instructor.Contains(';') == true)
                {
                    multi = Regex.Split(course4.Instructor, delim);
                    foreach (var d in multi)
                    {
                        tempDuplicates.Add(d);
                    }
                }
            }

            /*Sort and get all distinct teachers*/
            tempDuplicates.Sort();
            tempDuplicates = tempDuplicates.Distinct().ToList();

            /*If the global list of unique teachers doesn't contain the teacher then add it to the list*/
            /*This logic deals with the courses that have multiple teachers listed in the record*/
            foreach (var u in tempDuplicates)
            {
                if (listOfTeachers.Contains(u) == false)
                {
                    listOfTeachers.Add(u);
                }
            }

            listOfTeachers.Sort();
            listOfDistinctTeachers = listOfTeachers.Distinct().ToList(); //The distinct list of teachers in CourseRepo

            foreach (var v in listOfDistinctTeachers)
            {
                if (v.Contains(TeacherSearch.Text))
                {
                    output.Add(v);
                }
            }

            if (TeacherSearch.Text.Equals("") == true)
            {
                output = new List <string>();
                SuggestedTeacherlistBox.ItemsSource = output; // Dispay auto-suggested teacehrs
            }
            else
            {
                SuggestedTeacherlistBox.ItemsSource = output; // Dispay auto-suggested teacehrs
            }
        }