Example #1
0
        /// <summary>
        /// Adds a lesson to the timetable
        /// </summary>
        /// <param name="dayIndex">The index of the day needed.</param>
        /// <param name="periodIndex">The index of the period needed.</param>
        /// <param name="periodLength">The number of periods the lesson covers.</param>
        /// <param name="subjectCode">The subject code associated with the type of subject.</param>
        /// <param name="teacherCode">The teacher code associated with the teacher name.</param>
        /// <param name="roomName">The room name.</param>
        /// <param name="yearIndex">The index of the year group, for the lesson.</param>
        /// <param name="formIndex">The index of the form in the year group specified.</param>
        /// <param name="homeworkAmount">The amount of homework that is expected to be set in the lesson.</param>
        /// <returns>Whether the lesson addition has been successful.</returns>
        public bool AddLesson(byte dayIndex, byte periodIndex, byte periodLength, string subjectCode, string teacherCode, string roomName, byte yearIndex, byte formIndex,byte homeworkAmount, bool locked, bool invisible)
        {
            int staffIndex = GetIndexOfStaff(teacherCode);
            int roomIndex = GetIndexOfRoom(roomName);

            if (roomIndex < 0) return false;
            if (staffIndex < 0) return false;
            if (!finalised) return false;
            if ((subjectCode == "") || (teacherCode == "") || (roomName == "")) return false;
            if (dayIndex >= this.Week.Count) return false;
            if (periodIndex + periodLength - 1 >= this.Week[dayIndex].PeriodsInDay.Count) return false;
            //check to see whether any lessons currently exist in that space. This will therefore check for clashes.
            if (roomTT[dayIndex][periodIndex][roomIndex] != null) return false;
            if (staffTT[dayIndex][periodIndex][staffIndex] != null) return false;
            if (mainTT[dayIndex][periodIndex][yearIndex][formIndex] != null) return false;

            Lesson newLesson = new Lesson(teacherCode, subjectCode, roomName, dayIndex, periodIndex,homeworkAmount,locked,invisible,formIndex,yearIndex);

            for (int periodptr = 0; periodptr < periodLength; periodptr++)
            {
                Lesson l = newLesson.Clone();
                l.PeriodIndex = Convert.ToByte(periodIndex + periodptr);

                mainTT[dayIndex][periodIndex+periodptr][yearIndex][formIndex] = l;
                staffTT[dayIndex][periodIndex+periodptr][staffIndex] = l;
                roomTT[dayIndex][periodIndex+periodptr][roomIndex] = l;
            }
            return true;
        }
Example #2
0
 public void AddNodeToUndo(Event task, int A, int B,Lesson lessonToUndo,bool undoEventAfter,bool redoEventAfter)
 {
     undoRedoEvent eventToAdd = new undoRedoEvent(task, A, B,lessonToUndo,undoEventAfter,redoEventAfter);
     if (redoStack.Count != 0) redoStack.Clear(); //when undoing, this will automatically get rid of all redo values.
     undoStack.Push(eventToAdd);
     undoToolStripMenuItem.Enabled = undoStack.Count > 1;
     redoToolStripMenuItem.Enabled = redoStack.Count > 1;
 }
Example #3
0
        private void tabControl1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F1:
                    tabControl1.SelectTab(0);
                    break;
                case Keys.F2:
                    tabControl1.SelectTab(1);
                    break;
                case Keys.F3:
                    tabControl1.SelectTab(2);
                    break;
                case Keys.F4:
                    tabControl1.SelectTab(3);
                    break;
                case Keys.F5:
                    tabControl1.SelectedTab.Refresh();
                    break;

                case Keys.Up:
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    int DayIndex = displayedItem.DayIndex;
                    int PeriodIndex = displayedItem.PeriodIndex;
                    int YearIndex = displayedItem.YearIndex;
                    int FormIndex = displayedItem.FormIndex;
                    do
                    {
                        if ((PeriodIndex == 0) && (DayIndex != 0)) {
                            DayIndex--;
                            PeriodIndex = currentTT.Week[DayIndex].PeriodsInDay.Count;
                        }
                        else if ((PeriodIndex == 0)) return;
                        PeriodIndex--;
                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                case Keys.Down:
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((PeriodIndex == currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (DayIndex != currentTT.Week.Count - 1)) {
                            DayIndex++;
                            PeriodIndex = -1;
                        }
                        else if ((PeriodIndex == currentTT.Week[DayIndex].PeriodsInDay.Count - 1)) return;
                        PeriodIndex++;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                case Keys.Left:
                    e.Handled = true; //this escapes the automatic movement of tab pages, which can be annoying.

                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((FormIndex == 0) && (YearIndex != 0)) {
                            YearIndex--;
                            FormIndex = currentTT.Years[YearIndex].Forms.Count;
                        }
                        else if ((YearIndex == 0) && (FormIndex == 0)) return;
                        FormIndex--;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;

                case Keys.Right:
                    e.Handled = true;
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((FormIndex == currentTT.Years[YearIndex].Forms.Count - 1) && (YearIndex != currentTT.Years.Count - 1)) {
                            YearIndex++;
                            FormIndex = -1;
                        }
                        else if ((YearIndex == currentTT.Years.Count - 1) && (FormIndex == currentTT.Years[YearIndex].Forms.Count - 1)) return;
                        FormIndex++;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];
                        //MessageBox.Show("RIGHT!!!");

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                case Keys.Delete:
                    if (displayedItem == null)
                    {
                        MessageBox.Show("There is no item selected for deletion.", "Delete Lesson");
                        return;
                    }
                    if (MessageBox.Show("Are you sure you want to delete the selected lesson: " + displayedItem.ToString() + "?", "Delete Lesson", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        currentTT.DeleteLesson(displayedItem);
                        RefreshViews();
                    }
                    break;
                default:
                    break;
            }
        }
