示例#1
0
 private void NameFlags()
 {
     if (FirstNameBox.Text.Trim() != null && !string.IsNullOrWhiteSpace(FirstNameBox.Text))
     {
         Flags |= GivenInfo.FIRSTNAME;
     }
     else
     {
         if (Flags.HasFlag(GivenInfo.FIRSTNAME))
         {
             Flags -= GivenInfo.FIRSTNAME;
             return;
         }
     }
     if (LastNameBox.Text.Trim() != null && !string.IsNullOrWhiteSpace(LastNameBox.Text))
     {
         Flags |= GivenInfo.LASTNAME;
     }
     else
     {
         if (Flags.HasFlag(GivenInfo.LASTNAME))
         {
             Flags -= GivenInfo.LASTNAME;
             return;
         }
     }
 }
示例#2
0
        //checks to see if the date is right when the date is typed rather than passed
        private void ValidateDate(object sender, EventArgs e)
        {
            NameFlags();
            int date;

            if (int.TryParse(DateBox.Text, out date))
            {
                if (((date - 1749) < 0))
                {
                    DateBox.Text = "1749";
                }
                else if (((1881 - date) < 0))
                {
                    DateBox.Text = "1881";
                }
                Flags |= GivenInfo.DATE;
            }
            else
            {
                if (Flags.HasFlag(GivenInfo.DATE))
                {
                    Flags -= GivenInfo.DATE;
                }
                return;
            }
        }
示例#3
0
        //runs when type is selected to give the correct number of books to the other box.
        private void TypeSelected(object sender, EventArgs e)
        {
            NameFlags();
            string selected = this.TypeBox.GetItemText(this.TypeBox.SelectedItem);

            if (selected == "All")
            {
                if (Flags.HasFlag(GivenInfo.TYPE))
                {
                    Flags -= GivenInfo.TYPE;
                }
                if (Flags.HasFlag(GivenInfo.BOOK))
                {
                    Flags -= GivenInfo.BOOK;
                }
                BookBox.DataSource = null;
                DateBox.Enabled    = false;
                return;
            }
            else if (Type.CorrectType(selected))
            {
                Utility util = new Utility();
                BookBox.DataSource = util.DictionaryKeys(new Type(selected));
                Flags          |= GivenInfo.TYPE;
                DateBox.Enabled = true;
            }
        }
示例#4
0
        //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;
            }
        }
示例#5
0
 private void TagSelected(object sender, EventArgs e)
 {
     Enum.TryParse <Tag>(TagBox.SelectedValue.ToString(), out tag);
     if (tag.ToString() == "None")
     {
         Flags -= GivenInfo.TAG;
         return;
     }
     else
     {
         Flags |= GivenInfo.TAG;
     }
 }
示例#6
0
 //gives the correct date to the date box
 private void BookSelected(object sender, EventArgs e)
 {
     NameFlags();
     if (this.BookBox.SelectedItem != null && !(this.BookBox.GetItemText(this.BookBox.SelectedItem) == "None"))
     {
         Utility util     = new Utility();
         Type    UsedType = new Type(this.TypeBox.GetItemText(this.TypeBox.SelectedItem));
         string  selected = this.BookBox.GetItemText(this.BookBox.SelectedItem);
         int     i;
         if (Int32.TryParse(selected.Trim('B', 'o', 'k'), out i))
         {
             DateBox.Text = util.DateGetter(UsedType, i);
             Flags       |= GivenInfo.BOOK;
         }
     }
     else
     {
         if (Flags.HasFlag(GivenInfo.BOOK))
         {
             Flags -= GivenInfo.BOOK;
         }
         return;
     }
 }
示例#7
0
        //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);
        }