public WebpageTermTimetable returnAnotherSameSession(WebpageTermTimetable abandonSession)
        {
            SavingAndReading data = new SavingAndReading();

            data.ReadTermTimetableFile();

            foreach (WebpageTermTimetable e1 in SystemList.TermTimetableList)
            {
                //if(abandonSession != e1)
                {
                    if (e1.ModuleShortName != abandonSession.ModuleShortName && e1.ModuleFullName == abandonSession.ModuleFullName && e1.SessinonProperty == abandonSession.SessinonProperty)
                    {
                        return(e1);
                    }
                }
            }
            return(null);
        }
        public bool checkSessionsCollision(WebpageTermTimetable original, WebpageTermTimetable comparision)
        {
            List <int> originalTimeNum    = new List <int>();
            List <int> comparisionTimeNum = new List <int>();
            bool       repeatNum          = false;


            originalTimeNum    = returnNumberList(original.StartHour, original.EndHour);
            comparisionTimeNum = returnNumberList(comparision.StartHour, comparision.EndHour);

            repeatNum = checkRepeatNumber(originalTimeNum, comparisionTimeNum);

            if (original.EndHour == comparision.StartHour && original.EndMin <= comparision.StartMin)
            {
                repeatNum = false;
            }

            return(repeatNum);
        }
        }//end of CompeletTT method

        public void print()
        {
            WebpageTimeTable test = new WebpageTimeTable();



            foreach (WebpageTimeTable t in timetableContainer)
            {
                WebpageTermTimetable newWebpageTermTimetable = new WebpageTermTimetable();
                newWebpageTermTimetable.Day              = t.Day;
                newWebpageTermTimetable.RoomName         = t.RoomName;
                newWebpageTermTimetable.RoomSize         = t.RoomSize;
                newWebpageTermTimetable.StartHour        = t.StartHour;
                newWebpageTermTimetable.StartMin         = t.StartMin;
                newWebpageTermTimetable.EndHour          = t.EndHour;
                newWebpageTermTimetable.EndMin           = t.EndMin;
                newWebpageTermTimetable.ModuleFullName   = t.SubjectFullName;
                newWebpageTermTimetable.ModuleShortName  = t.SubjectShortName;
                newWebpageTermTimetable.SessinonProperty = "Lecture";

                SavingAndReading data = new SavingAndReading();
                data.ReadModuleFile("module.xml");

                var i = SystemList.ModuleList.FindIndex(r => r.ModuleFullName == t.SubjectFullName) + 1;



                foreach (Module e1 in SystemList.ModuleList)
                {
                    if (e1.ModuleFullName == t.SubjectFullName || e1.ModuleShortName == t.SubjectShortName)
                    {
                        newWebpageTermTimetable.LecturerID = e1.LecturerID;
                        //Console.WriteLine(e1.ModuleFullName, "   ***   ", t.SubjectFullName);
                    }
                }

                SystemList.TermTimetableList.Add(newWebpageTermTimetable);
            }
        }
        private void drawingStudentTT(WebpageTermTimetable e2)
        {
            var moduleShortName = e2.ModuleShortName.Substring(3);
            var roomName        = e2.RoomName;
            var lecturerName    = findLecturerName(e2.LecturerID);
            var row             = e2.Day + 1;
            var column          = e2.StartHour - 8;
            var columnspan      = e2.EndHour - e2.StartHour;


            Label newLabel = new Label();

            newLabel.Dock      = DockStyle.Fill;
            newLabel.Text      = roomName + "\n" + moduleShortName + "\n" + lecturerName;
            newLabel.TextAlign = ContentAlignment.MiddleCenter;
            timetableLayoutPanel.Controls.Add(newLabel);
            timetableLayoutPanel.SetCellPosition(newLabel, new TableLayoutPanelCellPosition(column, row));

            if (columnspan > 1)
            {
                timetableLayoutPanel.SetColumnSpan(newLabel, columnspan);
            }
        }
 public SessionGroups()
 {
     nonLectureSession = new WebpageTermTimetable();
     StudentGroup      = new List <Student>();
 }
