示例#1
0
        public int FindBinary(BookFields type, string param)
        {
            int result = -1;

            SortInternalMethod(type, true);
            switch (type)
            {
            case BookFields.Authors:
                result = BinarySearchAuthor(param, Comparer <string> .Default);
                break;

            case BookFields.Name:
                result = BinarySearchName(param, Comparer <string> .Default);
                break;

            case BookFields.Publisher:
                result = BinarySearchPublisher(param, Comparer <string> .Default);
                break;

            case BookFields.Genres:
                result = BinarySearchGenre(param, Comparer <string> .Default);
                break;

            default:
                MessageBox.Show("Ошибка типизации");
                break;
            }
            return(result);
        }
示例#2
0
        public void SortInternalMethod(BookFields type, bool ascending)
        {
            switch (type)
            {
            case BookFields.Authors:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.Author).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.Author).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.Name:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.PagesCount:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.PagesCount).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.PagesCount).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.YearCreation:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.YearCreation).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.YearCreation).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.YearPublication:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.YearPublication).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.YearPublication).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.Publisher:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.Publisher).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.Publisher).ToDictionary(x => x.Key, x => x.Value));
                break;

            case BookFields.Genres:
                Library = @ascending ? new Dictionary <int, Book>(Library.OrderBy(x => x.Value.Genre).ToDictionary(x => x.Key, x => x.Value)) : new Dictionary <int, Book>(Library.OrderByDescending(x => x.Value.Genre).ToDictionary(x => x.Key, x => x.Value));
                break;
            }
        }
示例#3
0
        public void Find(bool binarySearch, string param, BookFields type)
        {
            Dictionary <int, Book> result;

            if (!binarySearch)
            {
                result = new Dictionary <int, Book>(FindInternalMethod(type, param));
                if (result.Count == 0)
                {
                    MessageBox.Show("Не найдено ничего");
                }
            }
            else
            {
                result = new Dictionary <int, Book>();
                int i = FindBinary(type, param);
                if (i == -1)
                {
                    MessageBox.Show("Не найдено ничего");
                }
                else
                {
                    result.Add(Library.Keys.Max() + 1, Library[i]);
                }
            }
            foreach (var book in result)
            {
                MessageBox.Show(book.Value.GetString());
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (FieldCB.SelectedItem != null && SearchTypeCB.SelectedItem != null)
            {
                BookFields fieldType = BookFields.Authors;
                switch (FieldCB.SelectedItem.ToString())
                {
                case "Автор":
                    fieldType = BookFields.Authors;
                    break;

                case "Имя":
                    fieldType = BookFields.Name;
                    break;

                case "Издатель":
                    fieldType = BookFields.Publisher;
                    break;

                case "Жанр":
                    fieldType = BookFields.Genres;
                    break;
                }
                if (SearchTypeCB.SelectedItem.ToString() == "Встроенный")
                {
                    DataContainer.books.Find(false, ValueTB.Text.ToString(), fieldType);
                }
                else
                {
                    DataContainer.books.Find(true, ValueTB.Text.ToString(), fieldType);
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (MethodCB.SelectedItem != null && FieldCB.SelectedItem != null && TypeCB.SelectedItem != null)
            {
                bool type = false;
                if (MethodCB.SelectedItem.ToString() == "Пирамидальный")
                {
                    type = true;
                }
                bool ascend = true;
                if (TypeCB.SelectedItem.ToString() == "По убыванию")
                {
                    ascend = false;
                }
                BookFields a = new BookFields();
                switch (FieldCB.SelectedItem.ToString())
                {
                case "Имя":
                    a = BookFields.Name;
                    break;

                case "Автор":
                    a = BookFields.Authors;
                    break;

                case "Количество страниц":
                    a = BookFields.PagesCount;
                    break;

                case "Год создания":
                    a = BookFields.YearCreation;
                    break;

                case "Год публикация":
                    a = BookFields.YearPublication;
                    break;

                case "Издатель":
                    a = BookFields.Publisher;
                    break;

                case "Жанр":
                    a = BookFields.Genres;
                    break;
                }
                DataContainer.books.Sort(type, a, ascend);
            }
            else
            {
                MessageBox.Show("Выберите все поля");
            }
        }
示例#6
0
        public Dictionary <int, Book> FindInternalMethod(BookFields type, string param)
        {
            Dictionary <int, Book> result = new Dictionary <int, Book>(Library);

            switch (type)
            {
            case BookFields.Authors:
                InternalSearchAuthor(ref result, param);
                break;

            case BookFields.Name:
                InternalSearchName(ref result, param);
                break;

            case BookFields.Publisher:
                InternalSearchPublisher(ref result, param);
                break;

            case BookFields.Genres:
                InternalSearchGenre(ref result, param);
                break;
            }
            return(result);
        }
示例#7
0
        /// <summary>
        /// Универсальная функция сортировки
        /// </summary>
        /// <param name="type"> false - внутренний, true - хипсорт </param>
        /// <param name="field"> поле из enum BookField</param>
        /// <param name="ascend"> false - по убыванию, true - по возрастанию</param>
        public void Sort(bool type, BookFields field, bool ascend)
        {
            if (!type)
            {
                SortInternalMethod(field, ascend);
            }
            else
            {
                switch (field)
                {
                case BookFields.YearCreation:
                    Library = new Dictionary <int, Book>(HeapSorter.sortingByYearCreation(Library, Library.Count));
                    break;

                case BookFields.YearPublication:
                    Library = new Dictionary <int, Book>(HeapSorter.sortingByYearPublication(Library, Library.Count));
                    break;

                case BookFields.PagesCount:
                    Library = new Dictionary <int, Book>(HeapSorter.sortingByPagesCount(Library, Library.Count));
                    break;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Book" /> class.
 /// </summary>
 public Book() : base(CLASS_NAME)
 {
     mFields = new BookFields(this);
 }