Example #4
0
 public Lesson Clone()
 {
     Lesson clonedObj = new Lesson(TeacherAbbreviation, SubjectAbbreviation, RoomCode, DayIndex, PeriodIndex, homeworkAmount, locked, invisible, FormIndex, YearIndex);
     return clonedObj;
 }
Example #5
0
        private void pb_staffView_MouseClick(object sender, MouseEventArgs e)
        {
            //After adding the new feature, please be sure to update the system maintenance!!!

            if (sw != null) sw.Stop();
            if (displayedItem != null)
            {
                displayedItem.selected = false;
                btn_locked.Checked = false;
                btn_invisible.Checked = false;
            }

            //Console.WriteLine("");
            //Console.WriteLine("Click detected: ");
            Rectangle cursor = new Rectangle(e.X, e.Y, 1, 1);

            int DayIndex = -1;

            do
            {
                DayIndex++;
            } while ((DayIndex < currentTT.Week.Count - 1) && (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)));
            //Console.WriteLine("DayIndex: " + DayIndex);
            if (DayIndex >= currentTT.Week.Count) return;
            //if (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)) return;

            int PeriodIndex = -1;

            do
            {
                PeriodIndex++;
            } while ((PeriodIndex < currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)));
            //Console.WriteLine("Period Index: " + PeriodIndex);
            if (PeriodIndex >= currentTT.Week[DayIndex].PeriodsInDay.Count) return;

            // if (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)) return;

            int StaffIndex = -1;

            do
            {
                StaffIndex++;
            } while ((StaffIndex < currentTT.Staff.Count - 1) && (!currentTT.Staff[StaffIndex].staffBounds.IntersectsWith(cursor)));
            //Console.WriteLine("Staff Index: " + StaffIndex);
            // if (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)) return;
            if (StaffIndex >= currentTT.Staff.Count) return;
            Lesson selectedLesson = null;
            try
            {
                selectedLesson = (Lesson)currentTT.staffTT[DayIndex][PeriodIndex][StaffIndex];
            }
            catch (Exception)
            {
                return;
            }
            //Console.WriteLine("Status: " + mainViewMode);
            if (mainViewMode == ClickMode.AddLessonViaMenu)
            {
                mainViewMode = ClickMode.Normal;
                lessonView = new AddLesson();
                lessonView.currentTT = currentTT;
                lessonView.LoadData();
                lessonView.cb_teacherCode.SelectedIndex = StaffIndex;
                lessonView.cb_day.SelectedIndex = DayIndex;
                lessonView.cb_periodStart.SelectedIndex = PeriodIndex;
                lessonView.ShowDialog();

                lbl_status.Text = "Ready";
                return;
            }

            if (mainViewMode == ClickMode.Move && sw.ElapsedMilliseconds > timeForMove)
            {
                if (displayedItem.locked)
                {
                    MessageBox.Show("One cannot move a locked lesson. To move it, please unlock the lesson.", "Lesson locking");
                    return;
                }
                bool ConditionA = (displayedItem.TeacherAbbreviation != currentTT.Staff[StaffIndex].TeacherAbbreviation);
                bool ConditionB = (displayedItem.PeriodIndex != PeriodIndex);
                bool eventAfter = ConditionA;

                if (ConditionA) AddNodeToUndo(Event.MoveStaff, currentTT.GetIndexOfStaff(displayedItem.TeacherAbbreviation), StaffIndex, displayedItem, false,ConditionB);
                if (ConditionB) AddNodeToUndo(Event.MovePeriod, displayedItem.PeriodIndex, PeriodIndex, displayedItem, eventAfter,false);

                currentTT.MoveTeacher(displayedItem, Convert.ToByte(StaffIndex));
                currentTT.MovePeriods(displayedItem, Convert.ToByte(PeriodIndex));

                mainViewMode = ClickMode.Normal;
                RefreshViews();
                displayedItem.selected = true;
                return;
            }
            if (selectedLesson == null) displayedItem = null;
            else
            {

                selectedLesson.selected = true;
                displayedItem = selectedLesson;
                pb_staffView.Refresh();

                cb_year.SelectedIndex = selectedLesson.YearIndex;
                cb_room.SelectedIndex = currentTT.GetIndexOfRoom(selectedLesson.RoomCode);
                cb_teacher.SelectedIndex = StaffIndex;
                cb_subject.SelectedIndex = currentTT.GetIndexOfSubject(selectedLesson.SubjectAbbreviation);
                btn_locked.Checked = selectedLesson.locked;
                btn_invisible.Checked = selectedLesson.invisible;

                if (selectedLesson.locked)
                {
                    editLessonToolStripMenuItem.Enabled = false; //we can't edit anything that's locked.

                }
                else
                {
                    editLessonToolStripMenuItem.Enabled = true;
                }

                cb_homework.Text = Convert.ToString(selectedLesson.homeworkAmount);
                cb_form.Text = currentTT.Years[selectedLesson.YearIndex].Forms[selectedLesson.FormIndex].FormName;
            }
            mainViewMode = ClickMode.Normal;
        }
