protected void btnremove_Click(object sender, EventArgs e) { #region 移动图书 foreach (GridViewRow grv in grvbooklist.Rows) { CheckBox chb = (CheckBox)grv.FindControl("cbok"); if (chb.Checked == true) { int bookid = Convert.ToInt32(grvbooklist.DataKeys[grv.RowIndex].Value); int categoryid = Convert.ToInt32(ddlnewcategory.SelectedValue); Books book = Bookmanager.GetBookDetailById(bookid); book.Categories = CategoriesManager.GetCategoriesById(categoryid); Bookmanager.EditBook(book); } } BindData(); #endregion }
public void BindData() { #region 根据图书Id绑定GridView Books book = Bookmanager.GetBookDetailById(Convert.ToInt32(ViewState["BookId"])); book.Clicks++; Bookmanager.EditBook(book); this.lblAuthor.Text = book.Author; this.lblBookName.Text = book.Title; this.lblPublisher.Text = book.Publishers.Name; this.lbltypeName.Text = book.Categories.Name; this.lblISBN.Text = book.ISBN; this.lblPublishDate.Text = book.PublishDate.ToShortDateString(); this.lblFonts.Text = book.WordsCount.ToString(); this.lblPrice.Text = book.UnitPrice.ToString("0.00"); this.lblContent.Text = book.ContentDescription; this.lblAuthorIntroduce.Text = book.AuthorDescription; this.lblRecomment.Text = book.EditorComment; this.lblCatagory.Text = book.TOC; this.lbclicks.Text = book.Clicks.ToString(); this.imgBook.ImageUrl = "~/Images/BookCovers/" + book.ISBN + ".jpg"; #endregion }
protected void btnok_Click(object sender, EventArgs e) { if (ViewState["BookId"] != null) { #region 更新图书 if (FileUploadimg.HasFile) { string[] arrexit = { ".jpg" }; DateTime dt = DateTime.Now; string Bfilename = dt.Year.ToString("0000") + dt.Month.ToString("00") + dt.Second.ToString("00") + dt.Millisecond.ToString("00"); bool isok = FunctionHelp.JudgeFileUploadimg(FileUploadimg, "~/Images/BookCovers/", Bfilename, arrexit); if (isok) { Books book = Bookmanager.GetBookDetailById(Convert.ToInt32(ViewState["BookId"])); book = GetBook(book); book.ISBN = Bfilename; Bookmanager.EditBook(book); Response.Redirect("~/Admin/ListAllBooks.aspx"); } else { labimessage.Text = "上传图片格式不正确"; } } else { Books book = Bookmanager.GetBookDetailById(Convert.ToInt32(ViewState["BookId"])); book = GetBook(book); Bookmanager.EditBook(book); Response.Redirect("~/Admin/ListAllBooks.aspx"); } #endregion } else { #region 添加图书 if (Bookmanager.SearchISBN(txtISBN.Text)) { labisbnmessage.Text = "该ISBN已存在"; } else { if (FileUploadimg.HasFile) { string[] arrexit = { ".jpg" }; bool isok = FunctionHelp.JudgeFileUploadimg(FileUploadimg, "~/Images/BookCovers/", txtISBN.Text, arrexit); if (isok) { Books book = new Books(); book = GetBook(book); Bookmanager.AddBook(book); labimessage.Text = "添加成功"; } else { labimessage.Text = "上传图片格式不正确"; } } } #endregion } }