コード例 #1
0
 private void recommendButton_Click(object sender, EventArgs e)//推荐
 {
     currentBook.Recommend = currentBook.Recommend + 1;
     BookShelfService.UpdateBook(currentBook);
     this.recommendButton.Enabled = false;
     this.recommendButton.Visible = false;
 }
コード例 #2
0
        public async Task CanLoanBook()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;

            await using var context = new ApplicationDbContext(options);

            var       userId = Guid.NewGuid().ToString();
            const int bookId = -1;

            context.Books.Add(new Book("foo", "bar", "test book")
            {
                ID = bookId
            });
            context.Users.Add(new User {
                UserName = "******", ID = userId
            });
            await context.SaveChangesAsync();

            var service = new BookShelfService(context);
            var user    = await service.FindUserAsync(userId);

            var book = await service.FindBookAsync(bookId);

            await service.RegisterLoanAsync(book, user);

            var exists = await context.Loans.AnyAsync(l => l.Book == book && l.User == user);

            Assert.True(exists);
        }
コード例 #3
0
 private void sortButton_Click(object sender, EventArgs e)//按分类管理
 {
     isNormal = false;
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     bookBindingSource.DataMember  = null;
     bookBindingSource.DataSource  = BookShelfService.Query(4);
 }
コード例 #4
0
 private void refreshButton_Click(object sender, EventArgs e)//刷新
 {
     isNormal = true;
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     bookBindingSource.DataSource  = shelfBindingSource;
     bookBindingSource.DataMember  = "Books";
 }
