Example #1
0
        public void T12_SearchByAuthor_SearchForBookByAuthor()
        {
            Author testAuthor1 = new Author("Franzen");
              testAuthor1.Save();
              Author testAuthor2 = new Author("Rowling");
              testAuthor2.Save();

              Book testBook1 = new Book("Freedom");
              testBook1.Save();
              Book testBook2 = new Book("Harry Potter and the Deathly Hallows");
              testBook2.Save();
              Book testBook3 = new Book("Harry Potter and the Chamber of Secrets");
              testBook3.Save();

              testBook1.AddAuthor(testAuthor1);
              testBook2.AddAuthor(testAuthor2);
              testBook3.AddAuthor(testAuthor2);

              List<Book> result = Book.SearchByAuthor("Rowling");
              List<Book> testBooks = new List<Book> {testBook2, testBook3};
              // Console.WriteLine(testBooks[0].GetTitle());
              // Console.WriteLine(result[0].GetTitle());
              // Console.WriteLine(testBooks[1].GetTitle());
              // Console.WriteLine(result[1].GetTitle());

              Assert.Equal(testBooks, result);
        }
Example #2
0
 private void Borrow_Submit_Click(object sender, EventArgs e)
 {
     book.Title = BorrowBook_textbox.Text;
     if (!manager.CheckBookExists(book))
     {
         MessageBox.Show("此本书不存在!请核实您所输入的书名!");
         return;
     }
     book = manager.getBook(book);
     if (book.Num > 0)
     {
         if (!manager.checkBookHadBorrow(user, book))
         {
             manager.borrowBook(user, book);
             MessageBox.Show("借阅成功!请于2个月后归还!");
         }
         else
         {
             MessageBox.Show("这本书您已经借阅过了!");
             return;
         }
     }
     else
     {
         MessageBox.Show("图书已全部借出!库存量已经为0!");
     }
 }
Example #3
0
        public void Test_Equal_EntriesMatch()
        {
            Book testBook1 = new Book ("Redwall");
              Book testBook2 = new Book ("Redwall");

              Assert.Equal(testBook1, testBook2);
        }
Example #4
0
        public static Book Find(int id)
        {
            SqlConnection connection = DB.Connection();
              connection.Open();

              SqlCommand command = new SqlCommand("SELECT * FROM books WHERE id = @BookId;", connection);
              SqlParameter idParameter = new SqlParameter();
              idParameter.ParameterName = "@BookId";
              idParameter.Value = id.ToString();
              command.Parameters.Add(idParameter);

              SqlDataReader reader = command.ExecuteReader();

              int foundId = 0;
              string foundTitle = null;

              while(reader.Read())
              {
            foundId = reader.GetInt32(0);
            foundTitle = reader.GetString(1);
              }
              Book foundBook = new Book(foundTitle, foundId);

              if (reader != null)
              {
            reader.Close();
              }
              if (connection != null)
              {
            connection.Close();
              }
              return foundBook;
        }
Example #5
0
        static void Main(string[] args)
        {
            Book book1 = new Book();
            book1.Title = "Wilbur's Wonderful Life";

            Shelf.Add(book1);

            foreach (var book in Shelf.arrayOfBooks)
            {
                Console.WriteLine(book.Title);
            }

            Console.Write("Please enter a book title: ");
            string input = Console.ReadLine();

            Book book2 = new Book();
            book2.Title = input;

            Shelf.Add(book2);

            foreach(var book in Shelf.arrayOfBooks)
            {
                Console.WriteLine(book.Title);
            }
            Console.Read();
        }
Example #6
0
 public bool checkBookExist(Book b)
 {
     try
     {
         conn.Open();
         string sql = "SELECT * FROM [Library].[dbo].[Book] where [title]='" + b.Title + "'";
         sqlcom = new SqlCommand(sql, conn);
         object tp = sqlcom.ExecuteScalar();
         if (tp == null)
         {
             return false;
         }
         else
         {
             return true;
         }
     }
     catch
     {
         throw;
     }
     finally
     {
         conn.Close();
     }
 }
Example #7
0
        public static Book Find(int searchId)
        {
            Book foundBook = new Book(""); //Program needs some value inside a Book object
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT * FROM books WHERE id = @BookId;", conn);

              SqlParameter idParameter = new SqlParameter();
              idParameter.ParameterName = "@BookId";
              idParameter.Value = searchId;

              cmd.Parameters.Add(idParameter);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int bookId = rdr.GetInt32(0);
            string bookTitle = rdr.GetString(1);
            Book newBook = new Book(bookTitle, bookId);
            foundBook = newBook;
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundBook;
        }
