📄 bookmanage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BookManage.Model;
using BookManage.BLL;
namespace BookManage.Admin
{
/// <summary>
/// BookModify 的摘要说明。
/// </summary>
public partial class BookManage : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
selectType.AutoBindData();
filterType.AutoBindData();
}
txtSearch.Attributes.Add("onkeydown", "if(event.keyCode==13){document.getElementById('" + btnSearch.ClientID + "').focus();document.getElementById('" + btnSearch.ClientID + "').click();}");
BindData();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void btnSubmit_Click(object sender, EventArgs e)
{
BookTypeInfo btInfo = new BookTypeInfo(int.Parse(selectType.SelectedValue), 0, string.Empty, string.Empty);
BookInfo bookInfo = new BookInfo(txtDesc.Value.Trim(), txtBookName.Text.Trim(), false, txtCode.Value.Trim(), 0, btInfo);
Book book = new Book();
int id;
if (ViewState["modifyID"] == null)
{
id = book.AddBook(bookInfo);
if (id > 0)
lblNotify.Text = "添加成功";
else
lblNotify.Text = "添加失败,添加过程出现错误";
}
else
{
id = Convert.ToInt32(ViewState["modifyID"]);
bookInfo.BookId = id;
if (book.ModifyBookInfo(bookInfo) > 0)
lblNotify.Text = "修改成功";
else
lblNotify.Text = "修改失败,修改过程出现错误";
ViewState.Remove("modifyID");
ltMode.Visible = false;
}
BindData();
}
protected void btnSearch_ServerClick(object sender, EventArgs e)
{
ViewState.Add("search", "search");
ViewState.Remove("type");
BindData();
}
protected void bookList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
BookInfo bookInfo = (BookInfo)e.Row.DataItem;
if (bookInfo.BookStatus == false)
e.Row.Cells[4].Text = "未借出";
else
e.Row.Cells[4].Text = "已借出";
}
}
protected void filterType_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState.Add("type", "type");
ViewState.Remove("search");
BindData();
}
protected void bookList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Book book = new Book();
int bookId = Convert.ToInt32(bookList.DataKeys[e.RowIndex].Value);
if (book.DeleteBookInfo(bookId) > 0)
Page.RegisterStartupScript("deleted", "<script type=\"text/javascript\">alert('删除成功');</script>");
else
Page.RegisterStartupScript("deleted", "<script type=\"text/javascript\">alert('删除失败,删除过程出现错误');</script>");
BindData();
}
protected void bookList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Modify")
{
int bookId = Convert.ToInt32(e.CommandArgument);
ViewState.Add("modifyID", bookId);
Book book = new Book();
BookInfo bookInfo = book.GetBookById(bookId);
txtBookName.Text = bookInfo.BookName;
txtCode.Value = bookInfo.BookCode;
txtDesc.Value = bookInfo.BookDesc;
selectType.SelectedValue = bookInfo.BookTypeInfo.BookTypeId.ToString();
ltMode.Visible = true;
bookList.Visible = false;
}
}
void BindData()
{
if (ViewState["search"] == null && ViewState["type"] == null)
{
bookList.DataSource = Book.GetBookList();
bookList.DataBind();
}
else if (ViewState["search"] != null)
{
bookList.DataSource = Book.GetBookListByName(txtSearch.Value);
bookList.DataBind();
}
else if (ViewState["type"] != null)
{
if (filterType.SelectedIndex == 0)
bookList.DataSource = Book.GetBookList();
else
{
int typeId = int.Parse(filterType.SelectedValue);
bookList.DataSource = Book.GetBookListByType(typeId);
}
bookList.DataBind();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -