Пример #1
0
        public void Initializa()
        {
            test  = new BookDao();
            iBook = new Books()
            {
                //BOOK_ID = 0,
                BookName       = "ibook",
                BookAuthor     = "ia",
                BookPublisher  = "ip",
                BookNote       = "insert_test",
                BookBoughtDate = "2018-08-01",
                BookClassId    = "BK"
            };

            argI = new BookSearchArg()
            {
                BookName    = "ibook",
                BookClassId = "BK",
                BookKeeper  = "",
                BookCodeId  = "A"
            };

            argEmpty = new BookSearchArg()
            {
                BookName    = "",
                BookClassId = "",
                BookKeeper  = "",
                BookCodeId  = ""
            };

            bookUpdateData = new BookUpdateData()
            {
                BookName       = "ubook",
                BookAuthor     = "ua",
                BookPublisher  = "up",
                BookNote       = "update_test",
                BookBoughtDate = "2018-08-01",
                BookCodeId     = "A",
                BookKeeper     = "0003"
            };
        }
Пример #2
0
        /// <summary>
        /// 編輯書籍
        /// </summary>
        /// <param name="book"></param>
        /// <returns></returns>
        public bool UpdateBookData(eLibrary.Model.BookUpdateData book)
        {
            string sql = @"
                         BEGIN TRY
		                    BEGIN TRANSACTION

                         UPDATE dbo.BOOK_DATA
                         SET BOOK_NAME = @BookName, BOOK_AUTHOR = @BookAuthor, 
                         BOOK_PUBLISHER = @BookPublisher, BOOK_NOTE = @BookNote, 
                         BOOK_BOUGHT_DATE =CONVERT( varchar(12), @BookBoughtDate, 111) , BOOK_CLASS_ID = @BookClass,
                         BOOK_STATUS = @BookStatus, BOOK_KEEPER = @BookKeeper
                         WHERE BOOK_ID = @BookId
                            COMMIT TRANSACTION
                         END TRY
                         BEGIN CATCH
		                    ROLLBACK TRANSACTION
	                     END CATCH"    ;
            //not sure the usage of BookId
            var result = 0;

            using (SqlConnection conn = new SqlConnection(this.GetDBConnectionString()))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add(new SqlParameter("@BookId", book.BookId));
                cmd.Parameters.Add(new SqlParameter("@BookName", book.BookName));
                cmd.Parameters.Add(new SqlParameter("@BookAuthor", book.BookAuthor));
                cmd.Parameters.Add(new SqlParameter("@BookPublisher", book.BookPublisher));
                cmd.Parameters.Add(new SqlParameter("@BookNote", book.BookNote));
                cmd.Parameters.Add(new SqlParameter("@BookBoughtDate", book.BookBoughtDate));
                cmd.Parameters.Add(new SqlParameter("@BookClass", book.BookClassId));
                cmd.Parameters.Add(new SqlParameter("@BookStatus", book.BookCodeId));
                cmd.Parameters.Add(new SqlParameter("@BookKeeper", book.BookKeeper == null ? string.Empty : book.BookKeeper));
                result = cmd.ExecuteNonQuery();
                conn.Close();
            }
            return(result == 1);
        }
Пример #3
0
 /// <summary>
 /// 編輯書籍
 /// </summary>
 /// <param name="book"></param>
 /// <returns></returns>
 public bool UpdateBookData(eLibrary.Model.BookUpdateData book)
 {
     return(bookDao.UpdateBookData(book));
 }