private void addButton_Click(object sender, EventArgs e)//加入书架 { if (nameTextBox.Text != null && authorTextBox.Text != null && sortTextBox.Text != null && introductionTextBox.Text != null) { int k = Convert.ToInt32(BookShelfService.AllBooks().Max(i => i.BookId)) + 1; string bookId = k + ""; string name = this.nameTextBox.Text; string author = this.authorTextBox.Text; string bookShelfId = currentShelf.BookShelfId; string lendTime = null; string clientName = null; string sort = this.sortTextBox.Text; string appointers = ""; string description = this.introductionTextBox.Text; Book newBook = new Book(bookId, name, bookShelfId, author, description, lendTime, clientName, sort, appointers) { State = "可正常使用" }; if (path != null) { FileStream fr = File.Open(path, FileMode.Open); FileStream fw = File.Open(resPath + @"\" + newBook.Name + ".jpg", FileMode.Create); Image newImage = Image.FromStream(fr); newImage.Save(fw, System.Drawing.Imaging.ImageFormat.Jpeg); newBook.imagePath = resPath + @"\" + newBook.Name + ".jpg"; fr.Close(); fw.Close(); } currentShelf.AddBook(newBook); BookShelfService.UpdateShelf(currentShelf); MessageBox.Show("已添加新书!"); this.addButton.Enabled = false; this.addButton.Visible = false; } else { MessageBox.Show("没有输入完整的信息!"); } }