Example #6
0
        private void tabControl1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F1:
                    tabControl1.SelectTab(0);
                    break;
                case Keys.F2:
                    tabControl1.SelectTab(1);
                    break;
                case Keys.F3:
                    tabControl1.SelectTab(2);
                    break;
                case Keys.F4:
                    tabControl1.SelectTab(3);
                    break;
                case Keys.F5:
                    tabControl1.SelectedTab.Refresh();
                    break;
                case Keys.Up:
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    int DayIndex = displayedItem.DayIndex;
                    int PeriodIndex = displayedItem.PeriodIndex;
                    int YearIndex = displayedItem.YearIndex;
                    int FormIndex = displayedItem.FormIndex;
                    do
                    {
                        if ((PeriodIndex == 0) && (DayIndex != 0)) {
                            DayIndex--;
                            PeriodIndex = currentTT.Week[DayIndex].PeriodsInDay.Count;
                        }
                        else if ((PeriodIndex == 0)) return;
                        PeriodIndex--;
                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                case Keys.Down:
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((PeriodIndex == currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (DayIndex != currentTT.Week.Count - 1)) {
                            DayIndex++;
                            PeriodIndex = -1;
                        }
                        else if ((PeriodIndex == currentTT.Week[DayIndex].PeriodsInDay.Count - 1)) return;
                        PeriodIndex++;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                case Keys.Left:
                    e.Handled = true; //this escapes the automatic movement of tab pages, which can be annoying.

                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((FormIndex == 0) && (YearIndex != 0)) {
                            YearIndex--;
                            FormIndex = currentTT.Years[YearIndex].Forms.Count;
                        }
                        else if ((YearIndex == 0) && (FormIndex == 0)) return;
                        FormIndex--;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;

                case Keys.Right:
                    e.Handled = true;
                    if (displayedItem == null) return;
                    displayedItem.selected = false;
                    DayIndex = displayedItem.DayIndex;
                    PeriodIndex = displayedItem.PeriodIndex;
                    YearIndex = displayedItem.YearIndex;
                    FormIndex = displayedItem.FormIndex;

                    do
                    {
                        if ((FormIndex == currentTT.Years[YearIndex].Forms.Count - 1) && (YearIndex != currentTT.Years.Count - 1)) {
                            YearIndex++;
                            FormIndex = -1;
                        }
                        else if ((YearIndex == currentTT.Years.Count - 1) && (FormIndex == currentTT.Years[YearIndex].Forms.Count - 1)) return;
                        FormIndex++;

                        displayedItem = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];
                        //MessageBox.Show("RIGHT!!!");

                    } while (displayedItem == null);
                    displayedItem.selected = true;
                    DisplayInfoAboutLesson(displayedItem);
                    pb_mainView.Refresh();
                    break;
                default:
                    break;
            }
        }
Example #7
0
        private void DrawSchoolView(Graphics G, int cellWidth, int cellHeight, int marginLeft, int marginTop, bool printInvisible)
        {
            int col = 2 * cellWidth;

            foreach (YearGroup year in currentTT.Years)
            {
                G.DrawRectangle(Pens.Black, col + marginLeft, marginTop, cellWidth * year.Forms.Count, cellHeight);
                G.DrawString(year.YearName, new Font("Segoe UI", 12), Brushes.Black, col, marginTop);

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

            int row = 2 * 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);
                }

                if (!currentTT.IsFinalised())
                {
                    return;
                }
                //int xCoord =  cellWidth + MarginLeft;
                int yCoord = cellHeight + 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 yearIndex = 0; yearIndex < currentTT.Years.Count; yearIndex++)
                        {
                            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;
                            }
                        }
                    }
                }
            }
        }
Example #8
0
 private void lv_tray_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lv_tray.SelectedIndices.Count != 0)
     {
         displayedItem.selected = false;
         displayedItem = currentTT.Tray[lv_tray.SelectedIndices[0]];
         DisplayInfoAboutLesson(displayedItem);
         lv_tray.Refresh();
     }
 }
