private static int SortCoursesByLength(Course x, Course y)
 {
     if (x.NumberOfBlocks > y.NumberOfBlocks)
         return -1;
     if (x.NumberOfBlocks < y.NumberOfBlocks)
         return +1;
     return 0;
 }
        public TimetableData(Block[] blocks, Course[] courses, Lecturer[] lecturers, Room[] rooms, Group[] groups)
            : base()
        {
            this.Blocks = blocks;
            this.Courses = courses;
            this.Lecturers = lecturers;
            this.Rooms = rooms;
            this.Groups = groups;

            Array.Sort(courses, SortCoursesByLength);
        }
示例#3
0
        private static void Export(short[, ,] dataToExport, Block[] blocks, Course[] courses, string title, string filePath)
        {
            //output[col,row]
            string[,] output = new string[dataToExport.GetLength(1) + 1, dataToExport.GetLength(2) + 2];

            //Day/Block-frame for the data
            output[0, 0] = title;
            for (int day = 0; day < dataToExport.GetLength(1); day++)
            {
                output[day + 1, 1] = Enum.GetName(typeof(DayOfWeek), day + 1);
            }
            for (int block = 0; block < dataToExport.GetLength(2); block++)
            {
                output[0, block] = blocks[block].Start.ToShortTimeString() + " - " + blocks[block].End.ToShortTimeString();
            }

            //data
            for (int column = 1; column < dataToExport.GetLength(1) + 1; column++)
            {
                for (int row = 2; row < dataToExport.GetLength(2) + 2; row++)
                {

                }
            }

            //string[][] output = new string[][]{  
            //        new string[]{"Col 1 Row 1", "Col 2 Row 1", "Col 3 Row 1"},  
            //        new string[]{"Col1 Row 2", "Col2 Row 2", "Col3 Row 2"}  
            //    };


            StringBuilder sb = new StringBuilder();
            for (int column = 0; column < output.GetLength(0); column++)
            {
                for (int row = 0; row < output.GetLength(1); row++)
                {
                    sb.Append("," + output[column, row]);
                }
                sb.AppendLine();
                //sb.AppendLine(string.Join(",", output[column]));
            }
            File.WriteAllText(filePath, sb.ToString());
        }
        private static void AppendCourses(Course[] courses, StringBuilder output)
        {
            Dictionary<Course, short> coursesDict = new Dictionary<Course, short>();
            foreach (Course c in courses)
            {
                Course listedCourse = null;
                if (coursesDict.Keys.Count > 0)
                {
                    foreach (Course k in coursesDict.Keys)
                    {
                        if (k.Id.Equals(c.Id))
                        {
                            listedCourse = k;
                            break;
                        }
                    }
                }
                if (listedCourse == null)
                    coursesDict.Add(c, 1);
                else
                    coursesDict[listedCourse]++;
            }

            output.Append("<courses>");
            foreach (Course c in coursesDict.Keys)
            {
                output.Append("<course cId=\"" + c.Id + "\"");
                output.Append(" gId=\"" + c.Group.Id + "\"");
                output.Append(" repeatsPerWeek=\"" + coursesDict[c] + "\"");
                output.Append(" numberOfBlocks=\"" + c.NumberOfBlocks + "\"");
                output.Append(" needsLab=\"" + c.NeedsLab + "\"");
                output.Append(" name=\"" + c.Name + "\"");
                output.Append(" isDummy=\"" + c.IsDummy + "\"");
                if (c.RoomPreference != null)
                    output.Append(" roomPreference=\"" + c.RoomPreference + "\"");
                for (int i = 0; i < c.Lecturers.Length; i++)
                {
                    output.Append(" lId" + i + "=\"" + c.Lecturers[i].Id + "\"");
                }
                output.Append("/>");
            }
            output.Append("</courses>");
        }
 private void AddCourses(CourseController CourseContext, Course[] courses)
 {
     foreach (Course course in courses)
     {
         bool isListed = false;
         foreach (Course storedCourse in CourseContext.Repetitions.Keys)
         {
             if (storedCourse.Id.Equals(course.Id))
             {
                 isListed = true;
                 CourseContext.Repetitions[storedCourse]++;
                 break;
             }
         }
         if (!isListed)
         {
             CourseContext.CourseList.Add(course);
             CourseContext.Repetitions.Add(course, 1);
         }
     }
 }
 internal Course[] GetCourseExportArray()
 {
     List<Course> cList = new List<Course>();
     foreach (var course in CourseList)
     {
         for (int i = 0; i < Repetitions[course]; i++)
         {
             Course c = new Course(course.Id, course.Name, course.Lecturers, course.RoomPreference,
                 course.Group, course.NeedsLab, course.IsDummy, course.NumberOfBlocks);
             cList.Add(c);
         }
     }
     return cList.ToArray();
 }
        public override void New()
        {
            if (!DataIsValid())
                return;

            Course newCourse = new Course();

            if (HasPreference)
                newCourse.RoomPreference = RoomPreferenceList[SelectedRoomPreferenceIndex];

            if (!HasSecondLecturer)
                newCourse.Lecturers = new Lecturer[] { LecturerList[SelectedLecturer1Index] };
            else if (SelectedLecturer2Index > 0)
                newCourse.Lecturers = new Lecturer[] { LecturerList[SelectedLecturer1Index], LecturerList[SelectedLecturer2Index] };

            newCourse.Group = GroupList[SelectedGroupIndex];
            newCourse.NumberOfBlocks = BlockCount;

            if (!Repetitions.ContainsKey(newCourse))
                Repetitions.Add(newCourse, RepetitionCount);

            newCourse.Name = CourseName;
            newCourse.Id = CourseId;

            newCourse.NeedsLab = NeedsLab;
            newCourse.IsDummy = IsDummy;

            CourseList.Add(newCourse);
        }