/// <summary> /// 获取养肥区 /// </summary> void GetFatten() { List <Book> books = DataFetch.GetBooks(true); FattenArea.ItemsSource = null; FattenArea.ItemsSource = books; }
/// <summary> /// 确定更换书源 /// </summary> private void SureSource_Click(object sender, RoutedEventArgs e) { //MessageBox.Show(((MenuItem)sender).Tag.ToString()); Book book = SourceChange.SelectedItem as Book; if (book != null && book is Book) { if (!DataFetch.UpdateBookSource(book)) { new Tips("更换失败~").Show(); } else { //更换书籍后,重新刷新全部书籍信息 //获取所有书籍 this.DataContext = DataFetch.GetBooks(); //启动时更新书籍 Update(); } //清空已有的部分数据 SourceChange.ItemsSource = null; SourceChange.Items.Clear(); buffer.Visibility = Visibility.Hidden; SourceChange.Visibility = Visibility.Collapsed; bookshelf.Visibility = Visibility.Visible; } }
/// <summary> /// 导入书源 /// </summary> private void Import_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "BookSource (*.json)|*.json" }; var result = openFileDialog.ShowDialog(); if (result == true) { try { StreamReader sr = new StreamReader(openFileDialog.FileName, Encoding.UTF8); var Book_Source = JsonHelper.DeserializeJsonToObject <BookSource>(sr.ReadToEnd()); sr.Close(); if (Book_Source.Title.Length > 1 && Book_Source.Url.Length > 1) { string Msg = DataFetch.SourceAdd(Book_Source) ? "添加成功~" : "添加失败!"; new Tips(Msg).Show(); //加载书源 ListSource.ItemsSource = DataFetch.GetBookSources(); } else { new Tips("错误的书源").Show(); } } catch (Exception ex) { new Tips("书源异常:" + ex.Message).Show(); } } }
/// <summary> /// 跳转到直接章节 /// </summary> /// <param name="page">章节数</param> private void Jump(int page) { try { //文章html string html = string.Empty; html = BLL.GetHtml.GetHttpWebRequest(book.ListUrl[NewId[page]]); newTitle.Text = NewId[page]; string str = BLL.Tool.GetRegexStr(html, bookSource.ContentRegular); newText.Document.Blocks.Clear(); Run run = new Run(BLL.Tool.HtmlFilter(str)); Paragraph p = new Paragraph(); p.Inlines.Add(run); newText.Document.Blocks.Add(p); ///重置翻页数 this.newText.ScrollToVerticalOffset(0); //保存已阅章节数 if (book.Id != 0) { DataFetch.UpdateUpdateReadingBook((int)book.Id, page); } NewPages = page; } catch { new Tips("打开错误,请检查书源是否存在问题?").Show(); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="book"></param> /// <param name="mainWindow"></param> /// <param name="config"></param> public DetailsPage(Book book, MainWindow mainWindow = null, Config config = null) { InitializeComponent(); Thread thread = new Thread(new ThreadStart(delegate { this.book = book; this.mainWindow = mainWindow; this.config = config; this.Dispatcher.Invoke(new Action(() => { this.Title = "《" + book.Name + "》-最新章节:" + book.Newest; this.DataContext = book; if (DataFetch.BoolBookAdd(book.Name)) { Join.Background = Brushes.DarkTurquoise; Join.Content = "已加入"; Join.IsEnabled = false; buffer.Visibility = Visibility.Hidden; } })); })); thread.IsBackground = true; //是否为后台线程 thread.Start(); this.Closed += BeforeClosing; }
/// <summary> /// 保存&更新书源 /// </summary> private void Keep_Click(object sender, RoutedEventArgs e) { BookSource bookSource = new BookSource(); bookSource.Title = sourceName.Text.Trim(); bookSource.Url = sourceUrl.Text.Trim(); bookSource.SearchUrl = SearchUrl.Text; bookSource.AddressRangeRegular = AddressRangeRegular.Text.Replace("'", "''"); bookSource.AddressCuttingRegular = AddressCuttingRegular.Text.Replace("'", "''"); bookSource.AddressRegular = AddressRegular.Text.Replace("'", "''"); bookSource.BookNameRegular = BookNameRegular.Text.Replace("'", "''"); bookSource.AuthorRegular = AuthorRegular.Text.Replace("'", "''"); bookSource.UpdateRegular = UpdateRegular.Text.Replace("'", "''"); bookSource.NewestRegular = NewestRegular.Text.Replace("'", "''"); bookSource.DetailsRegular = DetailsRegular.Text.Replace("'", "''"); bookSource.StateRegular = StateRegular.Text.Replace("'", "''"); bookSource.DirectoryScopeRegular = DirectoryScopeRegular.Text.Replace("'", "''"); bookSource.DirectoryCuttingRegular = DirectoryCuttingRegular.Text.Replace("'", "''"); bookSource.DirectoryTieleRegular = DirectoryTieleRegular.Text.Replace("'", "''"); bookSource.DirectoryUrlRegular = DirectoryUrlRegular.Text.Replace("'", "''"); bookSource.ContentTitleRegular = ContentTitleRegular.Text.Replace("'", "''"); bookSource.ContentRegular = ContentRegular.Text.Replace("'", "''"); bookSource.ImageRegular = ImageRegular.Text.Replace("'", "''"); bookSource.State = 1; //这个是更新原有源 if (((Button)sender).Content.ToString() != "保存当前书源") { int id = Convert.ToInt32(Keep.Tag); bookSource.Id = id; string Msg = DataFetch.SourceUpdate(bookSource) ? "更新成功~" : "更新失败!"; Tips tips = new Tips(Msg); tips.Show(); //加载书源 ListSource.ItemsSource = DataFetch.GetBookSources(); } else //这个是增加新源 { if (state_search && state_details && state_Catalog && state_Text) { if (sourceName.Text.Trim().Length > 0 && sourceName.Text != "请输入新书源名~" && sourceUrl.Text.Trim().Length > 0 && sourceUrl.Text != "请输入新书源URL~") { string Msg = DataFetch.SourceAdd(bookSource) ? "添加成功~" : "添加失败!"; new Tips(Msg).Show(); } else { new Tips("请输入书源名和书源链接!").Show(); } } else { new Tips("请将其他页面的内容全部填写完毕,并保证准确无误后在进行提交!").Show(); } } //加载书源 ListSource.ItemsSource = DataFetch.GetBookSources(); Empty(); }
/// <summary> /// 加入书架 /// </summary> private void Join_Click(object sender, RoutedEventArgs e) { DataFetch.BookAdd(book); Join.Background = Brushes.DarkTurquoise; Join.Content = "已加入"; Join.IsEnabled = false; }
/// <summary> /// 初始化 /// </summary> public static void Initialization() { if (BookSourceS == null) { BookSourceS = DataFetch.GetBookSources(); } }
/// <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(); }
private static string GetTParam(string yt_video_uri) { string t_param; DataFetch df = new DataFetch(); string watch_page_contents = df.GetWatchPageContents(yt_video_uri); if (String.IsNullOrEmpty(watch_page_contents)) { return(null); } Regex regex = new Regex("swfHTML = .*&t=([^&]+)&"); Match match = regex.Match(watch_page_contents); if (!match.Success) { return(null); } t_param = Regex.Unescape(match.Result("$1")); if (t_param == null) { t_param = match.Result("$1"); } return(t_param); }
/// <summary> /// 养肥区更新 /// </summary> private void UpdateFatten() { Thread thread = new Thread(new ThreadStart(delegate { List <Book> books = DataFetch.GetBooks(true); foreach (Book book in books) { book.FattenNumber = DataFetch.GetListCount(book) - (int)book.Read; if (book.FattenNumber >= config.FattenNumber) { this.Dispatcher.Invoke(new Action(() => { new Tips("《" + book.Name + "》已经养肥,请尽情享用~").Show(); })); } } this.Dispatcher.Invoke(new Action(() => { if ((bool)BoolFertilizingArea.IsChecked) { FattenArea.ItemsSource = books; } })); })); thread.IsBackground = true; thread.Start(); }
/// <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 ItemFatten_Click(object sender, RoutedEventArgs e) { int id = Convert.ToInt32(((MenuItem)sender).Tag); DataFetch.Add_MoveOut(id, true); //获取所有书籍 this.DataContext = DataFetch.GetBooks(); }
public void TestFetchData() { DateTime date = new DateTime(2015, 1, 7); DataFetch df = new DataFetch(); bool ret = df.FetchData(out List <int> lst, date); Assert.IsFalse(ret); }
public BookSourceAdd(MainWindow mainWindow) { InitializeComponent(); //加载书源 ListSource.ItemsSource = DataFetch.GetBookSources(); this.Closed += BeforeClosing; this.mainWindow = mainWindow; }
/// <summary> /// 构造函数入口 /// </summary> /// <param name="book">书籍信息</param> /// <param name="mainWindow">主窗口对象</param> /// <param name="config">配置项</param> public ReadingPage(Book book, MainWindow mainWindow = null, Config config = null) { InitializeComponent(); Thread thread = new Thread(new ThreadStart(delegate { try { this.book = book; this.mainWindow = mainWindow; this.config = config; //获取目录 DataFetch.GetList(book); bookSource = DataFetch.GetBookSource(book.Source); //主要为遍历目录 int i = 0; foreach (KeyValuePair <string, string> kvp in book.ListUrl) { if (kvp.Key.Trim().Length > 2) { i++; NewId.Add(i, kvp.Key); } } Dispatcher.Invoke((Action) delegate { if (book.Read == 0) { Jump(1); } else { Jump((int)book.Read); } }); } catch (Exception ex) { Tool.TextAdditional(ex.Message); } })); thread.IsBackground = true; //是否为后台线程 thread.Start(); this.Closed += BeforeClosing; //newText.IsEnabled = false; //窗口大小改变时 this.SizeChanged += new SizeChangedEventHandler(ReadingPage_Resize); //设置定时器(朗读) timer = new DispatcherTimer(); timer.Interval = new TimeSpan(10000000); //时间间隔为一秒 timer.Tick += new EventHandler(timer_Tick); }
/// <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 BeforeClosing(object sender, EventArgs e) { if (mainWindow != null && !WindowsShow) { mainWindow.Visibility = Visibility.Visible; //获取所有书籍 mainWindow.DataContext = DataFetch.GetBooks(); } }
/// <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; } }
public MainWindow() { InitializeComponent(); string path = AppDomain.CurrentDomain.BaseDirectory; //this.Icon = BitmapFrame.Create(new Uri(path + "Resources/favicon.ico")); //获取配置项 config = ConfigReadWrite.GetConfig(); //添加书源 lb = DataFetch.GetBookSources(); //绑定书源 BookSourceName.ItemsSource = lb; BookSourceName.Text = config.SourceStation; //this.BookSourceName.SelectedIndex = 0; //获取所有书籍 this.DataContext = DataFetch.GetBooks(); //启动时更新书籍 Update(); //启动时更新养肥区 UpdateFatten(); //字体 Typeface.ItemsSource = Tool.GetTypeface(); Typeface.Text = config.Typeface; //绑定字体大小 TypefaceSize.ItemsSource = config.GetTypefaceSize; TypefaceSize.Text = config.FontSize.ToString(); //绑定主题 theme.ItemsSource = config.GetTheme; theme.Text = config.Theme; //绑定书源 SourceStation.ItemsSource = lb; SourceStation.Text = config.SourceStation; //禁用养肥区 fatten.IsEnabled = false; about.Text = "本软件只是娱乐之作,所有数据来源皆来自于网络,如果有侵犯到他人的权益,请于我进行联系,我会第一时间删除源站,谢谢合作!\n\n本软件默认有两个源:笔趣阁、追书网,用户可以自定义增加更多的源站,如果你有更好的源站,可以推荐给我,我会第一时间集成进去。\n\n本软件初始发布于吾爱破解,如果你在使用的过程中有发现BUG或者其他不合理的地方,请进行留言。本软件只作用于学习研究,请在下载内24小时内删除本软件。"; }
/// <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 MoveOut_Click(object sender, RoutedEventArgs e) { Book book = FattenArea.SelectedItem as Book; if (book != null && book is Book) { DataFetch.Add_MoveOut((int)book.Id, false); //获取所有书籍 this.DataContext = DataFetch.GetBooks(); UpdateFatten(); } }
/// <summary> /// 删除书源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Delete_Click(object sender, RoutedEventArgs e) { BookSource bookSource = ListSource.SelectedItem as BookSource; if (bookSource != null && bookSource is BookSource) { if (MessageBox.Show("确定要删除书源【" + bookSource.Title + "】? 本操作不可以逆转,请谨慎操作~", "提示", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { DataFetch.DeleteBookSource((int)bookSource.Id); } } }
/// <summary> /// 窗口打开时执行的 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { HwndSource hWndSource; WindowInteropHelper wih = new WindowInteropHelper(this); hWndSource = HwndSource.FromHwnd(wih.Handle); //添加处理程序 hWndSource.AddHook(MainWindowProc); Identification = HotKey.GlobalAddAtom("Shift-S"); HotKey.RegisterHotKey(wih.Handle, Identification, HotKey.KeyModifiers.Shift, (int)System.Windows.Forms.Keys.S); //软件更新 DataFetch.SoftwareUpdate(); }
/// <summary> /// 加入养肥区 /// </summary> private void ItemFatten_Click(object sender, RoutedEventArgs e) { int id = Convert.ToInt32(((MenuItem)sender).Tag); DataFetch.Add_MoveOut(id, true); //获取所有书籍 this.DataContext = DataFetch.GetBooks(); if (FertilizingArea.Visibility == Visibility.Visible) { //更新养肥区界面 GetFatten(); } }
/// <summary> /// 加入书架 /// </summary> private void JoinBookshelves_Click(object sender, RoutedEventArgs e) { Book book = SearchList.SelectedItem as Book; if (book != null && book is Book) { if (DataFetch.BookAdd(book)) { new Tips("添加成功!").Show(); //获取所有书籍 this.DataContext = DataFetch.GetBooks(); } } }
public MainWindow() { InitializeComponent(); //190731增加,这里新增加一个判断,判断是否存在指定列,如果不存在将进行增加列操作 if (!DataFetch.ColumnExistence("BookSource", "Code")) { SQLiteDBHelper.ExecuteDataTable("ALTER TABLE BookSource ADD COLUMN Code Text; ", null); } string path = AppDomain.CurrentDomain.BaseDirectory; //this.Icon = BitmapFrame.Create(new Uri(path + "Resources/favicon.ico")); //获取配置项 config = ConfigReadWrite.GetConfig(); about.Text = "本软件只是娱乐之作,所有数据来源皆来自于网络,如果有侵犯到他人的权益,请于我进行联系,我会第一时间删除源站,谢谢合作!\n\n本软件默认有五个源,用户可以自定义增加更多的源站,如果你有更好的源站,可以推荐给我,我会第一时间集成进去。\n\n本软件初始发布于吾爱破解,如果你在使用的过程中有发现BUG或者其他不合理的地方,请进行留言。本软件只作用于学习研究,请在下载内24小时内删除本软件。"; //字体 Typeface.ItemsSource = Tool.GetTypeface(); Typeface.Text = config.Typeface; //绑定字体大小 TypefaceSize.ItemsSource = config.GetTypefaceSize; TypefaceSize.Text = config.FontSize.ToString(); //绑定主题 theme.ItemsSource = config.GetTheme; theme.Text = config.Theme; //更新书源状态 //DataFetch.UpdateSourceState(); //刷新数据 RefreshData(); //绑定书源 SourceStation.ItemsSource = lb; SourceStation.Text = config.SourceStation; //默认显示养肥区 FertilizingArea.Visibility = Visibility.Visible; fatten.IsEnabled = true; //绑定养肥区 fatten.ItemsSource = config.GetFattenNumber; fatten.Text = config.FattenNumber.ToString(); GetFatten(); }
/// <summary> /// 检测书源可用率 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Testing_Click(object sender, RoutedEventArgs e) { MessageBox.Show("状态码如果为1代表书源站正常访问,如果为0代表不可访问", "提示"); App.Current.Dispatcher.Invoke((Action)(() => { //更新书源状态 DataFetch.UpdateSourceState(); //加载书源 ListSource.ItemsSource = DataFetch.GetBookSources(0); TempData.UpdateBookSourceS(); })); }
/// <summary> /// 确定更换书源 /// </summary> private void SureSource_Click(object sender, RoutedEventArgs e) { //MessageBox.Show(((MenuItem)sender).Tag.ToString()); Book book = SourceChange.SelectedItem as Book; if (book != null && book is Book) { if (!DataFetch.UpdateBookSource(book)) { new Tips("更换失败~").Show(); } SourceChange.Visibility = Visibility.Collapsed; bookshelf.Visibility = Visibility.Visible; } }