コード例 #1
0
        protected void GridView_BorrowedBooks_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            conn = new OleDbConnection(connectionString);
            string bookID = null;

            try
            {
                if (e.CommandName == "ReturnBook")
                {
                    string bookTitle = e.CommandArgument.ToString();
                    conn.Open();
                    cmd = new OleDbCommand("Select ID FROM Book where BookName='" + bookTitle + "'", conn);
                    int x = (int)cmd.ExecuteScalar();
                    if (x != 0)
                    {
                        bookID = cmd.ExecuteScalar().ToString();
                    }
                    OleDbCommand insertIntoBorrowedBooks = new OleDbCommand("insert into BorrowedBook([BorrowedBookID],[BorrowedUserID],[State],[BorrowDate]) values (?,?,?,?)", conn);
                    insertIntoBorrowedBooks.Parameters.Add(new OleDbParameter("BorrowedBookID", int.Parse(bookID)));
                    insertIntoBorrowedBooks.Parameters.Add(new OleDbParameter("BorrowedUserID", int.Parse(Session["userID"].ToString())));
                    insertIntoBorrowedBooks.Parameters.Add(new OleDbParameter("State", OleDbType.Boolean)).Value   = true;
                    insertIntoBorrowedBooks.Parameters.Add(new OleDbParameter("BorrowDate", OleDbType.Date)).Value = System.DateTime.Now;
                    insertIntoBorrowedBooks.ExecuteNonQuery();
                    conn.Close();
                    GridView_BorrowedBooks.DataBind();
                }
            }
            catch  { }
        }
コード例 #2
0
        protected void setBooksReturned()
        {
            foreach (GridViewRow row in GridView_BorrowedBooks.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    string bookTitle = row.Cells[1].Text;
                    if (bookTitle != null && bookIsReturned(bookTitle))
                    {
                        //   lbl_error.Text = bookTitle;
                        LinkButton theButton = (LinkButton)row.FindControl("btn_returnBook");

                        if (theButton != null)
                        {
                            theButton.Enabled = false;
                            theButton.Text    = "Returned";
                        }
                    }
                }
            }
            GridView_BorrowedBooks.DataBind();
        }