Example #8
0
        public static Book CreateBook(string name, string author, DateTime takeDate, DateTime returnDate)
        {
            Book book = new Book();
            book.Name = name;
            book.Author = author;
            book.TakeDate = takeDate;
            book.ReturnDate = returnDate;

            return book;
        }
Example #9
0
 public EditBook(Book b,CheckBookInfo test)
 {
     book = b;
     InitializeComponent();
     c = test;
     Book_Title.Text = book.Title;
     Book_content.Text = book.Content;
     Book_num.Text = book.Num.ToString() ;
     Book_publisher.Text = book.Publisher;
     Book_publishing_home.Text = book.Publishing_home;
     dateTimePicker1.Value = book.Date;
 }
Example #10
0
        public void Test_GetAuthors()
        {
            Author a = new Author("Allen");
              a.Save();

              Book newbook = new Book("2a", "Sf", "The blob");
              newbook.Save();

              newbook.AddAuthor(a.id);

              Assert.Equal(a.id, newbook.GetAuthors()[0].id);
        }
Example #11
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            //създаваме нова книга чрез конструктора Books()
            try
            {
                if (textBoxInvNum.Text != "" && textBoxTitle.Text != "")
                {
                    Book newBook = new Book();
                    //на съответните полета присвояваме стойностите от текстовите кутии
                    newBook.InvNum = textBoxInvNum.Text;
                    newBook.ISBN = textBoxISBN.Text;
                    newBook.Title = textBoxTitle.Text;
                    newBook.Description = textBoxDescription.Text;
                    newBook.YearPub = Int32.Parse(textBoxYearPubl.Text);
                    newBook.Price = Decimal.Parse(textBoxPrice.Text);
                    newBook.Rejection = false;
                    newBook.CategoryID = Int32.Parse(comboBoxCategory.SelectedValue.ToString());
                    newBook.LanguageID = Int32.Parse(comboBoxLanguage.SelectedValue.ToString());
                    // обработка на селектираните редове от  DataGridViewAuthors - това са авторите на новата книга
                    int authorID;//локална променлива
                    foreach (DataGridViewRow row in dataGridViewAuthors.SelectedRows)
                    {
                        authorID = Convert.ToInt32(row.Cells[0].Value);//вземаме стойността Value на ID на автора от текущо селектирания ред - row.Cells[0].Value
                        //добавяне на данните за автора към свойството Authors на книгата, която обработваме
                        //свойството не е просто свойство, а е списък (List) от автори
                        newBook.Authors.Add(context.Authors.ToList().Find(a => a.AuthorID == authorID));
                    }
                    //добавяне на новата книга в базата и записване на промените
                    context.Books.AddObject(newBook);
                    context.SaveChanges();
                    MessageBox.Show("Книгата е добавена!");
                }
                else
                {
                    MessageBox.Show("Грешка! Не сте въвели данни.");
                }

            }
            catch (FormatException)
            {
                MessageBox.Show("Вие не сте въвели данни! " + "Книгата не е добавена!");
            }
            if (MessageBox.Show("Ще въвеждате ли други книги?", "Добавяне на книга",
                        MessageBoxButtons.YesNo) == DialogResult.No)
            {
                this.Close();
            }
            else
            {
                Clear();
            }
        }
        public void Test_AddBook_AddsBookToAuthor()
        {
            Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();
              Book newBook = new Book ("Redwall");
              newBook.Save();
              newAuthor.AddBook(newBook);

              List<Book> testBook = new List<Book> {newBook};
              List<Book> allBooks = newAuthor.GetBooks();

              Assert.Equal(testBook, allBooks);
        }
Example #13
0
        public void Test_AddAuthor_AddsAuthorToBook()
        {
            Book newBook = new Book ("Redwall");
              newBook.Save();
              Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();
              newBook.AddAuthor(newAuthor);

              List<Author> testAuthor = new List<Author> {newAuthor};
              List<Author> allAuthors = newBook.GetAuthors();

              Assert.Equal(testAuthor, allAuthors);
        }
Example #14
0
        public void Test_FindByAuthor_FindsBookByAuthor()
        {
            Book testBook = new Book ("Redwall");
              testBook.Save();
              Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();

              testBook.AddAuthor(newAuthor);

              List<Book> testBookList = new List<Book> {testBook};
              List<Book> resultBookList = Book.FindByAuthor("Jac.Ques");

              Assert.Equal(testBookList, resultBookList);
        }
