public TestClass()
 {
     this.courselist   = new Database();
     this.courseSearch = new SearchQuery(courselist);
     this.results      = new SearchResults();
 }
Beispiel #2
0
        // When a query is entered into the text field and enter is pressed, the database will be searched
        private void searchBox_Enter(object sender, KeyPressEventArgs e)
        {
            string noResults = "";

            metroBar.Value = 0;
            metroBar.Update();
            if (e.KeyChar == (char)Keys.Return)
            {
                string searchString = this.searchBox.Text;
                if (searchType == 0)
                {
                    this.results = this.courseSearch.genericSearch(searchString);
                }
                else if (searchType == 1)
                {
                    this.results = this.courseSearch.searchByCode(searchString);
                }
                else if (searchType == 2)
                {
                    this.results = this.courseSearch.searchByName(searchString);
                }
                else if (searchType == 3)
                {
                    this.searchBox.Text = "";
                    searchString        = "";
                    string searchTime = startTimeBox.Text;
                    if (mondayCheckBox.Checked)
                    {
                        searchString += "M,";
                    }
                    if (tuesdayCheckBox.Checked)
                    {
                        searchString += "T,";
                    }
                    if (wednesdayCheckBox.Checked)
                    {
                        searchString += "W,";
                    }
                    if (thursdayCheckBox.Checked)
                    {
                        searchString += "R,";
                    }
                    if (fridayCheckBox.Checked)
                    {
                        searchString += "F";
                    }
                    string[] splitResult = searchTime.Split(':');
                    int      hour        = 0;
                    if (String.IsNullOrWhiteSpace(splitResult[0]) || !int.TryParse(splitResult[0], out hour))
                    {
                        searchTime = "";
                    }
                    else if (PMCheckBox1.Checked)
                    {
                        hour      += 12;
                        searchTime = Convert.ToString(hour) + ":";
                        if (splitResult.Length > 1 && !String.IsNullOrWhiteSpace(splitResult[1]))
                        {
                            searchTime += splitResult[1];
                        }
                        else
                        {
                            searchTime += "00";
                        }
                    }
                    this.results = this.courseSearch.searchByTime(searchString, searchTime);
                }
                else if (searchType == 4)
                {
                    this.results = this.courseSearch.searchByDepartment(searchString);
                }
                if (this.results.hasCourses())
                {
                    if (this.searchResultsBox.Items.Count > 0)
                    {
                        this.searchResultsBox.Items.Clear();
                    }
                    for (int i = 0; i < this.results.size(); i++)
                    {
                        this.searchResultsBox.Items.Add(this.results.getIndex(i).getCourseCode());
                        metroBar.Value = i * 100 / this.results.size();
                        metroBar.Update();
                    }
                    metroBar.Value = 100;
                    metroBar.Update();
                }
                else
                {
                    if (this.searchResultsBox.Items.Count > 0)
                    {
                        this.searchResultsBox.Items.Clear();
                    }
                    noResults = "No results found";
                    this.searchResultsBox.Items.Add(noResults);
                }
            }
            this.courseDataBox.Text = "";
        }