Example #9
0
        /// <summary>
        /// Finalise the timetable. This will prevent the structure from being changed...
        /// </summary>
        public void Finalise()
        {
            mainTT = new Lesson[Week.Count][][][];

            staffTT = new Lesson[Week.Count][][];
            roomTT = new Lesson[Week.Count][][];
            for (int ptr = 0; ptr < Week.Count; ptr++)
            {
                numberOfTotalPeriods += Week[ptr].PeriodsInDay.Count();
                mainTT[ptr] = new Lesson[Week[ptr].PeriodsInDay.Count][][];
                staffTT[ptr] = new Lesson[Week[ptr].PeriodsInDay.Count][];
                roomTT[ptr] = new Lesson[Week[ptr].PeriodsInDay.Count][];

                for (int pptr = 0; pptr < Week[ptr].PeriodsInDay.Count; pptr++)
                {
                    this.mainTT[ptr][pptr] = new Lesson[Years.Count][];

                    for (int yptr = 0; yptr < Years.Count; yptr++)
                        this.mainTT[ptr][pptr][yptr] = new Lesson[Years[yptr].Forms.Count];

                    staffTT[ptr][pptr] = new Lesson[Staff.Count];
                    roomTT[ptr][pptr] = new Lesson[Rooms.Count];
                }
            }

            this.finalised = true;
        }
Example #10
0
 public undoRedoEvent(Event task, int A_Index, int B_Index,Lesson lessonToUndo,bool undoEventAfter, bool redoEventAfter)
 {
     A = A_Index;
     B = B_Index;
     this.undoEventAfter = undoEventAfter;
     this.redoEventAfter = redoEventAfter;
     this.task = task;
     this.lessonToUndo = lessonToUndo;
 }
Example #11
0
 private void DisplayInfoAboutLesson(Lesson LessonToDisplay)
 {
     cb_year.SelectedIndex = LessonToDisplay.YearIndex;
     cb_homework.Text = Convert.ToString(LessonToDisplay.homeworkAmount);
     cb_room.SelectedIndex = currentTT.GetIndexOfRoom(LessonToDisplay.RoomCode);
     cb_subject.SelectedIndex = currentTT.GetIndexOfSubject(LessonToDisplay.SubjectAbbreviation);
     cb_teacher.SelectedIndex = currentTT.GetIndexOfStaff(LessonToDisplay.TeacherAbbreviation);
     cb_form.SelectedIndex = LessonToDisplay.FormIndex;
     btn_invisible.Checked = LessonToDisplay.invisible;
     btn_locked.Checked = LessonToDisplay.locked;
 }
Example #12
0
 public void MoveToTray(Lesson lessonToMove)
 {
     DeleteLesson(lessonToMove);
     lessonToMove.DayIndex = 0;
     lessonToMove.PeriodIndex = 0;
     lessonToMove.YearIndex = 0;
     lessonToMove.FormIndex = 0;
     Tray.Add(lessonToMove);
 }
Example #13
0
        /// <summary>
        /// Move a lesson from one year to another.
        /// </summary>
        /// <param name="LessonToMove">The lesson object to move.</param>
        /// <param name="newYearIndex">The new year index to move to.</param>
        public void MoveYears(Lesson LessonToMove, byte newYearIndex)
        {
            if (LessonToMove.YearIndex == newYearIndex) return; //already done
            if (mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][newYearIndex][0] != null) return; //should throw exception really.
            Lesson oldLessonToMove = LessonToMove.Clone();
            byte oldYearIndex = oldLessonToMove.YearIndex;
            LessonToMove.YearIndex = newYearIndex;

            if (Years[newYearIndex].Forms.Count > oldLessonToMove.FormIndex)
            {
                LessonToMove.FormIndex = oldLessonToMove.FormIndex;
            }
            else
            {
                LessonToMove.FormIndex = 0;
            }

            if (Years[newYearIndex].Forms.Count == 0) return;

                 mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][newYearIndex][LessonToMove.FormIndex] = LessonToMove;

                mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][oldYearIndex][oldLessonToMove.FormIndex] = null;
        }
Example #14
0
        /// <summary>
        /// Allows one to move teachers from one location to another.
        /// </summary>
        /// <param name="LessonToMove">The lesson object to move</param>
        /// <param name="newTeacherIndex">The new teacher index to move to.</param>
        public void MoveTeacher(Lesson LessonToMove, byte newTeacherIndex)
        {
            if (LessonToMove.TeacherAbbreviation == Staff[newTeacherIndex].TeacherAbbreviation) return; //work is done.
            if (staffTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][newTeacherIndex] != null) return; //should throw an exception really.

            byte oldTeacherIndex = Convert.ToByte(GetIndexOfStaff(LessonToMove.TeacherAbbreviation));
            Lesson oldLessonToMove = LessonToMove.Clone();
            LessonToMove.TeacherAbbreviation = Staff[newTeacherIndex].TeacherAbbreviation;
            int i = 0;

            do {
                staffTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex + i][newTeacherIndex] = LessonToMove;
                i++;
            } while((LessonToMove.PeriodIndex + i < Week[LessonToMove.DayIndex].PeriodsInDay.Count) && (staffTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex + i][oldTeacherIndex] == oldLessonToMove));

            for (int j = 0; j < i; j++)
                staffTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex + j][oldTeacherIndex] = null;
        }