Example #15
0
        public void Test_DeleteOne_DeletesOneBook()
        {
            Book newBook1 = new Book ("Redwall");
              Book newBook2 = new Book ("Memnoch the Devil");
              newBook1.Save();
              newBook2.Save();
              List<Book> newList = Book.GetAll();

              newBook1.DeleteOne();

              List<Book> resultList = Book.GetAll();
              List<Book> testList = new List<Book> {newBook2};

              Assert.Equal(testList, resultList);
        }
Example #16
0
        public void T11_SearchByTitle_SearchForBookByTitle()
        {
            Book testBook1 = new Book("Harry Potter and the Deathly Hallows");
              testBook1.Save();
              Book testBook2 = new Book("Freedom");
              testBook2.Save();
              Book testBook3 = new Book("James and the Giant Peach");
              testBook3.Save();

              List<Book> result = Book.SearchByTitle("Freedom");
              List<Book> testBooks = new List<Book> {testBook2};
              // Console.WriteLine(result[0].GetTitle());
              // Console.WriteLine(testBooks[0].GetTitle());

              Assert.Equal(testBooks, result);
        }
Example #17
0
 public int borrowBook(User user, Book book)
 {
     try
     {
         int tp = bookDAO.BorrowBooks(user, book);
         user.HadBorrow++;
         user.CountBorrow++;
         userDAO.updateUser(user);
         book.Num--;
         bookDAO.updateBook(book);
         return tp;
     }
     catch
     {
         return 0;
     }
 }
Example #18
0
        public void T10_AddExistingAuthor()
        {
            Author testAuthor1 = new Author("Franzen");
              testAuthor1.Save();
              Author testAuthor2 = new Author("Franzen");
              testAuthor2.Save();

              Book testBook = new Book("Freedom");
              testBook.Save();
              Book testBook2 = new Book("Example");
              testBook2.Save();

              testBook.AddAuthor(testAuthor1);
              testBook.AddAuthor(testAuthor2);

              int result = testBook.GetAuthors().Count;

              Assert.Equal(1, result);
        }
Example #19
0
        public HomeModule()
        {
            Get["/"] = _ => {
            Dictionary<string, object> model = new Dictionary<string, object>();
            List<Book> booksByTitle = Book.SearchByTitle("VOID-SEARCH-TO-PREVENT-DATA");
            List<Book> booksByAuthor = Book.SearchByAuthor("VOID-SEARCH-TO-PREVENT-DATA");
            model.Add("booksByTitle", booksByTitle);
            model.Add("booksByAuthor", booksByAuthor);
            return View["index.cshtml", model];
              };

              Get["/librarian"] = _ => {
            return View["librarian.cshtml"];
              };

              Post["/success"] = _ => {
            Book newBook = new Book(Request.Form["title-input"]);
            newBook.Save();

            Author newAuthor = new Author(Request.Form["author-input"]);
            newAuthor.Save();

            newBook.AddAuthor(newAuthor);

            Dictionary<string, object> model = new Dictionary<string, object>();
            model.Add("addedBook", newBook);
            model.Add("addedAuthor", newAuthor);

            return View["success.cshtml", model];
              };

              Post["/results"] = _ => {
            string input = Request.Form["search-input"];
            Dictionary<string, object> model = new Dictionary<string, object>();
            List<Book> booksByTitle = Book.SearchByTitle(input.ToString());
            List<Book> booksByAuthor = Book.SearchByAuthor(input.ToString());
            model.Add("booksByTitle", booksByTitle);
            model.Add("booksByAuthor", booksByAuthor);
            return View["index.cshtml", model];
              };
        }
