Example #1
0
        //[FUNCTION - InputToMainButton_Click]
        //Begins irreversible course database creation from excel file
        private void InputToMainButton_Click(object sender, EventArgs e)
        {
            //[USER INPUT VALIDATION > everything needs to be completed/selected and excel file loaded]
            if (CheckInputCompletion() && !BackgroundWorkerCourses.IsBusy)
            {
                //Remove all input error labels
                FirstNameNeedLabel.Visible  = false;
                LastNameNeedLabel.Visible   = false;
                TermNeedLabel.Visible       = false;
                LoadingCoursesPanel.Visible = true;

                //Gather all input into userData object
                userData.setFirstName(FirstNameTextBox.Text);
                userData.setLastName(LastNameTextBox.Text);
                if (TermComboBox.Text == "Fall")
                {
                    userData.setTermInterest("FA");
                }
                else if (TermComboBox.Text == "Spring")
                {
                    userData.setTermInterest("SP");
                }
                else
                {
                    userData.setTermInterest("JA");
                }

                //Set initial progress view to zero/nothing-done
                StartCalcPB();

                //PARTIAL INSTRUCTION FROM LINK (background worker)
                //https://www.youtube.com/watch?v=G3zRhhGCJJA
                //Begin worker (allows for loading bar to update)
                BackgroundWorkerCourses.RunWorkerAsync();
            }
            else
            {
                DisplayInputErrors();
            }
        }
Example #2
0
        //[FUNCTION - ProcessCourseData]
        //Goes through each row in selected excel spreadsheet dynamically populating the course list
        private void ProcessCourseData()
        {
            curCalcNum = 0;
            while (excelReader.Read())
            {
                //Skip row if credit info is missing
                if (Convert.ToInt32(excelReader.GetDouble(12)) == 0)
                {
                    continue;
                }

                //Update progress every 200 rows
                if (curCalcNum % 200 == 0)
                {
                    precentComplete = (curCalcNum / totalCalcNum) * 100f;
                    BackgroundWorkerCourses.ReportProgress((int)precentComplete);
                }

                //Selection that decides whether the current row contains a unique course or section
                if (!courses.Exists(s => s.getCourseName() == excelReader.GetString(6) && s.getAbrvCourseName() == TruncatedCourseID()))
                {
                    // SingleCourse constructor inputs initial course data
                    courses.Add(new SingleCourse
                                (
                                    excelReader.GetString(6),
                                    TruncatedCourseID(),
                                    GetCourseLevel(),
                                    excelReader.GetString(3),
                                    Convert.ToInt32(excelReader.GetDouble(12)),
                                    new List <string> {
                        (excelReader.GetString(2))
                    },
                                    new List <string>(GetRowInstructNames()),
                                    new List <SingleSection> {
                        (new SingleSection {
                        })
                    }
                                ));

                    //Find index of last added course (above)
                    int courseIndex = courses.Count() - 1;

                    //Updates the first section info for that course
                    courses[courseIndex].getSections()[0].setTerm(excelReader.GetString(2));
                    courses[courseIndex].getSections()[0].setID(excelReader.GetString(5));
                    courses[courseIndex].getSections()[0].setCourseName(excelReader.GetString(6));
                    courses[courseIndex].getSections()[0].setStartTimes(SplitCellIntoList(17, ", ", " NA"));
                    courses[courseIndex].getSections()[0].setStopTimes(SplitCellIntoList(18, ", ", " NA"));
                    courses[courseIndex].getSections()[0].setMeetDays(SplitCellIntoList(19, ",", "NA"));
                    courses[courseIndex].getSections()[0].FormatTimeToMinutes();
                    courses[courseIndex].getSections()[0].setInstructFirstN(SplitCellIntoList(10, ", ", ""));
                    courses[courseIndex].getSections()[0].setInstructLastN(SplitCellIntoList(9, ", ", "NA"));
                    sectionIDs.Add(excelReader.GetString(5));
                    courseIDs.Add(TruncatedCourseID() + "|" + excelReader.GetString(6));
                }
                else if (DetermineSectionNeed(courseIDs.IndexOf(TruncatedCourseID() + "|" + excelReader.GetString(6))))
                {
                    //Collects info on where to put the unique section
                    int  courseIndex      = courseIDs.IndexOf(TruncatedCourseID() + "|" + excelReader.GetString(6));
                    int  sectionIndex     = courses[courseIndex].getSections().Count();
                    bool termRecorded     = false;
                    bool instructRecorded = false;

                    //Add new term avaliability to course if the section's term is unique
                    foreach (var availTerm in courses[courseIndex].getTermsAvailable())
                    {
                        if (availTerm == excelReader.GetString(2))
                        {
                            termRecorded = true;
                        }
                    }
                    if (!termRecorded)
                    {
                        courses[courseIndex].getTermsAvailable().Add(excelReader.GetString(2));
                    }

                    //Add unique instructors to course object if needed
                    List <string> currentInstructs = SplitCellIntoList(9, ",", "NA");
                    foreach (var course in courses)
                    {
                        foreach (var section in course.getSections())
                        {
                            foreach (var instruct in section.getInstructLastN())
                            {
                                foreach (var currentInstruct in currentInstructs)
                                {
                                    if (currentInstruct == instruct)
                                    {
                                        instructRecorded = true;
                                    }
                                }
                            }
                        }
                    }
                    if (!instructRecorded)
                    {
                        List <string> lastNames    = SplitCellIntoList(9, ", ", "NA");
                        List <string> firstNames   = SplitCellIntoList(10, ", ", "NA");
                        int           indexCounter = 0;
                        foreach (var lastName in lastNames)
                        {
                            if (firstNames.Count() == 1 && firstNames[0] == "NA")
                            {
                                courses[courseIndex].getInstructAvailable().Add(lastName);
                            }
                            else if (firstNames.Count() == 1)
                            {
                                courses[courseIndex].getInstructAvailable().Add(firstNames[0] + " " + lastName);
                            }
                            else
                            {
                                courses[courseIndex].getInstructAvailable().Add(firstNames[indexCounter] + " " + lastName);
                            }
                            indexCounter++;
                        }
                        indexCounter = 0;
                    }

                    //Creates a new singleSection object in the found course
                    courses[courseIndex].getSections().Add(new SingleSection {
                    });
                    //Sets up variables of the unique section
                    courses[courseIndex].getSections()[sectionIndex].setTerm(excelReader.GetString(2));
                    courses[courseIndex].getSections()[sectionIndex].setID(excelReader.GetString(5));
                    courses[courseIndex].getSections()[sectionIndex].setCourseName(excelReader.GetString(6));
                    courses[courseIndex].getSections()[sectionIndex].setStartTimes(SplitCellIntoList(17, ", ", " NA"));
                    courses[courseIndex].getSections()[sectionIndex].setStopTimes(SplitCellIntoList(18, ", ", " NA"));
                    courses[courseIndex].getSections()[sectionIndex].setMeetDays(SplitCellIntoList(19, ",", "NA"));
                    courses[courseIndex].getSections()[sectionIndex].FormatTimeToMinutes();
                    courses[courseIndex].getSections()[sectionIndex].setInstructFirstN(SplitCellIntoList(10, ", ", ""));
                    courses[courseIndex].getSections()[sectionIndex].setInstructLastN(SplitCellIntoList(9, ", ", "NA"));

                    sectionIDs.Add(excelReader.GetString(5));
                }
                curCalcNum++;
            }
        }