protected void Page_Load(object sender, EventArgs e)
        {
            // 传参异常捕获
            try
            {
                // 获取get的传参
                BookId = Convert.ToInt32(Request.QueryString["id"]);
            }
            catch (Exception)
            {
                Response.Redirect("./Main.aspx");
            }
            // id值不可为负数
            if (BookId <= 0)
            {
                Response.Redirect("./Main.aspx");
            }

            BookDao bookDao = new BookDao();
            // 获取图书详情
            BookInfo bookInfo = bookDao.GetBookDetailById(BookId);

            // 展示到页面
            BookAuthor      = bookInfo.Author;
            BookDescription = bookInfo.Description;
            BookImage       = bookInfo.Image;
            BookPrice       = bookInfo.Price;
            BookTitle       = bookInfo.Name;
            BookType        = bookInfo.TypeName;
        }
Esempio n. 2
0
        private void UpdatePage()
        {
            int id = 0;

            try
            {
                id = Convert.ToInt32(Request.QueryString["bookId"]);
            }
            //捕获异常,如果有错就返回上一页
            catch (Exception)
            {
                Response.Write("<script>window.history.go(-1);</script>");
            }
            //实例化一个数据库操作
            BookDao bookDao = new BookDao();

            //通过ID获取书本的详细信息
            BookInfo book = bookDao.GetBookDetailById(id);

            if (book == null)
            {
                //无数据时,返回上一页
                Response.Write("<script>window.history.go(-1);</script>");
            }
            else
            {
                //将这本书的信息写在界面上
                TextAuthor.Text      = book.Author;
                TextDescription.Text = book.Description;
                TextImage.Text       = book.Image;
                TextName.Text        = book.Name;
                TextPrice.Text       = book.Price + "";

                for (int i = 0; i < DropDownList.Items.Count; i++)
                {
                    if (Convert.ToInt32(DropDownList.Items[i].Value) == book.TypeId)
                    {
                        DropDownList.SelectedIndex = i;
                    }
                }
            }
        }