Example #20
0
        static void Main(string[] args)
        {
            //We are given a library of books. Define classes for the library and the books.
            //The library should have name and a list of books.
            //The books have title, author, publisher, year of publishing and ISBN. Keep the books in List<Book>
            //(first find how to use the class System.Collections.Generic.List<T>).

            //Implement methods for adding, searching by title and author, displaying and deleting books.\

            //Write a test class that creates a library, adds few books to it and displays them.
            //Find all books by Nakov, delete them and print again the library.

            Book book1 = new Book("Encarta Encyclopedia", "Tom Jones", "Izdanie Trud", "1989", "sfrsdfr9342343");
            Book book2 = new Book("Raznovidnosti na ruskiq ribolov", "James Brown", "Prosveta", "1983", "sfrsf2342343");
            Book book3 = new Book("Introduction Programming with C#", "Svetlin Nakov", "Prosveta", "2011", "sfrsf2342343");
            Book book4 = new Book("Introduction Programming with Java", "Svetlin Nakov", "Prosveta", "1985", "sfrsf2342343");

            List<Book> books = new List<Book> { book1, book2, book3, book4 };

            Library library = new Library(books);
            library.Name = "My cool new library";
            //view books in newly created library
            library.ViewAllBooks();

            List<Book> NakovBooks = library.GetBooksByAuthor("Svetlin Nakov");

            //see how many Nakov books are there now
            Console.WriteLine();
            Console.WriteLine("There are {0} Nakov's books in the library", NakovBooks.Count);
            Console.WriteLine();
            foreach (Book NakovBook in NakovBooks)
            {
                library.DeleteBook(NakovBook);
            }
            //view library after deleting Nakov's Books
            library.ViewAllBooks();
            //see how many Nakov books are there now
            NakovBooks = library.GetBooksByAuthor("Svetlin Nakov");
            Console.WriteLine("Now there are {0} Nakov's books in the library", NakovBooks.Count);
        }
Example #21
0
 static void CreateNewBook(string invn, string isbn, string title,int authorID, string descr, int categID,
 int yearpubl, int langID, int price)
 {
     LibraryEntities context = new LibraryEntities();
     Author author = context.Author.FirstOrDefault(p => p.ID == authorID);
     Book newBook = new Book()
     {
         InvNum = invn,
         ISBN = isbn,
         Title = title,
         Description = descr,
         CategoryID = categID,
         YearPubl = yearpubl,
         LanguageID = langID,
         Price = price,
         Rejection = false
     };
     newBook.Author.Add(author);
     context.Book.AddObject(newBook);
     context.SaveChanges();
     //return newBook.ID;
 }
Example #22
0
 public int BorrowBooks(User u, Book b)
 {
     try
     {
         conn.Open();
         DateTime date = new DateTime();
         date = System.DateTime.Now;
         DateTime returnDate = new DateTime();
         returnDate = date.AddMonths(2);
         string sql = @"INSERT INTO [Library].[dbo].[Link]
        ([user_id]
        ,[book_id]
        ,[borrowDate]
        ,[returnDate])
      VALUES
        ('" + u.User_id + @"'
        ,'" + b.Book_id + @"'
        ,'" + date + @"'
        ,'" + returnDate + "')";
         sqlcom = new SqlCommand(sql, conn);
         object tp = sqlcom.ExecuteScalar();
         if (tp == null)
         {
             return 0;
         }
         else
         {
             return 1;
         }
     }
     catch
     {
         throw;
     }
     finally
     {
         conn.Close();
     }
 }
