Beispiel #1
0
        private void cb_year_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cb_year.Text == "")
            {
                return;                     //probably a faster way of doing this.
            }
            if (currentTT == null)
            {
                return;
            }
            cb_form.Items.Clear();

            YearGroup yearToDisplay = (YearGroup)cb_year.SelectedItem;

            foreach (FormClass f in yearToDisplay.Forms)
            {
                cb_form.Items.Add(f);
            }

            cb_form.SelectedIndex = 0;
            if (displayedItem == null)
            {
                return;
            }
            if (displayedItem.YearIndex == cb_year.SelectedIndex)
            {
                return;
            }
            currentTT.MoveYears(displayedItem, Convert.ToByte(cb_year.SelectedIndex));
            RefreshViews();
        }
Beispiel #2
0
        private void DrawYear(Graphics G, int Width, int Height, int cellWidth, int cellHeight, int marginTop, int marginLeft, int YearIndex)
        {
            int       col  = 2 * cellWidth;
            YearGroup year = currentTT.Years[YearIndex];

            foreach (FormClass fc in year.Forms)
            {
                G.DrawRectangle(Pens.Black, col + marginLeft, marginTop, cellWidth, cellHeight);
                G.DrawString(fc.FormName, new Font("Segoe UI", 12), Brushes.Black, col + marginLeft, marginTop);
                col += cellWidth;
            }


            int row = cellHeight;

            foreach (Day schoolDay in currentTT.Week)
            {
                G.DrawRectangle(Pens.Black, marginLeft, row + marginTop, cellWidth, cellHeight);
                G.DrawString(schoolDay.DayName, new Font("Segoe UI", 12), Brushes.Black, marginLeft, row + marginTop);
                //G.FillRectangle(Brushes.SkyBlue, schoolDay.dayBounds);
                foreach (Period singlePeriod in schoolDay.PeriodsInDay)
                {
                    G.DrawRectangle(Pens.Black, marginLeft + cellWidth, row + marginTop, cellWidth, cellHeight);
                    G.DrawString(singlePeriod.PeriodDisplay, new Font("Segoe UI", 12), Brushes.Black, marginLeft + cellWidth, row + marginTop);
                    row += cellHeight;
                    // G.FillRectangle(Brushes.Purple,singlePeriod.periodBounds);
                }
            }

            bool printInvisible = ck_printInvisible.Checked;

            if (!currentTT.IsFinalised())
            {
                return;
            }
            //int xCoord =  cellWidth + MarginLeft;
            int yCoord = marginTop;

            for (int dayIndex = 0; dayIndex < currentTT.Week.Count; dayIndex++)
            {
                for (int periodIndex = 0; periodIndex < currentTT.Week[dayIndex].PeriodsInDay.Count; periodIndex++)
                {
                    int xCoord = 2 * cellWidth + marginLeft;
                    yCoord += cellHeight;

                    for (int formIndex = 0; formIndex < currentTT.Years[YearIndex].Forms.Count; formIndex++)
                    {
                        Lesson obj = currentTT.mainTT[dayIndex][periodIndex][YearIndex][formIndex];
                        if ((obj != null) && (!obj.invisible | (obj.invisible & printInvisible)))
                        {
                            G.DrawRectangle(Pens.Black, xCoord, yCoord, cellWidth, cellHeight);
                            G.DrawString(currentTT.mainTT[dayIndex][periodIndex][YearIndex][formIndex].ToString(), new Font("Segoe UI", 12), Brushes.Black, xCoord, yCoord);
                        }
                        xCoord += cellWidth;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the number of visible forms
        /// </summary>
        /// <param name="year">The year group to find the number of visible forms for.</param>
        /// <returns>Number of Visible Forms (integer)</returns>
        public int numberOfVisibleForms(YearGroup year)
        {
            int number = 0;

            foreach (FormClass form in year.Forms)
            {
                if (form.visible)
                {
                    number++;
                }
            }
            return(number);
        }
Beispiel #4
0
        private void btn_addDay_Click(object sender, EventArgs e)
        {
            if (TT.Years.Count() == 256)
            {
                MessageBox.Show("Operation couldn't be completed, because you cannot have more than 256 years.");
                return;
            }

            YearGroup newYear = new YearGroup("Year X");

            TT.Years.Add(newYear);
            //Add Day

            RefreshDayList();
        }
Beispiel #5
0
        private void btn_addDay_Click(object sender, EventArgs e)
        {
            if (TT.Years.Count() == 256)
            {
                MessageBox.Show("Operation couldn't be completed, because you cannot have more than 256 years.");
                return;
            }



            YearGroup newYear = new YearGroup("Year X");

            TT.Years.Add(newYear);
            //Add Day

            RefreshDayList();
        }
Beispiel #6
0
        private void list_days_SelectedIndexChanged(object sender, EventArgs e)
        {
            list_periods.Items.Clear(); //clear the period list, ready for displaying new ones.
            if (list_days.SelectedItem == null)
            {
                return;
            }
            YearGroup selectedYear = (YearGroup)list_days.SelectedItem;

            tb_dayName.Text = selectedYear.YearName;



            //display selected periods for that particular day.


            foreach (FormClass p in selectedYear.Forms)
            {
                ListViewItem lvi = new ListViewItem(p.ToString());
                list_periods.Items.Add(lvi);
            }
        }
Beispiel #7
0
        private void btn_addPeriod_Click(object sender, EventArgs e)
        {
            //Add Period

            YearGroup selectedYear = (YearGroup)list_days.SelectedItem;



            if (selectedYear == null)
            {
                return;
            }
            if (selectedYear.Forms.Count() == 256)
            {
                MessageBox.Show("Operation not allowed, as you cannot have more than 256 forms per year.");
                return;
            }
            selectedYear.AddForm("Form");
            ListViewItem lvi = new ListViewItem(selectedYear.GetBackForm().ToString());

            //THIS IS INEFFICIENT, SO YOU SHOULD WRITE SOME MORE FUNCTIONS IN THE CLASS!!!!!
            list_periods.Items.Add(lvi);
            list_periods.Refresh();
        }
Beispiel #8
0
        /// <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);
        }
Beispiel #9
0
        private void tb_dayName_TextChanged(object sender, EventArgs e)
        {
            YearGroup selectedYear = (YearGroup)list_days.SelectedItem;

            selectedYear.YearName = tb_dayName.Text;
        }
Beispiel #10
0
 /// <summary>
 /// Gets the number of visible forms
 /// </summary>
 /// <param name="year">The year group to find the number of visible forms for.</param>
 /// <returns>Number of Visible Forms (integer)</returns>
 public int numberOfVisibleForms(YearGroup year)
 {
     int number = 0;
     foreach(FormClass form in year.Forms)
     {
         if (form.visible) number++;
     }
     return number;
 }
Beispiel #11
0
        /// <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;
        }