コード例 #1
0
 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.";
     }
 }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 public bool IfBookExists(Book aBook)
 {
     return bookGateway.IfBookExist(aBook);
 }