public Schedule_Search(String label, String crn, String subject, String number, String hours, String title, String instructor, DropOption semester, DropOption session, DropOption campus, DropOption dist, DropOption col, DropOption dept, DropOption status, DropOption ssts_code, DropOption crse_levl, DropOption time1, DropOption ugr, bool checkFri1, bool checkFri2, bool checkMon1, bool checkMon2, bool checkSat1, bool checkSat2, bool checkSun1, bool checkSun2, bool checkThurs1, bool checkThurs2, bool checkTues1, bool checkTues2, bool checkWed1, bool checkWed2) { Label = label; CRN = crn; Subject = subject; Number = number; Hours = hours; Title = title; Instructor = instructor; Semester = semester; Session = session; Campus = campus; Dist = dist; Col = col; Dept = dept; Status = status; Ssts_code = ssts_code; Crse_levl = crse_levl; Time1 = time1; Ugr = ugr; CheckFri1 = checkFri1; CheckFri2 = checkFri2; CheckMon1 = checkMon1; CheckMon2 = checkMon2; CheckSat1 = checkSat1; CheckSat2 = checkSat2; CheckSun1 = checkSun1; CheckSun2 = checkSun2; CheckThurs1 = checkThurs1; CheckThurs2 = checkThurs2; CheckTues1 = checkTues1; CheckTues2 = checkTues2; CheckWed1 = checkWed1; CheckWed2 = checkWed2; }
/* Load the schedule search website, pull in the options from the website for the various dropdown menus, * then fill in the combo boxes for these menus as well as the lists of value pairs (DropOptions) */ public void InitializeLists() { UTF8Encoding objUTF8; String htmlText =""; // Try to load the staff schedule search website try { webClient = new WebClient(); const string strUrl = "http://www.registrar.usf.edu/ssearch/staff/staff.php"; byte[] reqHTML; reqHTML = webClient.DownloadData(strUrl); objUTF8 = new UTF8Encoding(); htmlText = objUTF8.GetString(reqHTML); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Exit(); } // Various Regex's to get the various options and value pairs from the website // Would love to have direct database access instead of having to use these // Tried to use a HTML Parser, but it was abysmally slow compared to loading the page // and using regex Regex Semester = new Regex("(?s)<SELECT NAME=\"P_SEMESTER\">(.+?)</SELECT>"); Regex SemesterOption = new Regex("(?m)(?i)<OPTION VALUE=\"(\\d+)\"[^>]*>(.+?)(<.+)?\n|\r$"); Regex Session = new Regex("(?s)<SELECT NAME=\"P_SESSION\">(.+?)</SELECT>"); Regex SessionOption = new Regex("(?m)<OPTION VALUE=\"([A-z])\">(.+)\n|\r$"); Regex Campus = new Regex("(?s)<SELECT NAME=\"P_CAMPUS\">(.+?)</SELECT>"); Regex CampusOption = new Regex("(?m)<OPTION VALUE=\"([0-9A-z])\">(.+)\n|\r$"); Regex Dist = new Regex("(?s)<SELECT NAME=\"P_DIST\">(.+?)</SELECT>"); Regex DistOption = new Regex("(?m)<OPTION VALUE=\"(\\d)\">(.+)\n|\r$"); Regex Col = new Regex("(?s)<SELECT NAME=\"P_COL\">(.+?)</SELECT>"); Regex ColOption = new Regex("(?m)<OPTION VALUE=\"([A-Z][A-Z])\">(.+)\n|\r$"); Regex Dept = new Regex("(?s)<SELECT NAME=\"P_DEPT\">(.+?)</SELECT>"); Regex DeptOption = new Regex("(?m)<OPTION VALUE=\"([A-Z]{3})\">(.+)\n|\r$"); Regex Status = new Regex("(?s)<SELECT NAME=\"p_status\">(.+?)</SELECT>"); Regex StatusOption = new Regex("(?m)<OPTION VALUE=\"([A-Z])\">(.+)\n|\r$"); Regex Ssts_code = new Regex("(?s)<SELECT NAME=\"p_ssts_code\">(.+?)</SELECT>"); Regex Ssts_codeOption = new Regex("(?m)<OPTION VALUE=\"([A-Z])\">(.+)\n|\r$"); Regex Crse_levl = new Regex("(?s)<SELECT NAME=\"P_CRSE_LEVL\">(.+?)</SELECT>"); Regex Crse_levlOption = new Regex("(?m)<OPTION VALUE=\"([A-Z]{2})\">(.+)\n|\r$"); Regex Time1 = new Regex("(?s)<SELECT NAME=\"P_TIME1\">(.+?)</SELECT>"); Regex Time1Option = new Regex("(?m)(?i)<OPTION VALUE=(\'[0-9]{4}\')>(.+)</option>$"); Regex Ugr = new Regex("(?s)<SELECT NAME=\"P_UGR\">(.+?)</SELECT>"); Regex UgrOption = new Regex("(?m)<OPTION VALUE=\"([0-9A-z]{4})\">(.+)\n|\r$"); blankOption = new DropOption(); blankOption.description = ""; blankOption.value = ""; /* The following loops use the Regex's defined above to first search for each option name, * then to pull in the various values for that option. For each option it creates a list * and creates a Dropoption value pair, for later submitting to the website. * I probably should have used dictionaries, but didn't think to do so at the time. */ // Pull in the list of semesters SemesterList = new List<DropOption>(); foreach (Match m in Semester.Matches(htmlText)) { foreach (Match n in SemesterOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboTerm.Items.Add(option); SemesterList.Add(option); } } // Pull in the summer sessions SessionList = new List<DropOption>(); foreach (Match m in Session.Matches(htmlText)) { foreach (Match n in SessionOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboSession.Items.Add(option); SessionList.Add(option); } } // Pull in the list of campuses CampusList = new List<DropOption>(); foreach (Match m in Campus.Matches(htmlText)) { foreach (Match n in CampusOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboCampus.Items.Add(option); SessionList.Add(option); } } // Pull in the distance learning options DistanceList = new List<DropOption>(); foreach (Match m in Dist.Matches(htmlText)) { foreach (Match n in DistOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboDistanceLearning.Items.Add(option); DistanceList.Add(option); } } // Pull in list of colleges CollegeList = new List<DropOption>(); foreach (Match m in Col.Matches(htmlText)) { foreach (Match n in ColOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboCollege.Items.Add(option); CollegeList.Add(option); } } // List of departments DepartmentList = new List<DropOption>(); foreach (Match m in Dept.Matches(htmlText)) { foreach (Match n in DeptOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboDepartment.Items.Add(option); DepartmentList.Add(option); } } // List of course statuses (usually Open or Closed) StatusList = new List<DropOption>(); foreach (Match m in Status.Matches(htmlText)) { foreach (Match n in StatusOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboStatus.Items.Add(option); StatusList.Add(option); } } // List of secondary course statuses Status2List = new List<DropOption>(); foreach (Match m in Ssts_code.Matches(htmlText)) { foreach (Match n in Ssts_codeOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboStatus2.Items.Add(option); Status2List.Add(option); } } // list of course level (usually Undergraduate, Graduate) LevelList = new List<DropOption>(); foreach (Match m in Crse_levl.Matches(htmlText)) { foreach (Match n in Crse_levlOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboLevel.Items.Add(option); LevelList.Add(option); } } // List of available begin times TimeList = new List<DropOption>(); foreach (Match m in Time1.Matches(htmlText)) { foreach (Match n in Time1Option.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboTime.Items.Add(option); TimeList.Add(option); } } // List of undergraduate requirements UGRList = new List<DropOption>(); foreach (Match m in Ugr.Matches(htmlText)) { foreach (Match n in UgrOption.Matches(m.Groups[1].Value.ToString())) { DropOption option = new DropOption(); option.value = n.Groups[1].Value.ToString(); option.description = n.Groups[2].Value.ToString(); comboUGR.Items.Add(option); UGRList.Add(option); } } // Remove the default option at top of certain combo boxes(causes a weird problem) comboCampus.Items.RemoveAt(0); comboCollege.Items.RemoveAt(0); comboDepartment.Items.RemoveAt(0); comboDistanceLearning.Items.RemoveAt(0); comboLevel.Items.RemoveAt(0); comboSession.Items.RemoveAt(0); comboStatus.Items.RemoveAt(0); comboStatus2.Items.RemoveAt(0); comboTerm.Items.RemoveAt(0); comboTime.Items.RemoveAt(0); comboUGR.Items.RemoveAt(0); // Create a "blank" option at the top of each combo box, default option comboCampus.Items.Insert(0, blankOption); comboCollege.Items.Insert(0, blankOption); comboDepartment.Items.Insert(0, blankOption); comboDistanceLearning.Items.Insert(0, blankOption); comboLevel.Items.Insert(0, blankOption); comboSession.Items.Insert(0, blankOption); comboStatus.Items.Insert(0, blankOption); comboStatus2.Items.Insert(0, blankOption); comboTerm.Items.Insert(0, blankOption); comboTime.Items.Insert(0, blankOption); comboUGR.Items.Insert(0, blankOption); comboCampus.SelectedIndex = 0; comboCollege.SelectedIndex = 0; comboDepartment.SelectedIndex = 0; comboDistanceLearning.SelectedIndex = 0; comboLevel.SelectedIndex = 0; comboSession.SelectedIndex = 0; comboStatus.SelectedIndex = 1; // Default to selected Open comboStatus2.SelectedIndex = 1; // Default to selected Active comboTerm.SelectedIndex = 0; // Retrieve current date, and use to pick the term, as the website is often // several terms behind String timeString; int timeYear = DateTime.Now.Year; int month = DateTime.Now.Month; // If between January and May, choose summer if (month <= 5) { timeString = timeYear.ToString() + "05"; } // If between June and August, inclusive, choose Fall else if (month <= 08) { timeString = timeYear.ToString() + "08"; } // Otherwise, choose Spring of the next year else { timeYear++; timeString = timeYear.ToString() + "01"; } // find the term option that matches the chosen term foreach(DropOption checkTime in comboTerm.Items){ if (checkTime.value == timeString) comboTerm.SelectedItem = checkTime; } termIndex = comboTerm.SelectedIndex; // save the chosen term for later clearing comboTime.SelectedIndex = 0; comboUGR.SelectedIndex = 0; // Create a new list of schedules, as the program is done initializing Schedule = new List<Schedule_Record>(); initialized = true; }