//checks to see if the page number is within the right range 1 < x < AdvancedSearch.MaxPage(); private void CheckPageNumber(object sender, EventArgs e) { string selectedType = this.TypeBox.GetItemText(this.TypeBox.SelectedItem); string selectedBook = this.BookBox.GetItemText(this.BookBox.SelectedItem); //The Records are Organized By Type. if (Flags.HasFlag(GivenInfo.TYPE) && Flags.HasFlag(GivenInfo.BOOK)) { //sees which type is checked in the box. for (int i = 0; i < types.Count(); i++) { //finds if the right type has been selected if (types[i] == selectedType) { //grabs the right index of the list holding the records. //it should be in the same position as the type[i] as they were intialized in that order. AdvancedSearch search = new AdvancedSearch(AllTypes[i]); //searches for a specific book title List <Records> Books = search.FindABook(selectedBook); //now finding out if the pagenumber was broken or not. int Max = search.MaxPage(Books); int ActualPage; if (int.TryParse(PageBox.Text, out ActualPage)) { if (0 < ActualPage && ActualPage <= Max) { //this is a valid page search. Flags |= GivenInfo.PAGE; return; } else { MessageBox.Show("Choose page between 0 and " + Max); PageBox.Text = "0 - " + Max; return; } } else { if (Flags.HasFlag(GivenInfo.PAGE)) { Flags -= GivenInfo.PAGE; } PageBox.Text = " "; return; } } } } else { if (Flags.HasFlag(GivenInfo.PAGE)) { Flags -= GivenInfo.PAGE; } PageBox.Text = " "; return; } }
//checks which search will be called based on the flags raised with the other info passed in. private async Task <List <Records> > CheckFlags(GivenInfo flags = GivenInfo.NONE) { string selectedType = this.TypeBox.GetItemText(this.TypeBox.SelectedItem); string selectedBook = this.BookBox.GetItemText(this.BookBox.SelectedItem); string selectedFirstName = FirstNameBox.Text; string selectedLastName = LastNameBox.Text; string selectedDate = DateBox.Text; int selectedPage = 0; if (Flags.HasFlag(GivenInfo.PAGE)) { selectedPage = int.Parse(PageBox.Text); } //goes through all of the possible flag combonations #region FlagChecks switch (flags) { case GivenInfo.NONE: { await LoadForm(); break; } case GivenInfo.TYPE: { return(FindListOfType(selectedType)); } #region BOOK case GivenInfo.TYPE | GivenInfo.BOOK: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(search.FindABook(selectedBook)); } case GivenInfo.PAGE | GivenInfo.BOOK | GivenInfo.TYPE: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); List <Records> FoundPages = await search.AsyncFindPage(search.FindABook(selectedBook), selectedPage); return(FoundPages); } #endregion Book #region Name case GivenInfo.TYPE | GivenInfo.LASTNAME: case GivenInfo.TYPE | GivenInfo.FIRSTNAME: { bool Last_Name = false; string UsedName = selectedFirstName; if (Flags.HasFlag(GivenInfo.LASTNAME)) { Last_Name = true; UsedName = selectedLastName; } Search search = new Search(FindListOfType(selectedType)); return(search.FindName(Last_Name, UsedName)); } case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.LASTNAME: case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.FIRSTNAME: { bool Last_Name = false; string UsedName = selectedFirstName; if (Flags.HasFlag(GivenInfo.LASTNAME)) { Last_Name = true; UsedName = selectedLastName; } AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(search.FindName(Last_Name, search.FindABook(selectedBook), UsedName)); } case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.LASTNAME | GivenInfo.PAGE: case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.FIRSTNAME | GivenInfo.PAGE: { bool Last_Name = false; string UsedName = selectedFirstName; if (Flags.HasFlag(GivenInfo.LASTNAME)) { Last_Name = true; UsedName = selectedLastName; } AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); List <Records> PageSearch = await search.AsyncFindPage(search.FindABook(selectedBook), selectedPage); return(search.FindName(Last_Name, PageSearch, UsedName)); } case GivenInfo.LASTNAME: case GivenInfo.FIRSTNAME: { string question; bool Last_Name = false; if (Flags.HasFlag(GivenInfo.LASTNAME)) { Last_Name = true; } List <Records> searchingNames = new List <Records>(); if (Last_Name) { question = selectedLastName; } else { question = selectedFirstName; } foreach (List <Records> rec in AllTypes) { AdvancedSearch search = new AdvancedSearch(rec); List <Records> FoundNames = search.FindName(Last_Name, question); searchingNames.AddRange(FoundNames); } return(searchingNames); } case GivenInfo.LASTNAME | GivenInfo.FIRSTNAME: { List <Records> searchingNames = new List <Records>(); foreach (List <Records> rec in AllTypes) { AdvancedSearch search = new AdvancedSearch(rec); List <Records> FoundNames = search.FindPerson(selectedFirstName, selectedLastName); searchingNames.AddRange(FoundNames); } return(searchingNames); } case GivenInfo.TYPE | GivenInfo.LASTNAME | GivenInfo.FIRSTNAME: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(search.FindPerson(selectedLastName + ", " + selectedFirstName)); } #endregion Name #region Date case GivenInfo.TYPE | GivenInfo.DATE: { MessageBox.Show("Too many records to show!"); break; // AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); // return await search.AsyncFindDate(GetValidDateRange(selectedDate)); } case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.DATE: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(await search.AsyncFindDate(GetValidDateRange(selectedDate), search.FindABook(selectedBook))); } case GivenInfo.DATE: { return(null); } #endregion Date #region Tag case GivenInfo.TAG: { List <Records> searchingNames = new List <Records>(); foreach (List <Records> rec in AllTypes) { AdvancedSearch search = new AdvancedSearch(rec); searchingNames.AddRange(search.FindTag(tag)); } return(searchingNames); } case GivenInfo.TAG | GivenInfo.TYPE: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(search.FindTag(tag)); } case GivenInfo.TYPE | GivenInfo.BOOK | GivenInfo.TAG: { AdvancedSearch search = new AdvancedSearch(FindListOfType(selectedType)); return(search.FindTag(tag, search.FindABook(selectedBook))); } #endregion Tag #endregion FlagChecks } return(null); }