示例#1
0
 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)
         {
             File.Copy(path, resPath + @"\" + newBook.Name + ".jpg");
             newBook.imagePath = path;
         }
         currentShelf.AddBook(newBook);
         BookShelfService.UpdateShelf(currentShelf);
         MessageBox.Show("已添加新书!");
         this.addButton.Enabled = false;
         this.addButton.Visible = false;
     }
     else
     {
         MessageBox.Show("没有输入完整的信息!");
     }
 }