private void btn_addDay_Click(object sender, EventArgs e) { Day newDay = new Day("New Day"); TT.Week.Add(newDay); //Add Day RefreshDayList(); }
/// <summary> /// Load a file /// </summary> /// <param name="filename">The filename to read.</param> /// <returns>Read successfully.</returns> public bool Load(string filename) { bool error = false; FileStream fileStream = null; BinaryReader reader = null; try { fileStream = new FileStream(filename, FileMode.Open); reader = new BinaryReader(fileStream); if (reader.ReadString() != "TLF") throw new Exception("The file loaded isn't a TT file."); finalised = reader.ReadBoolean(); int numberOfYears = reader.ReadInt32(); for (int i = 0; i < numberOfYears; i++) { YearGroup thisYear = new YearGroup(reader.ReadString()); int numberOfForms = reader.ReadInt32(); for (int j = 0; j < numberOfForms; j++) { FormClass thisForm = new FormClass(reader.ReadString()); thisYear.Forms.Add(thisForm); } this.Years.Add(thisYear); } int numberOfDays = reader.ReadInt32(); byte identifier = 0; for (int i = 0; i < numberOfDays; i++) { Day newDay = new Day(reader.ReadString()); int numberOfPeriods = reader.ReadInt32(); for (int j = 0; j < numberOfPeriods; j++) { newDay.AddPeriod(reader.ReadString(), reader.ReadString()); identifier++; } this.Week.Add(newDay); } int numberOfRooms = reader.ReadInt32(); for (int i = 0; i < numberOfRooms; i++) { Room newRoom = new Room(reader.ReadString()); Rooms.Add(newRoom); } int numberOfTeachers = reader.ReadInt32(); for (int i = 0; i < numberOfTeachers; i++) { Teacher newTeacher = new Teacher(reader.ReadString(), reader.ReadString()); Staff.Add(newTeacher); } int numberOfSubjects = reader.ReadInt32(); for (int i = 0; i < numberOfSubjects; i++) { Subject newSubject = new Subject(reader.ReadString(), reader.ReadString()); Subjects.Add(newSubject); } //start writing lessons if (finalised) Finalise(); //finalise the timetable, so that we won't crash the program. for (int dayptr = 0; dayptr < Week.Count; dayptr++) for (int periodptr = 0; periodptr < Week[dayptr].PeriodsInDay.Count; periodptr++) for (int yearptr = 0; yearptr < Years.Count; yearptr++) for (int formptr = 0; formptr < Years[yearptr].Forms.Count; formptr++) { if (reader.ReadBoolean() == true) { //lesson is present, so read it. Lesson newLesson = new Lesson(reader); int indexOfRoom = GetIndexOfRoom(newLesson.RoomCode); int indexOfStaff = GetIndexOfStaff(newLesson.TeacherAbbreviation); mainTT[dayptr][periodptr][yearptr][formptr] = newLesson; roomTT[dayptr][periodptr][indexOfRoom] = newLesson; staffTT[dayptr][periodptr][indexOfStaff] = newLesson; } } } catch (Exception ex) { error = true; } finally { if (reader != null) reader.Close(); if (fileStream != null) fileStream.Close(); } return !error; }