Example #15
0
 /// <summary>
 /// Move a room to a new room index
 /// </summary>
 /// <param name="LessonToMove">Lesson to move</param>
 /// <param name="newRoomIndex">new Room Index to move to (byte)</param>
 public void MoveRooms(Lesson LessonToMove, byte newRoomIndex)
 {
     if (LessonToMove.RoomCode == Rooms[newRoomIndex].RoomCode) return; //work is done already.
     if (roomTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][newRoomIndex] != null) return; //should throw exception really
     Lesson oldLessonToMove = LessonToMove.Clone();
     byte oldRoomIndex = Convert.ToByte(GetIndexOfRoom(LessonToMove.RoomCode));
     LessonToMove.RoomCode = Rooms[newRoomIndex].RoomCode;
          roomTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][newRoomIndex] = LessonToMove;
          roomTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][oldRoomIndex] = null;
 }
Example #16
0
        /// <summary>
        /// Move a lesson to a new period.
        /// </summary>
        /// <param name="LessonToMove">The lesson to move.</param>
        /// <param name="newPeriodIndex">The new period index to move to.</param>
        /// <returns>Success</returns>
        public bool MovePeriods(Lesson LessonToMove, byte newPeriodIndex)
        {
            //updating for main tt also means we must update for staff, adn other tables too. This is important to remember.
               //we essentially go through the current value, and save to newperiodindex + i. repeat for the other tables.
            if (newPeriodIndex == LessonToMove.PeriodIndex) return true;

            //move main one to new period index
            //if oldPeriodIndex + i is the same lesson, move that to newPeriodIndex + i.
            //The same is true for staff
            //the same is true for rooms
            byte oldPeriodIndex = LessonToMove.PeriodIndex;
            int roomIndex = GetIndexOfRoom(LessonToMove.RoomCode);
            int staffIndex = GetIndexOfStaff(LessonToMove.TeacherAbbreviation);
            if (roomIndex < 0 | staffIndex < 0) return false;
            if (mainTT[LessonToMove.DayIndex][newPeriodIndex][LessonToMove.YearIndex][LessonToMove.FormIndex] != null) return false;
            if (staffTT[LessonToMove.DayIndex][newPeriodIndex][staffIndex] != null) return false;
            if (roomTT[LessonToMove.DayIndex][newPeriodIndex][roomIndex] != null) return false;
            LessonToMove.PeriodIndex = newPeriodIndex;
            int baseIndex = newPeriodIndex > oldPeriodIndex ? newPeriodIndex : oldPeriodIndex; //get the lowest of the two. This is to prevent an overflow.

            mainTT[LessonToMove.DayIndex][newPeriodIndex][LessonToMove.YearIndex][LessonToMove.FormIndex] = LessonToMove;
            mainTT[LessonToMove.DayIndex][oldPeriodIndex][LessonToMove.YearIndex][LessonToMove.FormIndex] = null;

            roomTT[LessonToMove.DayIndex][newPeriodIndex][roomIndex] = LessonToMove;
            roomTT[LessonToMove.DayIndex][oldPeriodIndex][roomIndex] = null; //clear the old memory pointer.

            staffTT[LessonToMove.DayIndex][newPeriodIndex][staffIndex] = LessonToMove;
            staffTT[LessonToMove.DayIndex][oldPeriodIndex][staffIndex] = null; //clear the old memory pointer.

            return true;
        }
Example #17
0
        /// <summary>
        /// Move a lesson from one form to another.
        /// </summary>
        /// <param name="LessonToMove">The lesson object to move.</param>
        /// <param name="newFormIndex">The new form index to be moved to.</param>
        public void MoveForms(Lesson LessonToMove, byte newFormIndex)
        {
            if (LessonToMove.FormIndex == newFormIndex) return; //it is already done.
            if (newFormIndex >= Years[LessonToMove.YearIndex].Forms.Count) return; //if we have odd information, then reject it and return without moving anything.
            if (mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][LessonToMove.YearIndex][newFormIndex] != null) return;//we should throw an exception really.

            byte oldFormIndex = LessonToMove.FormIndex;
            LessonToMove.FormIndex = newFormIndex;

                mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][LessonToMove.YearIndex][newFormIndex] = LessonToMove;
                mainTT[LessonToMove.DayIndex][LessonToMove.PeriodIndex][LessonToMove.YearIndex][oldFormIndex] = null;
        }
Example #18
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;
        }
Example #19
0
        private void deleteLessonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //delete lesson
            if (displayedItem != null)
            {
                currentTT.DeleteLesson(displayedItem);
                displayedItem = null;

            }
            else
            {
                MessageBox.Show("Please select a lesson first.", "TimeLord");

            }
        }
