private void displayListView(int tabPage)
        {
            SavingAndReading data = new SavingAndReading();

            //data.ReadSystemList();
            //displayStudentListView();
            //displayLecturerListView();
            switch (tabPage)
            {
            case 0:
                data.ReadStudentFile();
                displayStudentListView();
                break;

            case 1:
                data.ReadLecturerFile();
                displayLecturerListView();
                break;

            case 2:
                data.ReadRoomFile(data.RoomFilename);
                displayRoomListView();
                break;
            }
        }
        public bool uniqueIDChecking(int id)
        {
            SavingAndReading data = new SavingAndReading();

            data.ReadStudentFile();

            for (int i = 0; i < SystemList.StudentList.Count(); i++)
            {
                if (SystemList.StudentList[i].Id == id)
                {
                    //Console.WriteLine("The ID you entered: " + newStudent.Id + " is existent!");
                    //enterID(newStudent);
                    return(false);
                }
            }

            return(true);
        }
        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();
        }