public string SaveBook(Book aBook)
 {
     int value = bookGateway.SaveBook(aBook);
     if (value > 0)
     {
         return "This book has been saved.";
     }
     else
     {
         return "Sorry! Book saved failed.";
     }
 }
        public int SaveBook(Book aBook)
        {
            string query = "INSERT INTO Book_tbl Values('"+aBook.Title+"','"+aBook.Author+"','"+aBook.Publisher+"')";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int rowAffect = command.ExecuteNonQuery();
            connection.Close();

            return rowAffect;
        }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            Book aBook = new Book();

            aBook.Title = titleTextBox.Text;
            aBook.Author = authorTextBox.Text;
            aBook.Publisher = publisherTextBox.Text;

            if(bookManager.IfBookExists(aBook)){
                msgLabel.Text = "Sorry, Book Already Exists.";
                return;
            }

            msgLabel.Text = bookManager.SaveBook(aBook);
        }
        public bool IfBookExist(Book aBook)
        {
            string query = "SELECT * FROM Book_tbl WHERE Title='"+aBook.Title+"'";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            if (reader.Read())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public List<Book> GetAllBookInfo()
        {
            List<Book> bookList = new List<Book>();
            string query = "SELECT * FROM Book_tbl";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while(reader.Read()){
                Book aBook = new Book();
                aBook.Id = int.Parse(reader["Id"].ToString());
                aBook.Title = reader["Title"].ToString();
                bookList.Add(aBook);
            }
            reader.Close();
            connection.Close();
            return bookList;
        }
        public Book GetAllBookTitle(int id)
        {
            Book aBook = new Book();
            string query = "SELECT * FROM Book_tbl WHERE Id='"+id+"'";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {

                aBook.Title = reader["Title"].ToString();

            }
            reader.Close();
            connection.Close();
            return aBook;
        }
        public List<Book> GetBookId(int id)
        {
            List<Book> bookIdList = new List<Book>();
            string query = "SELECT * FROM Relation_tbl WHERE MemberId='"+id+"'";
            SqlConnection connection = new SqlConnection(connectionString);

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Book aBook = new Book();
                aBook.Id = int.Parse(reader["BookId"].ToString());
                int bookId = aBook.Id;
                aBook = GetAllBookTitle(bookId);
                bookIdList.Add(aBook);

            }
            reader.Close();
            connection.Close();
            return bookIdList;
        }
 public bool IfBookExists(Book aBook)
 {
     return bookGateway.IfBookExist(aBook);
 }