Example #20
0
        /// <summary>
        /// Delete a lesson
        /// </summary>
        /// <param name="lessonToDelete">The lesson to delete</param>
        /// <returns>success in deleting</returns>
        public bool DeleteLesson(Lesson lessonToDelete)
        {
            if (lessonToDelete == null) return false;
            byte StaffIndex = Convert.ToByte(GetIndexOfStaff(lessonToDelete.TeacherAbbreviation));
            byte RoomIndex = Convert.ToByte(GetIndexOfRoom(lessonToDelete.RoomCode));
            byte DayIndex = lessonToDelete.DayIndex;
            byte PeriodIndex = lessonToDelete.PeriodIndex;
            byte YearIndex = lessonToDelete.YearIndex;
            byte FormIndex = lessonToDelete.FormIndex;

            int Ptr = 0;
            do
            {
                mainTT[DayIndex][PeriodIndex + Ptr][YearIndex][FormIndex] = null;
                Ptr++;
            } while ((Ptr < Week[DayIndex].PeriodsInDay.Count - 1) && (mainTT[DayIndex][PeriodIndex + Ptr][YearIndex][FormIndex] == lessonToDelete));

            Ptr = 0;
             do
            {
                roomTT[DayIndex][PeriodIndex + Ptr][RoomIndex] = null;
                Ptr++;

            } while ((Ptr < Week[DayIndex].PeriodsInDay.Count - 1) && (roomTT[DayIndex][PeriodIndex + Ptr][RoomIndex] == lessonToDelete));

            Ptr = 0;
             do
            {
                staffTT[DayIndex][PeriodIndex + Ptr][StaffIndex] = null;
                Ptr++;
            } while ((Ptr < Week[DayIndex].PeriodsInDay.Count - 1) && (staffTT[DayIndex][PeriodIndex + Ptr][StaffIndex] == lessonToDelete));

            //the code above deletes the consecutive lessons (which typically are automatically added).

            return true;
        }
Example #21
0
        private void pb_roomView_MouseClick(object sender, MouseEventArgs e)
        {
            if (displayedItem != null)
            {
                displayedItem.selected = false;

            }

            Rectangle cursor = new Rectangle(e.X, e.Y, 1, 1);

            int DayIndex = -1;

            do
            {
                DayIndex++;
            } while ((DayIndex < currentTT.Week.Count - 1) && (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)));

            if (DayIndex >= currentTT.Week.Count) return;
            //if (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)) return;

            int PeriodIndex = -1;

            do
            {
                PeriodIndex++;
            } while ((PeriodIndex < currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)));

            if (PeriodIndex >= currentTT.Week[DayIndex].PeriodsInDay.Count) return;

            // if (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)) return;

            int RoomIndex = -1;

            do
            {
                RoomIndex++;
            } while ((RoomIndex < currentTT.Rooms.Count - 1) && (!currentTT.Rooms[RoomIndex].roomBounds.IntersectsWith(cursor)));

            // if (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)) return;
            if (RoomIndex >= currentTT.Rooms.Count) return;
            Lesson selectedLesson = null;
            try
            {
                selectedLesson = (Lesson)currentTT.roomTT[DayIndex][PeriodIndex][RoomIndex];
            }
            catch (Exception)
            {
                return;
            }
            if (selectedLesson == null) return;
            selectedLesson.selected = true;
            displayedItem = selectedLesson;
            pb_roomView.Refresh();

            cb_year.SelectedIndex = selectedLesson.YearIndex;
            cb_room.SelectedIndex = currentTT.GetIndexOfRoom(selectedLesson.RoomCode);
            cb_teacher.SelectedIndex = currentTT.GetIndexOfStaff(selectedLesson.TeacherAbbreviation);
            cb_subject.SelectedIndex = currentTT.GetIndexOfSubject(selectedLesson.SubjectAbbreviation);

            cb_homework.Text = Convert.ToString(selectedLesson.homeworkAmount);
            cb_form.Text = currentTT.Years[selectedLesson.YearIndex].Forms[selectedLesson.FormIndex].FormName;
            btn_invisible.Checked = selectedLesson.invisible;
            btn_locked.Checked = selectedLesson.locked;
        }
