admin/bookinfo.aspx.cs

(完整代码) 2KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BookMS.admin
{
    public partial class bookinfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("adminlogin.aspx");
            if (!IsPostBack)
            {   
                int id=Convert.ToInt32(Request["id"]);
                BookDao bookDao = new BookDao();
                Book book = bookDao.GetBookById(id);
                txt_bookid.Text = book.Id.ToString();
                txt_name.Text = book.Name;
                txt_author.Text = book.Author;
                txt_publisher.Text = book.Publisher;
                txt_price.Text = book.Price.ToString();
                txt_main.Text = book.Main;
                if (!book.Cover.Equals("default"))
                    txt_cover.Text = book.Cover;
                Connect connect = new Connect();
                DataSet ds = new DataSet();
                connect.FillDataSet(ds, "select * from booktype", "adminlist");
                ddl_type.DataSource = ds;
                ddl_type.DataValueField = "id";
                ddl_type.DataTextField = "name";
                ddl_type.DataBind();
                foreach (ListItem item in ddl_type.Items)
                    if (item.Value.Equals(book.Typeid.ToString()))
                        item.Selected = true;
            }
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            BookDao bookDao = new BookDao();
            Book book = bookDao.GetBookById(Convert.ToInt32(txt_bookid.Text));
            book.Name = txt_name.Text;
            book.Author = txt_author.Text;
            book.Typeid = Convert.ToInt32(ddl_type.SelectedValue);
            book.Publisher = txt_publisher.Text;
            book.Price = (float)Convert.ToDouble(txt_price.Text);
            book.Main = txt_main.Text;
            if (!txt_cover.Text.Equals(""))
                book.Cover = txt_cover.Text;
            bookDao.UpdateBook(book);
            lab_tip.Text = "修改成功<script>alert('修改成功');</script>";
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。