public static void Test2() { BookShelf test2 = new BookShelf(); Book book1 = new Book("5", "C#程序设计语言", "2", "Peter Golde", "C#编程指南。", null, null, "编程", "") { State = "可正常使用", Recommend = 14, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\C#程序设计语言.jpg" }; Book book2 = new Book("6", "JAVA语言程序设计", "2", "佚名", "JAVA编程指南。", "2020年5月1日", "李梦凡", "编程", user1 + " ") { State = "已被借阅", Recommend = 12, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\JAVA语言程序设计.jpg" }; Book book3 = new Book("7", "三国演义", "2", "罗贯中", "罗贯中所写的一本书。", "2020年9月1日", "康盛尧", "文学", user1 + " " + user3 + " ") { State = "已被借阅", Recommend = 13, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\三国演义.jpg" }; List <Book> Books2 = new List <Book>() { book1, book2, book3 }; foreach (var book in Books2) { test2.AddBook(book); } test2.BookShelfId = "2"; BookShelfService.AddBookShelf(test2); }
public int CompareTo(BookShelf other) { if (other == null) { return(1); } return(this.BookShelfId.CompareTo(other.BookShelfId)); }
public static void UpdateShelf(BookShelf newBookShelf)//更新数据库内的书架 { RemoveBooksFromShelf(newBookShelf.BookShelfId); using (var db = new BookShelfContext()) { db.Entry(newBookShelf).State = EntityState.Modified; db.Books.AddRange(newBookShelf.Books); db.SaveChanges(); } }
public static BookShelf AddBookShelf(BookShelf shelf)//添加新的书架 { try { using (var db = new BookShelfContext()) { db.BookShelves.Add(shelf); db.SaveChanges(); MessageBox.Show("已成功添加书架!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(shelf); } catch (Exception e) { MessageBox.Show("添加书架错误!" + e.ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); throw new ApplicationException($"添加书架错误: {e.Message}"); } }
public static void Test1() { BookShelf test1 = new BookShelf(); Book book1 = new Book("1", "毛泽东选集", "1", "毛泽东", "毛泽东所写的一本书。", null, null, "政治", "") { State = "可正常使用", Recommend = 10, imagePath = BookShelfService.findPath() + @"\" + "毛泽东选集" + ".jpg" }; Book book2 = new Book("2", "论持久战", "1", "毛泽东", "毛泽东所写的一本书。", "2020年8月1日", "涂珈玮", "政治", "") { State = "已被借阅", Recommend = 15, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\论持久战.jpg" }; Book book3 = new Book("3", "钢铁是怎样炼成的", "1", "奥斯特洛夫斯基", "奥斯特洛夫斯基所写的一本书。", "2020年8月1日", "涂珈玮", "文学", user2 + " ") { State = "已被借阅", Recommend = 15, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\钢铁是怎样炼成的.jpg" }; Book book4 = new Book("4", "西游记", "1", "吴承恩", "吴承恩所写的一本书。", "2020年8月1日", "康盛尧", "文学", user3 + " ") { State = "已被借阅", Recommend = 13, imagePath = @"C:\Users\tjw20\source\repos\LibrarySystem-Final\discovers\西游记.jpg" }; List <Book> Books1 = new List <Book>() { book1, book2, book3, book4 }; foreach (var book in Books1) { test1.AddBook(book); } test1.BookShelfId = "1"; BookShelfService.AddBookShelf(test1); }