Example #23
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if(btnAdd.Content.ToString() == "Uusi")
         {
             Book newBook = new Book(0);
             newBook.Name = "Anna kirjan nimi";
             spBooks.DataContext = newBook;
             btnAdd.Content = "Tallenna uusi kantaan";
         }
         else
         {
             Book current = spBooks.DataContext as Book;
             BookLibrary.InsertBook(current);
             dgBooks.DataContext = BookLibrary.GetBooks(true);
             btnAdd.Content = "Uusi";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #24
0
 public bool CheckBookExists(Book book)
 {
     return bookDAO.checkBookExist(book);
 }
Example #25
0
 public void AddBook(Book book)
 {
     Books.Add(book);
 }
Example #26
0
 public int addBook(Book book)
 {
     return bookDAO.insertBook(book);
 }
Example #27
0
 public int updateBook(Book book)
 {
     return bookDAO.updateBook(book);
 }
Example #28
0
 public int returnBook(User user, Book book)
 {
     try
     {
         int tp = bookDAO.ReturnBooks(user, book);
         user.HadBorrow--;
         userDAO.updateUser(user);
         book.Num++;
         bookDAO.updateBook(book);
         return tp;
     }
     catch
     {
         return 0;
     }
 }
Example #29
0
        public static List<Book> GetAll()
        {
            List<Book> allBooks = new List<Book> {};
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT * FROM books;", conn);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int bookId = rdr.GetInt32(0);
            string bookTitle = rdr.GetString(1);
            Book newBook = new Book (bookTitle, bookId);

            allBooks.Add(newBook);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allBooks;
        }
Example #30
0
 public UCMemberBook(AuthorService aService, BookService bService, BookCopyService bcService, LoanService lService, MemberService mService, Member member, Book book)
 {
     InitializeComponent();
     pMember = member;
     pBook = book;
     pAuthorService = aService;
     pBookService = bService;
     pBookCopyService = bcService;
     pLoanService = lService;
     pMemberService = mService;
     init();
 }
Example #31
0
 public void CreateChildrenBook()
 {
     IBorrowAbleBook CatInTheHat   = new Book("Dr Seuss", 37, 000003, "Cat In The Hat", 3);
     IBorrowAbleBook GoodNightMoon = new Book("Margaret Wise Brown", 52, 000004, "Good Night Moon", 10);
 }
Example #32
0
 public void CreateBook()
 {
     IBorrowAbleBook TheLordOfTheRings1 = new Book("J.R.R. Tolkien", 378, 000001, "Lord Of The Rings: the two towers", 2);
     IBorrowAbleBook HarryPotter1       = new Book("J.K.Rowling", 500, 000002, "Harry Potter og de vises sten", 10);
 }
Example #33
0
 public void Dispose()
 {
     Author.DeleteAll();
     Book.DeleteAll();
 }
Example #34
0
 public void Maplewood(int ISBN)
 {
     ISBN = 0;
     Book.BookInfo(0);
 }
Example #35
0
 public bool checkBookHadBorrow(User user, Book book)
 {
     return bookDAO.CheckBookHadBorrow(user,book);
 }
Example #36
0
 public int deleteBook(Book book)
 {
     return bookDAO.deleteBook(book);
 }
Example #37
0
 public void AddItem(Book book)
 {
     this.items.Add(book);
 }
        /// <summary>
        /// Validates the input fields and then if a book has been selected it Saves the changes made to that book, otherwise it creates a new Book.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveChangesBTN_Click(object sender, EventArgs e)
        {
            if (ValidBookInfo()) // Confirms that all input fields are valid before continuing.
            {
                // Reads all author input fields that are open and saves the author names in a string list
                List <string> authorNames   = new List <string>();
                int           authorTBIndex = BookInfoFLP.Controls.IndexOf(editAuthorTB);
                for (int i = 0; i < authorFields; i++)
                {
                    TextBox currentTB = (TextBox)BookInfoFLP.Controls[authorTBIndex + i];
                    authorNames.Add(currentTB.Text);
                }
                bool createNewAuthor = false;


                List <Author> authorlist = new List <Author>();
                foreach (string an in authorNames)
                {
                    Author auth = authorService.GetAuthorByName(an); // Checks to see if author with same name exists, if so, uses that author instead of creating a duplicate.
                    if (auth == null)                                // If no author with the name was found
                    {
                        createNewAuthor = true;
                        auth            = new Author()
                        {
                            Name = an.Trim(' ') // Trim value to remove potential space before and after name
                        };
                    }
                    authorlist.Add(auth);
                }
                // Create new book
                if (lbBooks.SelectedItem == null)
                {
                    string confirmBoxText = createNewAuthor ? "No author that matches your input was found, by continiuing you will create a new Author entry as well as a new book entry." :
                                            "Continuing will add a new book to the database. Please verify that all book information is correct before confirmation.";
                    string confirmBoxTitle = "Confirm addition of new book";
                    if (ConfirmedPopup(confirmBoxText, confirmBoxTitle))
                    {
                        Book newBook = new Book()
                        {
                            Title       = editTitleTB.Text,
                            ISBN        = editISBNTB.Text,
                            Authors     = authorlist,
                            Description = editDescriptionTB.Text
                        };

                        bookService.Add(newBook);
                        UpdateBookList(bookService.All().ToList());
                    }
                }
                else //Update Book
                {
                    string confirmBoxText = "You are about to edit: '" + currentBookDisplay[lbBooks.SelectedIndex].ToString() + "'.\r\n" +
                                            "Please verify that all book information is correct before confirmation.";
                    string confirmBoxTitle = "Confirm Book Info Update";
                    if (ConfirmedPopup(confirmBoxText, confirmBoxTitle))
                    {
                        Book b = lbBooks.SelectedItem as Book;
                        if (b != null)
                        {
                            b.Title       = editTitleTB.Text;
                            b.ISBN        = editISBNTB.Text;
                            b.Authors     = authorlist;
                            b.Description = editDescriptionTB.Text;
                            bookService.Edit(b);
                        }
                    }
                }
            }
            else // If not all input fields were valid entries.
            {
                string confirmBoxText  = "All fields did not contain valid data. Make sure your Author and Title fields are filled out.";
                string confirmBoxTitle = "Invalid book entry";
                InfoPopup(confirmBoxText, confirmBoxTitle);
            }
        }
Example #39
0
 public void RemoveBook(Book book)
 {
     Books.Remove(book);
 }