// 双击时打开默认文件 private void listView1_DoubleClick(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 1) { BookAndUser bu = (BookAndUser)(listView1.SelectedItems[0].Tag); Book b = bu.Book; if (b.Files != null) { FileViewer.OpenFile(b.File); } if (bu.UserBook == null) { UserBooks ub = JianLiLinq.Default.CreateUserBook(b); ub.BookReadCounts = 1; JianLiLinq.Default.DB.SubmitChanges(); } else { bu.UserBook.BookReadCounts++; db.SubmitChanges(); } } }
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; }
private void NewCategory() { if (this.CategoryTree.SelectedNode.Tag is Categories) { Categories cparent = (Categories)(CategoryTree.SelectedNode.Tag); NewCategoryForm ncf = new NewCategoryForm(); if (ncf.ShowDialog() == DialogResult.OK) { Categories c = new Categories { CategoryName = ncf.CategoryName, CategoryDesc = ncf.CategoryDesc, CategoryParent = cparent.CategoryID }; db.Categories.InsertOnSubmit(c); db.SubmitChanges(); TreeNode tn = new TreeNode(); tn.Tag = c; tn.Text = c.CategoryName; tn.ToolTipText = c.CategoryDesc; CreateSonNode(this.CategoryTree.SelectedNode); // 起码要初始化 this.CategoryTree.SelectedNode.Nodes.Add(tn); // 完成节点添加 } } }