Example #1
0
 //Check if group contains practice
 public bool ContainsPractice(CourseGroup cg)
 {
     foreach (var c in cg.coursesInGroup)
     {
         if (c.OccupationDescription == "תרגול")
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
        //Check if selected course appropriate with previous selected courses
        public bool CheckCourse(CourseGroup cg, List <CourseGroup> stack)
        {
            foreach (var c in cg.coursesInGroup)
            {
                foreach (var group in stack)
                {
                    foreach (var course in group.coursesInGroup)
                    {
                        if (c.Day == course.Day && ((c.StartHour >= course.StartHour && c.StartHour <= course.EndHour) ||
                                                    (c.EndHour >= course.StartHour && c.EndHour <= course.EndHour)))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Example #3
0
        //Arrange all courses by SubjectCode
        public List <List <CourseGroup> > ArrangeBySubjectCode(List <List <CoursesDetails> > allCourses)
        {
            List <List <CourseGroup> > CoursesByNameAndGroup = new List <List <CourseGroup> >();

            for (int i = 0; i < allCourses.Count(); i++)
            {
                List <CourseGroup> CourseGroup = new List <CourseGroup>();
                for (int j = 0; j < allCourses[i].Count(); j++)
                {
                    var         Contains = false;
                    CourseGroup cg       = new CourseGroup();
                    cg.coursesInGroup.Add(allCourses[i][j]);
                    var CourseCode = allCourses[i][j].GroupCode;
                    foreach (var l in CourseGroup)
                    {
                        if (l.coursesInGroup[0].GroupCode == CourseCode)
                        {
                            Contains = true;
                        }
                    }
                    for (int k = j + 1; k < allCourses[i].Count() && !Contains; k++)
                    {
                        var CurrentCourseCode = allCourses[i][k].GroupCode;
                        if (CurrentCourseCode != CourseCode)
                        {
                            break;
                        }
                        else
                        {
                            cg.coursesInGroup.Add(allCourses[i][k]);
                        }
                    }
                    if (!Contains)
                    {
                        CourseGroup.Add(cg);
                    }
                }
                CoursesByNameAndGroup.Add(CourseGroup);
            }
            CoursesByNameAndGroup.Sort((a, b) => a.Count().CompareTo(b.Count()));
            //Split courses with 2 practice
            foreach (var group in CoursesByNameAndGroup)
            {
                foreach (var cg in group.ToList())
                {
                    int counter = 0;
                    foreach (var c in cg.coursesInGroup)
                    {
                        if (c.OccupationDescription == "תרגול")
                        {
                            counter++;
                        }
                    }
                    if (counter > 1)
                    {
                        for (int i = 0; i < counter; i++)
                        {
                            var newGroup = new CourseGroup();
                            foreach (var c in cg.coursesInGroup.ToList())
                            {
                                if (c.OccupationDescription == "סופי-הרצאה")
                                {
                                    newGroup.coursesInGroup.Add(c);
                                }
                                else if (c.OccupationDescription == "תרגול" && !ContainsPractice(newGroup))
                                {
                                    newGroup.coursesInGroup.Add(c);
                                    cg.coursesInGroup.Remove(c);
                                }
                            }
                            group.Add(newGroup);
                        }
                        group.Remove(cg);
                    }
                }
            }

            //Set Color for each CourseGroup
            Random randomGen = new Random();

            Colors[]      names          = (Colors[])Enum.GetValues(typeof(Colors));
            List <Colors> SelectedColors = new List <Colors>();

            foreach (var Group in CoursesByNameAndGroup)
            {
                Colors randomColorName = names[randomGen.Next(names.Length)];
                while (SelectedColors.Contains(randomColorName))
                {
                    randomColorName = names[randomGen.Next(names.Length)];
                }
                foreach (var cg in Group)
                {
                    SelectedColors.Add(randomColorName);
                    foreach (var c in cg.coursesInGroup)
                    {
                        c.Color = randomColorName.ToString();
                    }
                }
            }
            return(CoursesByNameAndGroup);
        }