Example #1
0
        //------------------------------------------------------------------------------
        // WARNING!! --Please Read SPECIAL NOTE below--
        // Runs a query which pulls all the courses that exist in CourseTime. Conceptually,
        // this creates a list of every class that has been offered. Details like the
        // Course ID, the time the class starts, the time the class ends, days offered,
        // quarter offered, and the section ID or collected to their respective
        // counterparts. This provides a means to reduce the amount of objects being handled
        // and can allow implmentation of day-specific and time-specific preferences.
        //
        // Various checks prevent duplication of machines.
        //
        // SPECIAL NOTE: If we have the means to, and are required to do so, of
        //               implementing different course offerings on a yearly basis
        //               this is where we would need to change it. DOING SO WOULD MEAN
        //               THAT THE FUNCTION, NORMALIZEMACHINES(), WOULD BE INCOMPATIBLE
        //               WITH THIS ALGORITHM.
        //------------------------------------------------------------------------------
        protected void InitMachines()
        {
            // This query returns ~2000 rows of course info. We pre-process a lot of info
            // with adding jobs and decidingg where to place maachinens/jobs.

            // If we know the school ID. Then we have what looks like an average of 300 classes less.
            //string oldquery = "select CourseID, StartTimeID, EndTimeID, DayID, QuarterID, SectionID from CourseTime order by CourseID ASC;";
            string query = "SELECT ct.CourseID, StartTimeID, EndTimeID, DayID, QuarterID, ct.SectionID, c.MaxCredit, c.DepartmentID " +
                           "FROM CourseTime as ct " +
                           "LEFT JOIN Course as c ON c.CourseID = ct.CourseID " +
                           "ORDER BY ct.CourseID ASC";
            DataTable dt      = DBPlugin.ExecuteToDT(query);
            int       dt_size = dt.Rows.Count - 1;
            DataRow   dr      = dt.Rows[dt_size];

            //Temporary Machine Variables
            Machine dummyMachine   = new Machine();
            DayTime dummyDayTime   = new DayTime();
            int     course         = 0;
            int     start          = 0;
            int     end            = 0;
            int     day            = 0;
            int     quarter        = 0;
            int     section        = 0;
            int     credits        = 0;
            int     currentCourse  = (int)dr.ItemArray[0]; //USED FOR PEAKING THE NEXT ROW
            int     currentQuarter = (int)dr.ItemArray[4]; //USED FOR PEAKING THE NEXT ROW
            int     currentSection = (int)dr.ItemArray[5]; //USED FOR PEAKING THE NEXT ROW

            //Treats the information gained from the query like a FILO object
            while (dt_size >= 0)
            {
                dr = dt.Rows[dt_size];
                //check for null values
                if (dr.ItemArray[0] == DBNull.Value || dr.ItemArray[1] == DBNull.Value ||
                    dr.ItemArray[2] == DBNull.Value || dr.ItemArray[3] == DBNull.Value ||
                    dr.ItemArray[4] == DBNull.Value || dr.ItemArray[5] == DBNull.Value)
                {
                    dt_size--; //IF any portion is null, then the row is discarded entirely.
                    continue;
                }
                //going to have to do the same with year probably; Andrue Note: Most likely the case
                course  = (int)dr.ItemArray[0];
                start   = (int)dr.ItemArray[1];
                end     = (int)dr.ItemArray[2];
                day     = (int)dr.ItemArray[3];
                quarter = (int)dr.ItemArray[4];
                section = (int)dr.ItemArray[5];
                credits = (int)dr.ItemArray[6];
                var deptId = (int)dr.ItemArray[7];

                //same course but different section OR different quarter is a different machine
                //different course is a different machine
                if ((currentCourse == course && (currentSection != section || currentQuarter != quarter)) || (currentCourse != course))
                {
                    dummyMachine   = new Machine(); //creates a new machine to be used
                    currentCourse  = (int)dr.ItemArray[0];
                    currentQuarter = (int)dr.ItemArray[4];
                    currentSection = (int)dr.ItemArray[5];
                }

                dummyDayTime = new DayTime();
                dummyDayTime.SetDayTime(day, start, end);
                dummyMachine.AddDayTime(dummyDayTime);
                dummyMachine.SetQuarter(quarter);

                //we add a new machine when we peek to the next row and see
                //(different course) OR (same course and (different section OR dif qtr))
                //Andrue Note: Maybe isolate these arguments into helper functions for ease-of-use?
                //if (itself(?)) OR (not same course) OR (IS course but NOT SAME Section OR Quarter)
                int next = dt_size - 1;
                if (dt_size == 0 || ((int)dt.Rows[next].ItemArray[0] != currentCourse ||
                                     ((int)dt.Rows[next].ItemArray[0] == currentCourse &&
                                      ((int)dt.Rows[next].ItemArray[5] != currentSection) ||
                                      (int)dt.Rows[next].ItemArray[4] != currentQuarter)))
                {
                    addMachine(dummyMachine, new Job(course, credits, false));
                }
                dt_size--;
            }
        }