/// <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(); }
/// <summary> /// 查看书籍 /// </summary> private void CheckBooks_Click(object sender, RoutedEventArgs e) { int Newid = Convert.ToInt32(((MenuItem)sender).Tag); Book book = DataFetch.GetBook(Newid); UI.DetailsPage dp = new UI.DetailsPage(book, this, config); dp.Show(); this.Visibility = Visibility.Hidden; }
/// <summary> /// 阅读书籍 /// </summary> private void Read_Click(object sender, RoutedEventArgs e) { int Newid = Convert.ToInt32(((MenuItem)sender).Tag); Book book = DataFetch.GetBook(Newid); UI.ReadingPage page = new UI.ReadingPage(book, this, config); page.Show(); this.Visibility = Visibility.Hidden; }
/// <summary> /// 点击打开阅读页 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewBook_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { int Newid = Convert.ToInt32(((Grid)sender).Tag); Book book = DataFetch.GetBook(Newid); UI.ReadingPage page = new UI.ReadingPage(book, this, config); page.Show(); this.Visibility = Visibility.Collapsed; } }
/// <summary> /// 删除书籍 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Delete_Click(object sender, RoutedEventArgs e) { //获取书籍ID int Id = Convert.ToInt32(((MenuItem)sender).Tag); Book book = DataFetch.GetBook(Id); if (MessageBox.Show("确定要删除《" + book.Name + "》? 本操作不可以逆转,请谨慎操作~", "提示", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { DataFetch.DeleteBook(Id); this.DataContext = DataFetch.GetBooks(); } }
/// <summary> /// 更换书源 /// </summary> private void Replace_Click(object sender, RoutedEventArgs e) { bookshelf.Visibility = Visibility.Hidden; SourceChange.Visibility = Visibility.Visible; int Newid = Convert.ToInt32(((MenuItem)sender).Tag); Book book = DataFetch.GetBook(Newid); SourceChange.ItemsSource = null; Thread thread = new Thread(new ThreadStart(delegate { List <Book> books = DataFetch.SourceSearch(book); this.Dispatcher.Invoke(new Action(() => { SourceChange.ItemsSource = books; })); })); thread.IsBackground = true; thread.Start(); }