Esempio n. 1
0
        public void LoadLessons()
        {
            m_reader = new XmlTextReader(m_fileName);
            XmlDocument xml = new XmlDocument();
            xml.Load(m_reader);
            XmlNodeList nodes = xml.GetElementsByTagName("Lessons");
            if ((nodes.Item(0).Attributes["Count"].Value.Equals("0")))
                return;

            foreach (XmlNode node in nodes.Item(0).ChildNodes)
            {
                Lecturer lect = null;
                Module mod = null;
                Room room = null;
                Group group = null;
                int day = 0;
                int time = 0;

                int num = 0;

                foreach (XmlNode data in node.ChildNodes)
                {
                    try
                    {
                        if (data.Name.Equals("Lecturer"))
                        {
                            num = int.Parse(data.InnerText);
                            if (num > -1)
                                lect = DataCollection.Instance.Lecturers[num];
                        }
                        else if (data.Name.Equals("Module"))
                        {
                            num = int.Parse(data.InnerText);
                            if (num > -1)
                                mod = DataCollection.Instance.Modules[num];
                        }
                        else if (data.Name.Equals("Room"))
                        {
                            num = int.Parse(data.InnerText);
                            if (num > -1)
                                room = DataCollection.Instance.Rooms[num];
                        }
                        else if (data.Name.Equals("Group"))
                        {
                            num = int.Parse(data.InnerText);
                            if (num > -1)
                                group = DataCollection.Instance.Groups[num];
                        }
                        else if (data.Name.Equals("Day"))
                        {
                            day = int.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals("Time"))
                        {
                            time = int.Parse(data.InnerText);
                        }

                        if (lect != null || mod != null || room != null || group != null)
                        {
                            Lesson lesson = new Lesson();
                            lesson.Lecturer = lect;
                            lesson.Module = mod;
                            lesson.Room = room;
                            lesson.Group = group;
                            lesson.Day = day;
                            lesson.Time = time;
                            DataCollection.Instance.Add(lesson);
                        }
                    }
                    catch
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 2
0
        private void Panel_DragDrop(object sender, DragEventArgs e)
        {
            GridPanel gPanel = (GridPanel)sender;
            Lesson lesson = new Lesson();

            /*****************************************************************************************************************/
            if (e.Data.GetData(typeof(Lesson)) is Lesson)
            {
                Lesson oldLesson = (Lesson)e.Data.GetData(typeof(Lesson));
                //  Move
                if (e.Effect == DragDropEffects.Move)
                {
                    GridPanel gp = (GridPanel)tlpTimetable.GetControlFromPosition(oldLesson.Time, oldLesson.Day);
                    if (gp.LessonData != oldLesson)
                    {
                        DataCollection.Instance.Remove(oldLesson);
                        gp.LessonData.Lecturer = null;
                        gp.LessonData.Module = null;
                        gp.LessonData.Room = null;
                        gp.LessonData.Group = null;
                        gp.UpdateText();
                    }
                }
                gPanel.LessonData = oldLesson;
            }
            else
            {
                if (e.Data.GetData(typeof(Lecturer)) is Lecturer && m_data is Lecturer)
                {
                    MessageBox.Show("Cannot add Lecturer to a Lecturer's Timetable", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (e.Data.GetData(typeof(Module)) is Module && m_data is Module)
                {
                    MessageBox.Show("Cannot add Module to a Module's Timetable", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (e.Data.GetData(typeof(Room)) is Room && m_data is Room)
                {
                    MessageBox.Show("Cannot add Room to a Room's Timetable", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (e.Data.GetData(typeof(Group)) is Group && m_data is Group)
                {
                    MessageBox.Show("Cannot add Group to a Group's Timetable", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (e.Data.GetData(typeof(Lecturer)) is Lecturer)
                {
                    Lecturer lect = (Lecturer)e.Data.GetData(typeof(Lecturer));
                    gPanel.LessonData.Lecturer = lect;
                }
                else if (e.Data.GetData(typeof(Module)) is Module)
                {
                    Module mod = (Module)e.Data.GetData(typeof(Module));
                    gPanel.LessonData.Module = mod;
                }
                else if (e.Data.GetData(typeof(Room)) is Room)
                {
                    Room room = (Room)e.Data.GetData(typeof(Room));
                    gPanel.LessonData.Room = room;
                }
                else if (e.Data.GetData(typeof(Group)) is Group)
                {
                    Group group = (Group)e.Data.GetData(typeof(Group));
                    gPanel.LessonData.Group = group;
                }

                if (m_data is Lecturer)
                {
                    gPanel.LessonData.Lecturer = (Lecturer)m_data;
                }
                else if (m_data is Module)
                {
                    gPanel.LessonData.Module = (Module)m_data;
                }
                else if (m_data is Room)
                {
                    gPanel.LessonData.Room = (Room)m_data;
                }
                else if (m_data is Group)
                {
                    gPanel.LessonData.Group = (Group)m_data;
                }
            }

            lesson = gPanel.LessonData;
            if(DataCollection.Instance.DoesLessonClash(lesson))
            {
                MessageBox.Show("Unable to add lesson. Make sure nothing is timetabled for the same lesson.\nE.g. Lecturers booked for the same room at the same time.", "ERROR: DOUBLE BOOKING DETECTED", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (DataCollection.Instance.FindLesson(lesson, lesson.Time, lesson.Day) == null)
            {
                DataCollection.Instance.Add(lesson);
            }
            else
            {
                int i = DataCollection.Instance.Lessons.IndexOf(lesson);
                DataCollection.Instance.Lessons[i] = lesson;
            }
            gPanel.UpdateText();
            ChangeColours(m_colour);
        }
Esempio n. 3
0
 public void Add(Lesson lesson)
 {
     Lessons.Add(lesson);
 }
Esempio n. 4
0
 public void Remove(Lesson lesson)
 {
     if (Lessons.Contains(lesson))
         Lessons.Remove(lesson);
 }
Esempio n. 5
0
 public void Insert(Lesson lesson, int index)
 {
     Lessons.Insert(index, lesson);
 }
Esempio n. 6
0
 public Lesson FindLesson(Lesson data, int time, int day)
 {
     foreach (Lesson lesson in Lessons)
     {
         if (lesson == data && (lesson.Time == time && lesson.Day == day))
         {
             return lesson;
         }
     }
     return null;
 }
Esempio n. 7
0
 /// <summary>
 ///     Check if a lesson clashes with another.
 ///     For example, 2 lecturers booked in the same room.
 /// </summary>
 /// <param name="lesson">Lesson to check</param>
 /// <returns></returns>
 public bool DoesLessonClash(Lesson lesson)
 {
     foreach (Lesson l in Lessons)
     {
         if ((lesson.Lecturer != null && lesson.Lecturer != l.Lecturer) && (lesson.Room != null && lesson.Room == l.Room) && (lesson.Day == l.Day && l.Time == l.Day))
         {
             return true;
         }
         else if ((lesson.Module != null && lesson.Module != l.Module) && (lesson.Room != null && lesson.Room == l.Room) && (lesson.Day == l.Day && l.Time == l.Day))
         {
             return true;
         }
         else if ((lesson.Room != null && lesson.Room != l.Room) && (lesson.Lecturer != null && lesson.Lecturer == l.Lecturer) && (lesson.Day == l.Day && l.Time == l.Day))
         {
             return true;
         }
         else if ((lesson.Room != null && lesson.Room != l.Room) && (lesson.Group != null && lesson.Group == l.Group) && (lesson.Day == l.Day && l.Time == l.Day))
         {
             return true;
         }
         else if ((lesson.Room != null && lesson.Group != l.Group) && (lesson.Group != null && lesson.Room == l.Room) && (lesson.Day == l.Day && l.Time == l.Day))
         {
             return true;
         }
     }
     return false;
 }