示例#1
0
        /// <summary>
        /// 搜索
        /// </summary>
        private void Search_Click(object sender, RoutedEventArgs e)
        {
            //书名
            string Keyword = BookName.Text.Trim();

            //搜索字符不得为NULL
            if (Keyword.Length < 1)
            {
                return;
            }
            //必须加这个,否则无法修改任何值
            SearchList.ItemsSource = null;
            SearchList.Items.Clear();
            search.Content = "搜索中~";


            //查看选择的哪个书源
            int id = BookSourceName.SelectedIndex;

            Thread thread = new Thread(new ThreadStart(delegate
            {
                List <Book> books = DataFetch.Search(lb[id], Keyword);
                this.Dispatcher.Invoke(new Action(() =>
                {
                    if (books != null)
                    {
                        SearchList.ItemsSource = books;
                    }
                    search.Content = "搜索";
                }));
            }));

            thread.IsBackground = true;
            thread.Start();
        }
示例#2
0
        /// <summary>
        /// 更换书源
        /// </summary>
        private void Replace_Click(object sender, RoutedEventArgs e)
        {
            bookshelf.Visibility    = Visibility.Hidden;
            SourceChange.Visibility = Visibility.Visible;
            buffer.Visibility       = Visibility.Visible;
            int  Newid = Convert.ToInt32(((MenuItem)sender).Tag);
            Book Works = DataFetch.GetBook(Newid);

            SourceChange.ItemsSource = null;

            Thread thread = new Thread(new ThreadStart(delegate
            {
                string BookName = Works.Name;
                List <BookSource> bookSources = TempData.GetBookSourceS();
                //存储书的书架
                List <Book> Books = new List <Book>();
                foreach (BookSource bookSource in bookSources)
                {
                    List <Book> books = DataFetch.Search(bookSource, BookName);
                    if (books != null)
                    {
                        foreach (Book book in books)
                        {
                            if (book.Name == BookName || book.Author == Works.Author && book.Name.Contains(BookName))
                            {
                                book.Id = Works.Id;
                                this.Dispatcher.Invoke(new Action(() =>
                                {
                                    if (SourceChange.Visibility == Visibility.Collapsed)
                                    {
                                        //必须加这个,否则无法修改任何值
                                        SourceChange.ItemsSource = null;
                                        SourceChange.Items.Clear();
                                        return;
                                    }
                                    else
                                    {
                                        foreach (var de in SourceChange.Items)
                                        {
                                            if (((Book)de).Source == book.Source)
                                            {
                                                continue;
                                            }
                                        }
                                        SourceChange.Items.Add(book);
                                    }
                                }));
                            }
                        }
                    }
                }
                this.Dispatcher.Invoke(new Action(() =>
                {
                    buffer.Visibility = Visibility.Hidden;
                }));
            }));

            thread.IsBackground = true;
            thread.Start();
        }
示例#3
0
        /// <summary>
        /// 搜索点击
        /// </summary>
        private void SearchClick()
        {
            //书名
            string Keyword = BookName.Text.Trim();

            //搜索字符不得为NULL
            if (Keyword.Length < 1)
            {
                return;
            }
            //必须加这个,否则无法修改任何值
            SearchList.ItemsSource = null;
            SearchList.Items.Clear();
            search.Content          = "搜索中~";
            SearchBuffer.Visibility = Visibility.Visible;
            search.IsEnabled        = false;

            //查看选择的哪个书源
            int id = BookSourceName.SelectedIndex;

            try
            {
                Thread thread = new Thread(new ThreadStart(delegate
                {
                    List <Book> books = DataFetch.Search(lb[id], Keyword);
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        if (books != null)
                        {
                            SearchList.ItemsSource = books;
                        }
                        search.Content          = "搜索";
                        SearchBuffer.Visibility = Visibility.Hidden;
                        search.IsEnabled        = true;
                    }));
                }));
                thread.IsBackground = true;
                thread.Start();
            }
            catch (Exception ex)
            {
                new Tips(ex.Message).Show();
                search.Content          = "搜索";
                SearchBuffer.Visibility = Visibility.Hidden;
                search.IsEnabled        = true;
            }
        }
示例#4
0
        /// <summary>
        /// 搜索点击
        /// </summary>
        private void SearchClick()
        {
            //书名
            string Keyword = BookName.Text.Trim();

            //搜索字符不得为NULL
            if (Keyword.Length < 1)
            {
                return;
            }
            //必须加这个,否则无法修改任何值
            SearchList.ItemsSource = null;
            SearchList.Items.Clear();
            search.Content          = "搜索中~";
            SearchBuffer.Visibility = Visibility.Visible;
            search.IsEnabled        = false;

            //查看选择的哪个书源
            int id = BookSourceName.SelectedIndex;

            try
            {
                //全部搜索和其他的不同,故此重写
                if (lb[id].Id == -5)
                {
                    Thread thread = new Thread(new ThreadStart(delegate
                    {
                        foreach (BookSource Source in TempData.GetBookSourceS())
                        {
                            try
                            {
                                List <Book> T_books = DataFetch.Search(Source, Keyword);
                                if (T_books != null)
                                {
                                    Dispatcher.Invoke(new Action(() =>
                                    {
                                        foreach (Book book in T_books)
                                        {
                                            SearchList.Items.Add(book);
                                        }
                                    }));
                                }
                            }
                            catch (Exception ex)
                            {
                                Tool.TextAdditional(ex.Message);
                            }
                        }
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            search.Content          = "搜索";
                            SearchBuffer.Visibility = Visibility.Hidden;
                            search.IsEnabled        = true;
                        }));
                    }));
                    thread.IsBackground = true;
                    thread.Start();
                }
                else
                {
                    Thread thread = new Thread(new ThreadStart(delegate
                    {
                        List <Book> books = DataFetch.Search(lb[id], Keyword);
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            if (books != null)
                            {
                                SearchList.ItemsSource = books;
                            }
                            search.Content          = "搜索";
                            SearchBuffer.Visibility = Visibility.Hidden;
                            search.IsEnabled        = true;
                        }));
                    }));
                    thread.IsBackground = true;
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                new Tips(ex.Message).Show();
                Tool.TextAdditional(ex.Message);
                search.Content          = "搜索";
                SearchBuffer.Visibility = Visibility.Hidden;
                search.IsEnabled        = true;
            }
        }