コード例 #5
0
        private void deleteShelfButton_Click(object sender, EventArgs e)//删除书架
        {
            BookShelf shelf = shelfBindingSource.Current as BookShelf;

            BookShelfService.RemoveBookShelf(shelf.BookShelfId);
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
コード例 #6
0
 public FormManage(FormMain form, Client client)
 {
     InitializeComponent();
     this.formMain      = form;
     this.currentClient = client;
     this.shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
 }
コード例 #7
0
 public FormDetail(FormLibrary form2, Book book, Client client)//从馆内藏书界面进入
 {
     InitializeComponent();
     this.Flag                         = 2;
     resPath                           = BookShelfService.findPath();
     this.currentBook                  = book;
     this.currentClient                = client;
     this.formLibrary                  = form2;
     this.nameTextBox.Text             = book.Name;
     this.nameTextBox.ReadOnly         = true;
     this.authorTextBox.Text           = book.Author;
     this.authorTextBox.ReadOnly       = true;
     this.sortTextBox.Text             = book.Sort;
     this.sortTextBox.ReadOnly         = true;
     this.shelfIdTextBox.Text          = book.BookShelfId;
     this.shelfIdTextBox.ReadOnly      = true;
     this.introductionTextBox.Text     = book.Description;
     this.introductionTextBox.ReadOnly = true;
     if (book.imagePath != null)
     {
         if (File.Exists(book.imagePath))
         {
             FileStream fs = File.Open(book.imagePath, FileMode.Open);
             this.discoverPictureBox.Image = Image.FromStream(fs);
             fs.Close();
             //this.discoverPictureBox.Image = Image.FromFile(book.imagePath);
         }
     }
     this.choosePictureButton.Visible = false;
     this.addButton.Visible           = false;
 }
コード例 #8
0
 public FormLibrary(FormMain form, Client client)
 {
     InitializeComponent();
     this.formMain      = form;
     this.currentClient = client;
     this.bookBindingSource.DataSource = BookShelfService.AllBooks();
 }
コード例 #9
0
        private void queryButton_Click(object sender, EventArgs e)//排序
        {
            List <Book> books = new List <Book>();

            switch (queryComboBox.Text)
            {
            case "推荐数":
                books = BookShelfService.Query(1);
                break;

            case "书号":
                books = BookShelfService.Query(2);
                break;

            case "作者":
                books = BookShelfService.Query(3);
                break;

            case "分类":
                books = BookShelfService.Query(4);
                break;

            case "书架号":
                books = BookShelfService.Query(5);
                break;

            default:
                MessageBox.Show("没有选择正确的排序方式!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;
            }
            this.bookBindingSource.DataSource = books;
        }
コード例 #10
0
 public void resetAppointAndLend()
 {
     appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
     this.appointBindingSource.DataSource = appointBooks;
     lendBooks = BookShelfService.GetAllLentBooks(currentClient);
     this.lendBindingSource.DataSource = lendBooks;
     this.nameTextBox.Text             = currentClient.Name;
 }
コード例 #11
0
        private void addShelfButton_Click(object sender, EventArgs e)//添加书架
        {
            int k = Convert.ToInt32(BookShelfService.GetAllShelfs().Max(i => i.BookShelfId)) + 1;

            BookShelfService.AddBookShelf(new BookShelf()
            {
                BookShelfId = k + ""
            });
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
コード例 #12
0
        private void finishButton_Click(object sender, EventArgs e)//完成
        {
            switch (Flag)
            {
            case 1:
                formAccount.Show();
                formAccount.resetAppointAndLend();
                formAccount.Parent = null;
                this.Close();
                break;

            case 2:
                formLibrary.Show();
                formLibrary.resetBooks();
                formLibrary.Parent = null;
                this.Close();
                break;

            case 3:
                formManage.Show();
                formManage.resetLibrary();
                formManage.Parent = null;
                this.Close();
                break;

            case 4:
                currentBook.Name        = this.nameTextBox.Text;
                currentBook.Author      = this.authorTextBox.Text;
                currentBook.Sort        = this.sortTextBox.Text;
                currentBook.Description = this.introductionTextBox.Text;
                BookShelfService.UpdateBook(currentBook);
                if (path != null)
                {
                    if (File.Exists(resPath + @"\" + currentBook.Name + ".jpg"))
                    {
                        File.Delete(resPath + @"\" + currentBook.Name + ".jpg");
                    }
                    FileStream fr       = File.Open(path, FileMode.Open);
                    FileStream fw       = File.Open(resPath + @"\" + currentBook.Name + ".jpg", FileMode.Create);
                    Image      newImage = Image.FromStream(fr);
                    newImage.Save(fw, System.Drawing.Imaging.ImageFormat.Jpeg);
                    currentBook.imagePath = resPath + @"\" + currentBook.Name + ".jpg";
                    fr.Close();
                    fw.Close();
                }
                formManage.Show();
                formManage.resetLibrary();
                formManage.Parent = null;
                this.Close();
                break;

            default:
                break;
            }
        }
コード例 #13
0
        private void deleteBookButton_Click(object sender, EventArgs e)//删除书籍
        {
            Book book = bookBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.RemoveBooks(book.BookId);
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
コード例 #14
0
 public FormDetail(FormManage form3, BookShelf shelf, Client client)//从图书管理界面的添加书籍进入
 {
     InitializeComponent();
     this.Flag                    = 3;
     resPath                      = BookShelfService.findPath();
     this.currentShelf            = shelf;
     this.currentClient           = client;
     this.formManage              = form3;
     this.shelfIdTextBox.Text     = shelf.BookShelfId;
     this.shelfIdTextBox.ReadOnly = true;
     this.appointButton.Visible   = false;
     this.lendButton.Visible      = false;
     this.recommendButton.Visible = false;
 }
コード例 #15
0
        private void returnButton_Click(object sender, EventArgs e)//还书
        {
            Book book = lendBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.ReturnBooks(book, currentClient);
            lendBooks = new List <Book>();
            lendBindingSource.DataSource = lendBooks;
            lendBooks = BookShelfService.GetAllLentBooks(currentClient);
            lendBindingSource.ResetBindings(false);
            lendBindingSource.DataSource = lendBooks;
        }
コード例 #16
0
        private void cancellButton_Click(object sender, EventArgs e)//取消预约
        {
            Book book = appointBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.CancellAppoint(book, currentClient);
            appointBooks = new List <Book>();
            appointBindingSource.DataSource = appointBooks;
            appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
            appointBindingSource.ResetBindings(false);
            appointBindingSource.DataSource = appointBooks;
        }
コード例 #17
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("没有输入完整的信息!");
     }
 }
コード例 #18
0
        static void Main(string[] args)
        {
            #region init book and shelf

            var bookShelfServ = new BookShelfService(new BookShelf
            {
                Name = "Tolkien's books"
            });

            bookShelfServ.AddBook(new Book
            {
                Name       = "Lord of Rings",
                NumOfPages = 789,
                Authors    = new List <string>(new string[] { "Tolkien" }),
                Year       = 1978
            });

            #endregion init book and shelf

            var session1 = new ConsoleSession(bookShelfServ);
            session1.NewSession();
        }
コード例 #19
0
        private void searchPictureBox_Click(object sender, EventArgs e)//查询
        {
            List <Book> books = new List <Book>();

            if (searchTextBox.Text == null)
            {
                MessageBox.Show("没有输入用于查询的关键词!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                switch (searchComboBox.Text)
                {
                case "书号":
                    books = BookShelfService.Search(1, searchTextBox.Text);
                    break;

                case "书名":
                    books = BookShelfService.Search(2, searchTextBox.Text);
                    break;

                case "作者":
                    books = BookShelfService.Search(3, searchTextBox.Text);
                    break;

                case "分类":
                    books = BookShelfService.Search(4, searchTextBox.Text);
                    break;

                case "书架号":
                    books = BookShelfService.Search(5, searchTextBox.Text);
                    break;

                default:
                    MessageBox.Show("没有选择正确的查询方式!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
            }
            this.bookBindingSource.DataSource = books;
        }
コード例 #20
0
        private void newButton_Click(object sender, EventArgs e)//续借
        {
            Book book = lendBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            if (book.reNewNum < 3)
            {
                BookShelfService.ReNewLending(book, currentClient);
            }
            else
            {
                MessageBox.Show("该书续借次数太多,不允许继续续借!");
            }
            lendBooks = new List <Book>();
            lendBindingSource.DataSource = lendBooks;
            lendBooks = BookShelfService.GetAllLentBooks(currentClient);
            lendBindingSource.ResetBindings(false);
            lendBindingSource.DataSource = lendBooks;
        }
コード例 #21
0
        public async Task CanGetAllBooks()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;

            await using var context = new ApplicationDbContext(options);

            var testBooks = new List <Book>
            {
                new Book("foo", "bar", "test book")
                {
                    ID = 1
                },
                new Book("bar", "foo", "book test")
                {
                    ID = 2
                }
            };

            foreach (var book in testBooks)
            {
                context.Books.Add(book);
            }

            await context.SaveChangesAsync();

            var service  = new BookShelfService(context);
            var allBooks = service.GetAllBooks().ToList();

            var correctLength       = allBooks.Count == testBooks.Count;
            var containsAllElements = allBooks.All(b => testBooks.Contains(b));

            Assert.True(correctLength && containsAllElements);
        }
コード例 #22
0
 public BookShelfController(ILogger <BookShelfController> logger, BookShelfService bookShelfService)
 {
     _logger           = logger;
     _bookShelfService = bookShelfService;
 }
コード例 #23
0
        public void resetBooks()
        {
            List <Book> books = BookShelfService.AllBooks();

            this.bookBindingSource.DataSource = books;
        }
コード例 #24
0
 private void appointButton_Click(object sender, EventArgs e)//预约
 {
     BookShelfService.AppointBook(currentBook, currentClient);
     this.appointButton.Enabled = false;
     this.appointButton.Visible = false;
 }
コード例 #25
0
 public BookShelfController(BookShelfService bookShelfService)
 {
     _bshelf = bookShelfService;
 }
コード例 #26
0
 public BookShelfController(BookShelfService bookShelfService, ApplicationDbContext dbContext)
 {
     this.bookShelfService = bookShelfService;
     this.dbContext        = dbContext;
 }
コード例 #27
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;
            }
        }
コード例 #28
0
 private void lendButton_Click(object sender, EventArgs e)//借阅
 {
     BookShelfService.LendBook(currentBook, currentClient);
 }
コード例 #29
0
 public void resetLibrary()
 {
     this.shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
 }