/// <summary>
        /// 添加类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnAddBook_Click(object sender, EventArgs e)
        {
            string typeName = TextTypeName.Text.Trim();

            if (string.Empty != typeName)
            {
                BookTypeDao bookTypeDao = new BookTypeDao();
                if (bookTypeDao.AddNewType(typeName))
                {
                    Response.AddHeader("Refresh", "0");
                }
            }
        }
        /// <summary>
        /// 更新列表
        /// </summary>
        private void UpdateList()
        {
            BookTypeDao     bookTypeDao = new BookTypeDao();
            List <BookType> list        = bookTypeDao.GetAllBookTypes();

            if (list != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (BookType type in list)
                {
                    sb.AppendFormat(
                        "<tr class='odd gradeX'><td>{0}</td><td>{1}</td><td><div bookId = '{0}' class='btn-group-sm text-center'><button type = 'button' class='btn btn-danger btn_delete' data-toggle='modal' data-target='#confirm-delete'>删除</button></div></td>",
                        type.Id, type.TypeName);
                }
                TypeList = sb.ToString();
            }
        }
        /// <summary>
        /// 类别删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnDeleteBook_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(BookId.Text);

            if (id == 1)
            {
                Response.Write("<script>alert('其他分类为默认分类,无法删除!');</script>");
                return;
            }
            BookTypeDao bookTypeDao = new BookTypeDao();

            // 删除成功
            if (bookTypeDao.DeleteTypeById(id))
            {
                BookDao bookDao = new BookDao();

                // 移动分类
                if (bookDao.RemoveBookToDefaultType(id))
                {
                    Response.AddHeader("Refresh", "0");
                }
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int typeId;

            try
            {
                typeId = Convert.ToInt32(Request.QueryString["typeId"]);
            }
            catch (Exception)
            {
                typeId = -1;
            }

            if (typeId <= 0)
            {
                typeId = -1;
            }

            BookDao bookDao = new BookDao();
            // 图书集合
            List <BookInfo> list;

            // 热搜图书
            list = bookDao.GetHotSearchTop10(typeId);
            if (list != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (BookInfo book in list)
                {
                    stringBuilder.AppendFormat("<div class='book'><a href = './BookDetial.aspx?id={0}' ><img src = '{1}' /><h4 class='title' alt='{2}'>{2}</h4><small class='text-info' alt='{3}'>{3} </small><p class='text-danger'>¥{4}</p></a></div>", book.Id, book.Image, book.Name, book.Author, book.Price);
                }
                HotSearch = stringBuilder.ToString();
            }
            else
            {
                HotSearch = "<h3 class='text-warning'>热搜图书暂无数据...</h3>";
            }

            // 新上架图书
            list = bookDao.GetNewComingTop10(typeId);
            if (list != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (BookInfo book in list)
                {
                    stringBuilder.AppendFormat("<div class='book'><a href = './BookDetial.aspx?id={0}' ><img src = '{1}' /><h4 class='title' alt='{2}'>{2}</h4><small class='text-info' alt='{3}'>{3} </small><p class='text-danger'>¥{4}</p></a></div>", book.Id, book.Image, book.Name, book.Author, book.Price);
                }
                NewComing = stringBuilder.ToString();
            }
            else
            {
                NewComing = "<h3 class='text-warning'>新上架图书暂无数据...</h3>";
            }

            // 推荐图书
            list = bookDao.GetRecommendBooksTop10(typeId);
            if (list != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (BookInfo book in list)
                {
                    stringBuilder.AppendFormat("<div class='book'><a href = './BookDetial.aspx?id={0}' ><img src = '{1}' /><h4 class='title' alt='{2}'>{2}</h4><small class='text-info' alt='{3}'>{3} </small><p class='text-danger'>¥{4}</p></a></div>", book.Id, book.Image, book.Name, book.Author, book.Price);
                }
                RecommendBooks = stringBuilder.ToString();
            }
            else
            {
                RecommendBooks = "<h3 class='text-warning'>推荐图书暂无数据...</h3>";
            }

            // 左侧类别栏
            BookTypeDao     bookTypeDao = new BookTypeDao();
            List <BookType> types       = bookTypeDao.GetAllBookTypes();

            if (types != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (BookType type in types)
                {
                    sb.AppendFormat(
                        "<a href='Main.aspx?typeId={0}' class='list-group-item'><i class='fa fa-comment fa-fw'></i>{1}</a>",
                        type.Id, type.TypeName);
                }
                BookType = sb.ToString();
            }
        }