Example #6
0
        public void produceRoomTimetable()
        {
            int position = 0, hour = 1, count = 0;
            //string moduleFullName, moduleShortName, roomName, lecturerName = "", startPosition, endPosition;
            WebpageTermTimetable ttDetails = new WebpageTermTimetable();

            SavingAndReading data          = new SavingAndReading();
            //data.ReadSystemList();

            string docName = "TimetableTemplate.xlsx";
            //var workbook = new XLWorkbook(docName);
            //var ws = workbook.Worksheet(1);

            List <Room> tempRoomList = new List <Room>();

            data.ReadRoomFile("room.xml");
            tempRoomList = SystemList.RoomsList;
            data.ReadSystemList();



            //start to select each object from roomsList and print details
            foreach (Room e1 in SystemList.RoomsList)
            {
                var workbook = new XLWorkbook(docName);
                var ws       = workbook.Worksheet(1);
                //if (e1.RoomName == tempRoomList[count].RoomName)
                {
                    subHeader = e1.RoomName;

                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 9; j++)
                        {
                            if (e1.TtDimensionArray[i][j].HasSubject == true)
                            {
                                position  = e1.TtDimensionArray[i][j].TermTTListPosition;
                                ttDetails = SystemList.TermTimetableList[position];

                                var moduleFullName  = ttDetails.ModuleFullName;
                                var moduleShortName = ttDetails.ModuleShortName;
                                var roomName        = ttDetails.RoomName;
                                var lecturerName    = findLecturerName(ttDetails.LecturerID);
                                hour = ttDetails.EndHour - ttDetails.StartHour;
                                //start inserting details for each timetable


                                //ProduceTT ptt = new ProduceTT();

                                //change the subHeader
                                insertTextToSubHeader(roomName, ws);

                                var startPosition = string.Format("{0}{1}", (char)(j + 66), (i + 4));
                                var endPosition   = string.Format("{0}{1}", (char)(j + 66 + hour - 1), (i + 4));
                                //if a module over one hour then merge the cells
                                if (hour > 1)
                                {
                                    mergeCells(startPosition, endPosition, ws);

                                    insertDetailsToCells(moduleFullName, moduleShortName, lecturerName, ws, startPosition, endPosition);
                                }
                                else
                                {
                                    insertDetailsToCells(moduleFullName, moduleShortName, lecturerName, ws, startPosition, endPosition);
                                }
                            }
                        }
                        createFolder();
                        string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Timetable System");

                        workbook.SaveAs(path + "\\Timetable\\" + e1.RoomName + ".xlsx");
                    }
                    colorSelectionList.Clear();
                    count++;
                }
            }
        }
        public void createTemplate()
        {
            SystemList.SessionGroupList.Clear();
            SystemList.TemplateList.Clear();

            int year = 1, term = 1, overlapTimeCollision = 0;
            int practical = 0, tutorial = 0, workshop = 0;
            int totalPracticalSesions = 0;

            int[] dayModules = new int[5];
            //string major = "BSc Computing";
            List <Student> tempStudentList = new List <Student>();
            List <Module>  tempModuleList  = new List <Module>();
            List <WebpageTermTimetable> tempModuleDetailsList          = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> moduleFullNameList             = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> moduleShortNameList            = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> overlapTimeModuleList          = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> overlapTimeModuleList2         = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> tempNonOverlapTimeSessionList  = new List <WebpageTermTimetable>();
            List <WebpageTermTimetable> tempNonOverlapTimeSessionList2 = new List <WebpageTermTimetable>();

            //List<WebpageTermTimetable> generalTTTemplateList = new List<WebpageTermTimetable>();
            //TTTemplateList generalTTTemplateList = new TTTemplateList();

            //List<WebpageTermTimetable> TTTemplateList = new List<WebpageTermTimetable>();
            WebpageTermTimetable[][] tempModuleDetailsArray  = new WebpageTermTimetable[5][];
            WebpageTermTimetable[][] tempModuleDetailsArray2 = new WebpageTermTimetable[5][];

            List <string>          totalPracticalOfEachModuleList = new List <string>();
            List <string>          tempStudentTimetableList       = new List <string>();
            List <string>          practicalList_1 = new List <string>();
            List <string>          practicalList_2 = new List <string>();
            List <SessionProperty> spList          = new List <SessionProperty>();

            List <SessionGroups>  sgList     = new List <SessionGroups>();
            List <TTTemplateList> newtttlist = new List <TTTemplateList>();

            List <Student> splitStudentList = new List <Student>();

            SavingAndReading data = new SavingAndReading();

            //data.ReadSystemList();
            data.ReadLecturerFile();
            data.ReadModuleFile(data.ModuleFilename);
            data.ReadStudentFile();

            //collect the student of a specific year and term
            tempStudentList = returnStudentList();
            //foreach (Student e1 in SystemList.StudentList)
            //{
            //    if (e1.Grade == year && e1.Term == term)
            //    {
            //        tempStudentList.Add(e1);
            //    }
            //}

            //collect the module of a specific year and term
            foreach (Module e1 in SystemList.ModuleList)
            {
                if (e1.Year == year && e1.Term == term)
                {
                    tempModuleList.Add(e1);
                }
            }

            //collect the module details from termtimetable
            foreach (Module e1 in tempModuleList)
            {
                foreach (WebpageTermTimetable e2 in SystemList.TermTimetableList)
                {
                    if (e1.ModuleFullName == e2.ModuleFullName)
                    {
                        tempModuleDetailsList.Add(e2);
                    }
                }
            }

            for (int i = 0; i < 5; i++)
            {
                int countModules = 0;
                foreach (WebpageTermTimetable e1 in tempModuleDetailsList)
                {
                    if (e1.Day == i)
                    {
                        countModules++;
                    }
                }

                dayModules[i] = countModules;
            }

            //seperate modules to different days

            for (int i = 0; i < 5; i++)
            {
                tempModuleDetailsArray[i]  = new WebpageTermTimetable[dayModules[i]];
                tempModuleDetailsArray2[i] = new WebpageTermTimetable[dayModules[i]];
                int j = 0;
                foreach (WebpageTermTimetable e1 in tempModuleDetailsList)
                {
                    if (e1.Day == i)
                    {
                        WebpageTermTimetable newObj = e1;
                        tempModuleDetailsArray[i][j] = newObj;
                        j++;
                    }
                }
            }


            //sort modules from 9am to 18pm
            for (int i = 0; i < 5; i++)
            {
                //for(int j = 0; j < tempModuleDetailsArray[i].Count(); j++)
                {
                    tempModuleDetailsArray2[i] = tempModuleDetailsArray[i].OrderBy(r => r.EndHour).ToArray();
                }
            }


            //check if there is a overlap time for sessions or not
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < tempModuleDetailsArray2[i].Count() - 1; j++)//module needs to make a comparision with rest of modules, so Count() - 1
                {
                    var  original    = tempModuleDetailsArray2[i][j];
                    var  comparision = tempModuleDetailsArray2[i][j + 1];
                    bool result      = false;

                    result = checkSessionsCollision(original, comparision);


                    if (result)
                    {
                        overlapTimeModuleList.Add(original);
                        var anotherSameSession = returnAnotherSameSession(comparision);
                        overlapTimeModuleList.Add(anotherSameSession);
                        overlapTimeCollision++;
                    }
                }
            }

            //add abandoned sessions to overlapTimeModuleList
            for (int i = 0; i < (overlapTimeCollision * 2); i++)
            {
                var anotherSameSession = returnAnotherSameSession(overlapTimeModuleList[i]);
                overlapTimeModuleList.Add(anotherSameSession);
            }

            //count total non-lecture session
            //foreach(Module e1 in tempModuleList)
            //{
            //    foreach(WebpageTermTimetable e2 in tempModuleDetailsList)
            //    {
            //        if(e1.ModuleFullName == e2.ModuleFullName && e2.ModuleShortName.Last() != '1')
            //        {
            //            SessionProperty newSp = new SessionProperty();

            //            if (e2.SessinonProperty == "Practical")
            //                practical++;
            //            else if (e2.SessinonProperty == "Tutorial")
            //                tutorial++;
            //            else if (e2.SessinonProperty == "Workshop")
            //                workshop++;

            //            spCount.Add(newSp);
            //        }
            //    }
            //}

            //copy overlapTimeList
            foreach (WebpageTermTimetable e1 in overlapTimeModuleList)
            {
                overlapTimeModuleList2.Add(e1);
            }


            //create general timetable templates
            for (int i = 0; i <= overlapTimeCollision; i++)
            {
                //List<WebpageTermTimetable> generalTTTList = new List<WebpageTermTimetable>();
                TTTemplateList generalTTTemplateList = new TTTemplateList();

                foreach (WebpageTermTimetable e1 in tempModuleDetailsList)
                {
                    if (e1.ModuleShortName.Last() == '1')
                    {
                        generalTTTemplateList.TttemPlateList.Add(e1);
                    }
                }

                if (overlapTimeModuleList.Count() != 0)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        generalTTTemplateList.TttemPlateList.Add(overlapTimeModuleList[j]);
                    }
                    overlapTimeModuleList.RemoveAt(0);
                    overlapTimeModuleList.RemoveAt(0);
                }

                newtttlist.Add(generalTTTemplateList);
                //MessageBox.Show("test");
            }

            //......................................................................
            //collect non-lecture session and remove overlap time sessions
            //firstly, collect non-lecture sessions
            //RemoveOverlapTimeSessions(tempModuleDetailsList);
            foreach (WebpageTermTimetable e1 in tempModuleDetailsList)
            {
                if (e1.ModuleShortName.Last() != '1')
                {
                    tempNonOverlapTimeSessionList.Add(e1);
                }
            }

            //remove the overlapTime Sessions
            foreach (WebpageTermTimetable e1 in tempNonOverlapTimeSessionList)
            {
                tempNonOverlapTimeSessionList2.Add(e1);
            }

            if (overlapTimeCollision != 0)
            {
                foreach (WebpageTermTimetable e1 in tempNonOverlapTimeSessionList2)
                {
                    foreach (WebpageTermTimetable e2 in overlapTimeModuleList2)
                    {
                        if (e1.ModuleShortName == e2.ModuleShortName)
                        {
                            tempNonOverlapTimeSessionList.Remove(e1);
                        }
                    }
                }
            }

            //count how many practical, tutorial, and workshop of a module
            foreach (Module e1 in tempModuleList)
            {
                SessionProperty newSp = new SessionProperty();
                newSp.ModuleFullName = e1.ModuleFullName;

                foreach (WebpageTermTimetable e2 in tempNonOverlapTimeSessionList)
                {
                    if (e2.ModuleFullName == e1.ModuleFullName)
                    {
                        if (e2.SessinonProperty == "Practical")
                        {
                            newSp.Practical++;
                        }
                        else if (e2.SessinonProperty == "Tutorial")
                        {
                            newSp.Tutorial++;
                        }
                        else if (e2.SessinonProperty == "Workshop")
                        {
                            newSp.Workshop++;
                        }
                    }
                }

                spList.Add(newSp);
            }



            //.....................................................................
            //split studentList to different groups
            foreach (SessionProperty e1 in spList)
            {
                //SessionGroups newSg = new SessionGroups();
                var sessionCount = sgList.Count();
                int practicalCount = 0, tutorialCount = 0, workshopCount = 0;

                if (e1.Practical != 0)
                {
                    foreach (WebpageTermTimetable e2 in tempNonOverlapTimeSessionList)
                    {
                        if (e2.SessinonProperty == "Practical" && e2.ModuleFullName == e1.ModuleFullName)
                        {
                            SessionGroups newSg = new SessionGroups();
                            newSg.NonLectureSession = e2;
                            sgList.Add(newSg);
                        }
                    }

                    //int i = sessionCount;

                    for (int i = 0; i < e1.Practical; i++)
                    {
                        if (e1.Practical != 1)
                        {
                            sgList[practicalCount + sessionCount].StudentGroup = returnSplitStudentList(e1.Practical, i, tempStudentList);
                        }
                        else
                        {
                            sgList[practicalCount + sessionCount].StudentGroup = tempStudentList;
                        }

                        practicalCount++;
                    }
                }

                if (e1.Tutorial != 0)
                {
                    foreach (WebpageTermTimetable e2 in tempNonOverlapTimeSessionList)
                    {
                        if (e2.SessinonProperty == "Tutorial" & e2.ModuleFullName == e1.ModuleFullName)
                        {
                            SessionGroups newSg = new SessionGroups();
                            newSg.NonLectureSession = e2;
                            sgList.Add(newSg);
                        }
                    }

                    //int i = e1.Practical;

                    for (int i = 0; i < e1.Tutorial; i++)
                    {
                        if (e1.Tutorial != 1)
                        {
                            sgList[tutorialCount + practicalCount + sessionCount].StudentGroup = returnSplitStudentList(e1.Tutorial, i, tempStudentList);
                        }
                        else
                        {
                            sgList[tutorialCount + practicalCount + sessionCount].StudentGroup = tempStudentList;
                        }

                        tutorialCount++;
                    }
                }

                if (e1.Workshop != 0)
                {
                    foreach (WebpageTermTimetable e2 in tempNonOverlapTimeSessionList)
                    {
                        if (e2.SessinonProperty == "Workshop" & e2.ModuleFullName == e1.ModuleFullName)
                        {
                            SessionGroups newSg = new SessionGroups();
                            newSg.NonLectureSession = e2;
                            sgList.Add(newSg);
                        }
                    }

                    //int i = e1.Practical + e1.Tutorial;

                    for (int i = 0; i < e1.Workshop; i++)
                    {
                        if (e1.Workshop != 1)
                        {
                            sgList[workshopCount + tutorialCount + practicalCount + sessionCount].StudentGroup = returnSplitStudentList(e1.Workshop, i, tempStudentList);
                        }
                        else
                        {
                            sgList[workshopCount + tutorialCount + practicalCount + sessionCount].StudentGroup = tempStudentList;
                        }
                        workshopCount++;
                    }
                }

                //MessageBox.Show("test");
            }



            //split studentList to newtttlist
            if (overlapTimeCollision != 0)
            {
                int count = 0;

                foreach (TTTemplateList e1 in newtttlist)
                {
                    e1.StudentList = returnSplitStudentList(overlapTimeCollision + 1, count, tempStudentList);
                    count++;
                }
            }

            //data.WriteSgFile();
            //data.WriteTemplate();
            //data.WriteSystemList();
            //copy newtttlist and newSg
            foreach (TTTemplateList e1 in newtttlist)
            {
                SystemList.TemplateList.Add(e1);
            }

            foreach (SessionGroups e1 in sgList)
            {
                SystemList.SessionGroupList.Add(e1);
            }
            //MessageBox.Show("test");
            data.WriteSgFile();
            data.WriteTemplate();
        }