public void LoadFile(JianLi3Data.File f) { string filepath = JianLi3FileServiceManager.Default.GetPath(f); if (System.IO.File.Exists(filepath)) { axAcroPDF1.setShowToolbar(false); axAcroPDF1.setShowScrollbars(false); axAcroPDF1.setLayoutMode("SinglePage"); axAcroPDF1.setPageMode("none"); axAcroPDF1.setView("FitH"); if (this.axAcroPDF1.LoadFile(filepath) == false) { throw new Exception("打开失败。" + filepath); } } else { throw new Exception("文件不存在:" + filepath); } _file = f; startTime = DateTime.Now; }
public static void OpenFile(JianLi3Data.File f) { if (AppendTab == null) { return; } JianLiLinq.Default.SetLastOpenBook(f.Book); string filepath = JianLi3FileServiceManager.Default.GetPath(f); string fileext = filepath.ToUpper().Substring(filepath.Length - 3, 3); switch (fileext) { case "PDF": try { TabPage tp = new TabPage(f.Book.BookName); BookViewControl bookViewControl1 = new JianLi3.BookViewControl(); tp.Controls.Add(bookViewControl1); bookViewControl1.Dock = System.Windows.Forms.DockStyle.Fill; bookViewControl1.Location = new System.Drawing.Point(3, 3); bookViewControl1.Name = "bookViewControl" + tp.Controls.Count.ToString(); bookViewControl1.Size = new System.Drawing.Size(728, 357); bookViewControl1.TabIndex = 0; bookViewControl1.LoadFile(f); AppendTab.TabPages.Add(tp); AppendTab.SelectedIndex = AppendTab.TabPages.Count - 1; } catch (Exception ex) { Process.Start(filepath); } break; case "CHM": if (MessageBox.Show("警告,当前文件为可执行文件,可能包含病毒,是否打开?", "危险!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Process.Start(filepath); } else { Process.Start(Path.GetDirectoryName(filepath)); } break; case "EXE": if (MessageBox.Show("警告,当前文件为可执行文件,可能包含病毒,是否打开?", "危险!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Process.Start(filepath); } else { Process.Start(Path.GetDirectoryName(filepath)); } break; default: Process.Start(filepath); break; } }
void View_OnBookCreate(ref bool iscreated) { JianLi3Data.DataClasses1DataContext db = JianLiLinq.Default.DB; string filesubpath; // 更新数据库 if (isBookInLib) { book = (from b in db.Books where b.BookName == View.BookTitle select b).Single(); book.BookName = View.BookTitle; book.BookPublishHouse = View.PublishHouse; book.BookRate = View.BookRate; if (book.BookCover == null) { Common2.UpdateBookCover(ref book, LocalPath); } JianLi3Data.File f = new JianLi3Data.File(); f.UploadDate = DateTime.Now; // 确定子文件路径 if (book.Keywords.KeywordSubPath != null) { f.FilePath = book.Keywords.KeywordSubPath + "\\" + Path.GetFileName(LocalPath); } else { f.FilePath = Path.GetFileName(LocalPath); } // 文件最终位置 filesubpath = f.FilePath; f.FileVersion = View.BookVersion; f.Book = book; f.FileDesc = View.FileDescription; db.Files.InsertOnSubmit(f); f.FilePath = JianLi3FileServiceManager.Default.MoveToLib(LocalPath, f); // 更新数据库 db.SubmitChanges(); } else { List <Keywords> bookkeywords = new List <Keywords>(); if (View.BookKeywords == "") { MessageBox.Show("没有给书籍设定关键字,无法完成归类,请使用“添加”按钮!"); return; } string[] keywordpaths = View.BookKeywords.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string kp in keywordpaths) { string[] ks = kp.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (ks.Length <= 1) { throw new Exception("关键字不该存在于顶层,需要类别。"); } Keywords k = JianLiLinq.Default.CreateOrGetKeyword(kp); if (!bookkeywords.Contains(k)) { bookkeywords.Add(k); } } Book b = new Book(); JianLi3Data.File f = new JianLi3Data.File(); f.UploadDate = DateTime.Now; b.BookName = View.BookTitle; b.BookPublishHouse = View.PublishHouse; b.BookRate = View.BookRate; b.BookSubTitle = View.BookSubTitle; b.BookDefaultKeyword = bookkeywords[0].KeywordID; b.BookType = BookHelper.BookTypeConvert(View.BookType); Common2.UpdateBookCover(ref b, LocalPath, false); if (bookkeywords[0].KeywordSubPath != null) { f.FilePath = bookkeywords[0].KeywordSubPath + "\\" + Path.GetFileName(LocalPath); } else { f.FilePath = Path.GetFileName(LocalPath); } f.FileVersion = View.BookVersion; f.Book = b; f.BookResource = View.IsResource; f.FileDesc = View.FileDescription; f.UserID = DataSettings.Default.User.UserID; db.Books.InsertOnSubmit(b); db.Files.InsertOnSubmit(f); db.SubmitChanges(); b.File = f;// 出现循环的时候,还需要这么搞一下? db.SubmitChanges(); foreach (Keywords k in bookkeywords) { BookKeywords bk = new BookKeywords(); bk.Book = b; bk.Keywords = k; b.BookKeywords.Add(bk); db.BookKeywords.InsertOnSubmit(bk); } f.FilePath = JianLi3FileServiceManager.Default.MoveToLib(LocalPath, f); // 更新数据库 db.SubmitChanges(); } iscreated = true; }
// Book public static bool UpdateBookCover(ref Book b, JianLi3Data.File file) { return(UpdateBookCover(ref b, JianLi3FileServiceManager.Default.GetPath(file))); }