public static void main(String[] args)
        {
            // Create a Book class, that has an author, a title and a release year
            // Create a constructor for setting those values
            // Book should have a toString() method that returns a string in this format:
            // Douglas Adams : The Hitchhiker's Guide to the Galaxy (1979)
            // Create a BookShelf class that has a list of books in it
            // We should be able to add and remove books
            // We should be able to query the favourite author (who has written the most books in the shelf)
            // We should be able to query the earliest published books.
            // We should be able to query the latest published books.
            // Bookself should have a toString() method which give us information about the number of books, the earliest and the latest released books, and the favourite author

            BookShelf myShelf = new BookShelf();

            myShelf.toString();
            // Should print out:
            // You have no books here.

            myShelf.put("Douglas Adams", "The Hitchhiker's Guide to the Galaxy", 1979);
            myShelf.put("Douglas Adams", "Mostly Harmless", 1992);
            myShelf.put("Frank Herbert", "Dune", 1965);
            myShelf.put("Frank Herbert", "The Dragon in the Sea", 1957);
            myShelf.remove("The Dragon in the Sea");

            myShelf.toString();
            // Should print out:
            // You have 3 books.
            // Earliest released: Frank Herbert : Dune (1965)
            // Latest released: Douglas Adams : Mostly Harmless (1992)
            // Favourite author: Douglas Adams
        }
Exemple #2
0
        private void deleteShelfButton_Click(object sender, EventArgs e)//删除书架
        {
            BookShelf shelf = shelfBindingSource.Current as BookShelf;

            BookShelfService.RemoveBookShelf(shelf.BookShelfId);
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
Exemple #3
0
        public int Flag = 0;                   //指示该界面由主界面还是图书管理界面进入(可能无用)
        public FormBookDetail(BookShelf shelf) //只有书架参数,表示是由添加新书按钮进入,所有文本框均为空并可用,但借阅、预约、推荐相关组件不可使用,基本完成
        {
            InitializeComponent();
            currentShelf                 = shelf;
            this.lendButton.Enabled      = false;
            this.lendButton.Visible      = false;
            this.recommendButton.Enabled = false;
            this.recommendButton.Visible = false;
            this.appointButton.Enabled   = false;
            this.appointButton.Visible   = false;
            this.shelfTextBox.Text       = shelf.BookShelfId;
            this.shelfTextBox.ReadOnly   = true;

            //与预约相关的控件
            this.textBox1.Enabled      = false;
            this.textBox1.Visible      = false;
            this.textBox2.Enabled      = false;
            this.textBox2.Visible      = false;
            this.textBox3.Enabled      = false;
            this.textBox3.Visible      = false;
            this.yearComboBox.Enabled  = false;
            this.yearComboBox.Visible  = false;
            this.monthComboBox.Enabled = false;
            this.monthComboBox.Visible = false;
            this.dayComboBox.Enabled   = false;
            this.dayComboBox.Visible   = false;
            findPath();
        }
Exemple #4
0
 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();
     }
 }
Exemple #6
0
        private void addButton_Click(object sender, EventArgs e)//添加图书,必须选取一个书架才能添加
        {
            BookShelf      shelf          = shelfBindingSource.Current as BookShelf;
            FormBookDetail formBookDetail = new FormBookDetail(shelf);

            if (formBookDetail.ShowDialog() == DialogResult.OK)
            {
                shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
                bookBindingSource.DataSource  = shelfBindingSource;
                bookBindingSource.DataMember  = "Books";
            }
        }
Exemple #7
0
        private void changeDetailButton_Click(object sender, EventArgs e)//修改图书细节
        {
            BookShelf      shelf          = shelfBindingSource.Current as BookShelf;
            Book           book           = bookBindingSource.Current as Book;
            FormBookDetail formBookDetail = new FormBookDetail(book, currentClient, 2);

            if (formBookDetail.ShowDialog() == DialogResult.OK)
            {
                shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
                bookBindingSource.DataSource  = shelfBindingSource;
                bookBindingSource.DataMember  = "Books";
            }
        }
Exemple #8
0
        public static void Test1()
        {
            //MessageBox.Show(administrator1);
            //MessageBox.Show(administrator2);
            BookShelf test1 = new BookShelf();
            Book      book1 = new Book("1", "毛泽东选集", "1", "毛泽东", "毛泽东所写的一本书。", null, null, "政治", "")
            {
                State     = "可正常使用",
                Recommend = 10,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\毛泽东选集.jpg"
            };
            Book book2 = new Book("2", "论持久战", "1", "毛泽东", "毛泽东所写的一本书。", "2020年8月1日", "涂珈玮", "政治", "")
            {
                State     = "已被借阅",
                Recommend = 15,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\论持久战.jpg"
            };
            //book2.Appointer = ClientService.transferIntoAppointer(administrator2, book2);
            //book2.Appointers.Add(administrator2);
            Book book3 = new Book("3", "钢铁是怎样炼成的", "1", "奥斯特洛夫斯基", "奥斯特洛夫斯基所写的一本书。", "2020年8月1日", "涂珈玮", "文学", user2 + " ")
            {
                State     = "已被借阅",
                Recommend = 15,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\钢铁是怎样炼成的.jpg"
            };
            //book3.Appointer = ClientService.transferIntoAppointer(administrator2, book3);
            //book3.Appointers.Add(administrator2);
            Book book4 = new Book("4", "西游记", "1", "吴承恩", "吴承恩所写的一本书。", "2020年8月1日", "康盛尧", "文学", user3 + " ")
            {
                State     = "已被借阅",
                Recommend = 13,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\西游记.jpg"
            };
            //book4.Appointer = ClientService.transferIntoAppointer(administrator2, book4);
            //book4.Appointers.Add(administrator2);
            List <Book> Books1 = new List <Book>()
            {
                book1, book2, book3, book4
            };

            foreach (var book in Books1)
            {
                //MessageBox.Show(book.Name+book.Appointer.Count()+"");
                //book.setAppoint();
                test1.AddBook(book);
            }
            test1.BookShelfId = "1";
            BookShelfService.AddBookShelf(test1);
        }
 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}");
     }
 }
Exemple #10
0
        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\Library\Resources\C#程序设计语言.jpg"
            };

            Book book2 = new Book("6", "JAVA语言程序设计", "2", "佚名", "JAVA编程指南。", "2020年5月1日", "李梦凡", "编程", user1 + " ")
            {
                State     = "已被借阅",
                Recommend = 12,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\JAVA语言程序设计.jpg"
            };
            //book2.Appointer = ClientService.transferIntoAppointer(administrator1, book2);
            //book2.Appointers.Add(administrator2);
            Book book3 = new Book("7", "三国演义", "2", "罗贯中", "罗贯中所写的一本书。", "2020年9月1日", "康盛尧", "文学", user1 + " " + user3 + " ")
            {
                State     = "已被借阅",
                Recommend = 13,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\三国演义.jpg"
            };
            //book3.Appointer = ClientService.transferIntoAppointer(administrator1, book3);
            List <Book> Books2 = new List <Book>()
            {
                book1, book2, book3
            };

            foreach (var book in Books2)
            {
                test2.AddBook(book);
            }
            test2.BookShelfId = "2";
            BookShelfService.AddBookShelf(test2);
        }
Exemple #11
0
        private void searchButton_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;
            }
        }