Example #1
0
 public FormLibrary(FormMain form, Client client)
 {
     InitializeComponent();
     this.formMain      = form;
     this.currentClient = client;
     this.bookBindingSource.DataSource = BookShelfService.AllBooks();
 }
Example #2
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)
         {
             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("没有输入完整的信息!");
     }
 }
Example #3
0
        public void resetBooks()
        {
            List <Book> books = BookShelfService.AllBooks();

            this.bookBindingSource.DataSource = books;
        }
Example #4
0
        private void searchPictureBox_Click(object sender, EventArgs e)//查询
        {
            if (searchTextBox.Text == null)
            {
                MessageBox.Show("没有输入用于查询的关键词!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                String      key         = searchTextBox.Text;
                List <Book> searchBooks = new List <Book>();
                switch (searchComboBox.Text)
                {
                case "书号":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.BookId.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.BookId.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "书名":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Name.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Name.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "作者":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Author.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Author.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "分类":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Sort.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Sort.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                default:
                    MessageBox.Show("没有选择正确的查询方式!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                bookBindingSource.DataMember = null;
                bookBindingSource.DataSource = searchBooks;
            }
        }