//private static int n { get; set; } = 0;
        public static List <OngoingClass>[] SplitToTimeTablePeriod()
        {
            int hallCount = Halls.ListOfHalls().Count;

            var OngoingClassesy = GenerateTimetable.GetHallAvailabilityReturnOngoingCourses();

            #region Was Used to mark/set the Periods for the Dynamic Tables, because of so many Bugs(The School system has just 46 periods so....)
            //n = OngoingClassesy.Count / hallCount;
            //if (OngoingClassesy.Count % hallCount > 0)
            //{
            //    n += 1;
            //}
            #endregion
            int counter = 0;
            List <OngoingClass>[] period = new List <OngoingClass> [46];


            int i = 0, sum = 0;
            int count12 = 0;
            do
            {
                //period = new List<OngoingClass>[n];

                // int sum = 0;

                period[counter] = new List <OngoingClass>();

                while (period[counter].Count <= (hallCount / 2) - 1)
                {
                    #region Code That Ensures the Halls Doesnt Clash (Commented... Tiny Big Bug)
                    bool checkVal = period[counter].Exists(x => x.Location == OngoingClassesy[i].Location);
                    if (checkVal == true)
                    {
                        // period[counter].Remove(OngoingClassesy[i]);
                        try
                        {
                            period[counter + 1] = new List <OngoingClass>
                            {
                                //period[counter].Remove(OngoingClassesy[i]);
                                OngoingClassesy[i]
                            };

                            //while (!(n > hallCount * 10 * 5))
                            //{
                            //    n += 1;
                            //}
                        }
                        catch (Exception)
                        {
                            return(period);
                        }
                    }
                    else
                    {
                        period[counter].Add(OngoingClassesy[i]);
                    }
                    #endregion


                    count12++;
                    if (count12 == hallCount - 1)
                    {
                        sum    += i + 1;
                        i       = sum;
                        count12 = 0;



                        //i = 0;
                    }
                    i++;

                    if (i >= OngoingClassesy.Count)
                    {
                        i -= i;
                        //break;
                    }
                    sum = 0;
                    //period[counter].Add(OngoingClassesy[i]);
                }
                counter++;
            } while (counter < period.Length);

            return(period);
        }
Exemple #2
0
        public static List <OngoingClass> GetHallAvailabilityReturnOngoingCourses()
        {
            //List of ALL Courses

            //var listOfCourses = Courses.SendList ; OLD CODE
            var listOfCourses = ImportCourses.ListOfCourses();
            // return listOfCourses;
            //List of All Halls
            var listOfHalls  = Halls.ListOfHalls();
            var onGoingClass = OngoingClass.OngoingCourses;


            #region First randomize the List of Courses
            //This is Creation of a Random List of Courses
            List <ImportCourses> randomCourseList = new List <ImportCourses>();
            //Call the Random Object
            Random random = new Random();
            //varable Random index
            int randomIndex = 0;

            //loop
            while (listOfCourses.Count > 0)
            {
                randomIndex = random.Next(0, listOfCourses.Count);
                randomCourseList.Add(listOfCourses[randomIndex]);
                listOfCourses.RemoveAt(randomIndex);
            }
            #endregion

            #region Looping thru the Randomized Courses and Adding them to the Ongoing Courses


            //i have no idea why i wrote this, or what it does
            int checkHallAvailability = listOfHalls.FindIndex(i => i.Availability == true);
            //truthfully --- signed Ojo Emmanuel

            for (int i = 0; i < randomCourseList.Count; i++)
            {
                //loop thru a count of the random list

                foreach (var hall in listOfHalls)
                {
                    //loop thru the available halls

                    foreach (var course in randomCourseList)
                    {
                        if (course.Status.ToUpper() == "C")
                        {
                            course.Size = "BIG";
                        }
                        else if (course.Status.ToUpper() == "E")
                        {
                            course.Size = "SMALL";
                        }
                        else if (course.Status.ToUpper() == "R")
                        {
                            course.Size = "MEDIUM";
                        }
                        else
                        {
                            course.Size = "unknown";
                        }
                        //loop thru the list of courses
                        if (hall.Availability == true && course.Size.ToUpper() == hall.Capacity.ToUpper())
                        {
                            bool checkVal = onGoingClass.Exists(x => x.LectureCode == course.Name.ToUpper());
                            //var check = onGoingClass.Find(x => x.LectureCode == course.Name);
                            //{
                            ////add the merged list to the ongoing class
                            //onGoingClass.Add(new OngoingClass { LectureCode = course.Name.ToUpper(), Location = hall.Number });
                            //hall.Availability = false;

                            //}

                            if ((checkVal == true))
                            {
                                onGoingClass.Remove(new OngoingClass {
                                    LectureCode = course.Name.ToUpper(), Location = hall.Number
                                });
                            }
                            else
                            {
                                onGoingClass.Add(new OngoingClass {
                                    LectureCode = course.Name.ToUpper(), Location = hall.Number
                                });
                                hall.Availability = false;
                            }
                        }
                    }

                    foreach (var Ahall in listOfHalls)
                    {
                        Ahall.Availability = true;
                    }
                }
            }
            #endregion
            return(onGoingClass);

            // return onGoingClass;
        }
Exemple #3
0
        //private void Btn_BrowseFileHall_Click(object sender, RoutedEventArgs e)
        //{

        //}

        private void Btn_AddBrowseFile_Click(object sender, RoutedEventArgs e)
        {
            var status = cmb_FileCategory.SelectionBoxItem.ToString();
            var txt    = txtBox_FileName.Text;

            if (status == "" || txt == "")
            {
                MessageBox.Show("Select File and Choose File Category");
            }
            else
            {
                if (status == "Halls")
                {
                    var sendFileAndGetStatus = Halls.GetOleDbConnectionSucess(FileNameAndPath);
                    if (sendFileAndGetStatus == null)
                    {
                        MessageBox.Show("Something Wrong With File");
                    }
                    else
                    {
                        var halls = Halls.ListOfHalls();
                        if (halls == null)
                        {
                            MessageBox.Show("Table Name Error:\nEnsure Sheet Name is Renamed to File Name \nEnsure All Editing is Completed", "Warning");
                        }
                        else
                        {
                            CountHall = halls.Count;
                            list_availableHall.ItemsSource = halls;
                            // list_availableCourses.ItemsSource = halls;
                        }
                    }
                }
                else
                {
                    var sendFileAndGetStatus = ImportCourses.GetOleDbConnectionSucess(FileNameAndPath);
                    if (sendFileAndGetStatus == null)
                    {
                        MessageBox.Show("Something Wrong With File");
                    }
                    else
                    {
                        var courses = ImportCourses.ListOfCourses();
                        if (courses == null)
                        {
                            MessageBox.Show("Table Name Error \n Ensure Sheet Name is Renamed to File Name", "Warning");
                        }
                        else
                        {
                            #region Displays Available Courses Count
                            CountCourse = courses.Count;

                            lbl_availableCourses.Content = $"Registered Courses ({CountCourse})";

                            #endregion
                            list_availableCourses.ItemsSource = courses;
                        }
                    }
                }
            }

            if (CountCourse > 0 && CountHall > 0)
            {
                btn_GenerateTimeTable.IsEnabled = true;
            }
        }