Example #22
0
        private void pb_staffView_MouseClick(object sender, MouseEventArgs e)
        {
            if (displayedItem != null)
            {
                displayedItem.selected = false;

            }

            Rectangle cursor = new Rectangle(e.X, e.Y, 1, 1);

            int DayIndex = -1;

            do
            {
                DayIndex++;
            } while ((DayIndex < currentTT.Week.Count - 1) && (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)));

            if (DayIndex >= currentTT.Week.Count) return;
            //if (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)) return;

            int PeriodIndex = -1;

            do
            {
                PeriodIndex++;
            } while ((PeriodIndex < currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)));

            if (PeriodIndex >= currentTT.Week[DayIndex].PeriodsInDay.Count) return;

            // if (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)) return;

            int StaffIndex = -1;

            do
            {
                StaffIndex++;
            } while ((StaffIndex < currentTT.Staff.Count - 1) && (!currentTT.Staff[StaffIndex].staffBounds.IntersectsWith(cursor)));

            // if (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)) return;
            if (StaffIndex >= currentTT.Staff.Count) return;
            Lesson selectedLesson = null;
            try
            {
                selectedLesson = (Lesson)currentTT.staffTT[DayIndex][PeriodIndex][StaffIndex];
            }
            catch (Exception)
            {
                return;
            }

            if (addLessonViaMenu == true)
            {
                lessonView = new AddLesson();
                lessonView.currentTT = currentTT;
                lessonView.LoadData();
                lessonView.cb_teacherCode.SelectedIndex = StaffIndex;
                lessonView.cb_day.SelectedIndex = DayIndex;
                lessonView.cb_periodStart.SelectedIndex = PeriodIndex;
                lessonView.ShowDialog();
                addLessonViaMenu = false;
                lbl_status.Text = "Ready";
                return;
            }

            if (selectedLesson == null) displayedItem = null;
            else
            {

                selectedLesson.selected = true;
                displayedItem = selectedLesson;
                pb_staffView.Refresh();

                cb_year.SelectedIndex = selectedLesson.YearIndex;
                cb_room.SelectedIndex = currentTT.GetIndexOfRoom(selectedLesson.RoomCode);
                cb_teacher.SelectedIndex = StaffIndex;
                cb_subject.SelectedIndex = currentTT.GetIndexOfSubject(selectedLesson.SubjectAbbreviation);

                cb_homework.Text = Convert.ToString(selectedLesson.homeworkAmount);
                cb_form.Text = currentTT.Years[selectedLesson.YearIndex].Forms[selectedLesson.FormIndex].FormName;
            }
        }
Example #23
0
        //private void DetectClickForMain(out int DayIndex, out int PeriodIndex, out int YearIndex, out int FormIndex,out Lesson selectedLesson,Rectangle cursor)
        //{
        //    DayIndex = -1;
        //    FormIndex = -1;
        //    YearIndex = -1;
        //    PeriodIndex = -1;
        //    selectedLesson = null;
        //    do
        //    {
        //        DayIndex++;
        //    } while ((DayIndex < currentTT.Week.Count - 1) && (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)));
        //    Console.WriteLine("DayIndex: " + DayIndex);
        //    if (DayIndex >= currentTT.Week.Count) return;
        //    //if (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)) return;
        //    do
        //    {
        //        PeriodIndex++;
        //    } while ((PeriodIndex < currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)));
        //    Console.WriteLine("Period Index: " + PeriodIndex);
        //    if (PeriodIndex >= currentTT.Week[DayIndex].PeriodsInDay.Count) return;
        //    // if (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)) return;
        //    do
        //    {
        //        YearIndex++;
        //    } while ((YearIndex < currentTT.Years.Count - 1) && (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)));
        //    Console.WriteLine("Year Index: " + YearIndex);
        //    // if (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)) return;
        //    if (YearIndex >= currentTT.Years.Count) return;
        //    do
        //    {
        //        FormIndex++;
        //    } while ((FormIndex < currentTT.Years[YearIndex].Forms.Count() - 1) && (!currentTT.Years[YearIndex].Forms[FormIndex].formBounds.IntersectsWith(cursor)));
        //    Console.WriteLine("Form Index: " + FormIndex);
        //    if (FormIndex >= currentTT.Years[YearIndex].Forms.Count()) return;
        //    try
        //    {
        //        selectedLesson = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];
        //    }
        //    catch
        //    {
        //    }
        //}
        private void pb_mainView_MouseClick(object sender, MouseEventArgs e)
        {
            //RENAME TO MouseUp.
            if (sw != null) sw.Stop();
            if (displayedItem != null)
            {
                displayedItem.selected = false;

            }
            if (!currentTT.IsFinalised()) return;
            Rectangle cursor = new Rectangle(e.X, e.Y, 1, 1);

            int YearIndex;
            int PeriodIndex;
            int DayIndex;
            int FormIndex;
            Lesson selectedLesson;
            DayIndex = -1;
            FormIndex = -1;
            YearIndex = -1;
            PeriodIndex = -1;
            selectedLesson = null;
            do
            {
                DayIndex++;
            } while ((DayIndex < currentTT.Week.Count - 1) && (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)));
            //Console.WriteLine("DayIndex: " + DayIndex);
            if (DayIndex >= currentTT.Week.Count) return;
            //if (!currentTT.Week[DayIndex].dayBounds.IntersectsWith(cursor)) return;

            do
            {
                PeriodIndex++;
            } while ((PeriodIndex < currentTT.Week[DayIndex].PeriodsInDay.Count - 1) && (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)));
            //Console.WriteLine("Period Index: " + PeriodIndex);
            if (PeriodIndex >= currentTT.Week[DayIndex].PeriodsInDay.Count) return;

            // if (!currentTT.Week[DayIndex].PeriodsInDay[PeriodIndex].periodBounds.IntersectsWith(cursor)) return;

            do
            {
                YearIndex++;
            } while ((YearIndex < currentTT.Years.Count - 1) && (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)));
            //Console.WriteLine("Year Index: " + YearIndex);
            // if (!currentTT.Years[YearIndex].yearBounds.IntersectsWith(cursor)) return;
            if (YearIndex >= currentTT.Years.Count) return;

            do
            {
                FormIndex++;
            } while ((FormIndex < currentTT.Years[YearIndex].Forms.Count() - 1) && (!currentTT.Years[YearIndex].Forms[FormIndex].formBounds.IntersectsWith(cursor)));
            //Console.WriteLine("Form Index: " + FormIndex);
            if (FormIndex >= currentTT.Years[YearIndex].Forms.Count()) return;

            try
            {
                selectedLesson = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];
            }
            catch
            {

            }

            if (mainViewMode == ClickMode.AddLessonViaMenu)
            {
                lessonView = new AddLesson();
                lessonView.currentTT = currentTT;
                lessonView.LoadData();
                lessonView.cb_day.SelectedIndex = DayIndex;

                lessonView.cb_periodStart.SelectedIndex = PeriodIndex;
                lessonView.cb_yearGroup.SelectedIndex = YearIndex;
                lessonView.cb_class.SelectedIndex = FormIndex;
                mainViewMode = ClickMode.Normal;
                lessonView.ShowDialog();

                pb_mainView.Refresh();
                lbl_status.Text = "Ready";
                return;
            }
            if (mainViewMode == ClickMode.InsertFromTray)
            {
                if (lv_tray.SelectedIndices.Count == 0)
                {
                    mainViewMode = ClickMode.Normal;
                    return;
                }
                currentTT.MoveFromTrayToMainTT(DayIndex, PeriodIndex, YearIndex, FormIndex, lv_tray.SelectedIndices[0]);
                mainViewMode = ClickMode.Normal;
                RefreshTrayItems();
                return;
            }
            else if (mainViewMode == ClickMode.FindStaff)
            {
                mainViewMode = ClickMode.Normal;
                lbl_status.Text = currentTT.FreeStaffCodes(Convert.ToByte(DayIndex), Convert.ToByte(PeriodIndex));

            }
            else if (mainViewMode == ClickMode.FindRooms) {
                mainViewMode = ClickMode.Normal;
                lbl_status.Text =  currentTT.FreeRoomCodes(Convert.ToByte(DayIndex), Convert.ToByte(PeriodIndex));

            }

            selectedLesson = currentTT.mainTT[DayIndex][PeriodIndex][YearIndex][FormIndex];

            if (mainViewMode == ClickMode.Move && sw.ElapsedMilliseconds > timeForMove)
            {

                //MessageBox.Show("Move: " + FormIndex + " " + YearIndex);
                if (displayedItem.locked)
                {
                    MessageBox.Show("One cannot move a locked lesson. To move it, please unlock the lesson.", "Lesson locking");
                    mainViewMode = ClickMode.Normal;
                    return;
                }

                bool ConditionA = (displayedItem.YearIndex != YearIndex);
                bool ConditionB = (displayedItem.PeriodIndex != PeriodIndex);
                bool ConditionC = (displayedItem.FormIndex != FormIndex);

                if (ConditionA) AddNodeToUndo(Event.MoveYear, displayedItem.YearIndex, YearIndex, displayedItem,false,ConditionB|ConditionC);
                if (ConditionB) AddNodeToUndo(Event.MovePeriod, displayedItem.PeriodIndex, PeriodIndex, displayedItem, ConditionA,ConditionC);

                if (ConditionC) AddNodeToUndo(Event.MoveForm, displayedItem.FormIndex, FormIndex,displayedItem, ConditionA | ConditionB,false);
                currentTT.MoveForms(displayedItem, Convert.ToByte(FormIndex));

                currentTT.MovePeriods(displayedItem, Convert.ToByte(PeriodIndex));
                currentTT.MoveYears(displayedItem, Convert.ToByte(YearIndex));

                mainViewMode = ClickMode.Normal;
                RefreshViews();
                displayedItem.selected = true;
                return;
            }

            if (selectedLesson == null)
            {
                displayedItem = null;
                pb_mainView.Refresh();
            }

            else
            {
                selectedLesson.selected = true;
                displayedItem = selectedLesson;;
                pb_mainView.Refresh();

                cb_year.SelectedIndex = YearIndex;
                cb_room.SelectedIndex = currentTT.GetIndexOfRoom(selectedLesson.RoomCode);
                cb_teacher.SelectedIndex = currentTT.GetIndexOfStaff(selectedLesson.TeacherAbbreviation);
                cb_subject.SelectedIndex = currentTT.GetIndexOfSubject(selectedLesson.SubjectAbbreviation);

                cb_homework.Text = Convert.ToString(selectedLesson.homeworkAmount);
                cb_form.Text = currentTT.Years[YearIndex].Forms[FormIndex].FormName;
                btn_invisible.Checked = selectedLesson.invisible;
                btn_locked.Checked = selectedLesson.locked;
            }
            mainViewMode = ClickMode.Normal;
        }
Example #24
0
 public void LoadLesson(Lesson lessonToLoad)
 {
     this.loadedLesson = lessonToLoad;
 }