📄 mainmanage.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using BookShop;
public partial class MainManage : System.Web.UI.Page
{
private int nCategoryID = -1;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["CategoryID"] != null)
{
nCategoryID = Int32.Parse(Request.Params["CategoryID"].ToString());
}
if (!Page.IsPostBack)
{
if (nCategoryID > -1)
{
///按照书籍种类显示所有书籍
BindBookData(nCategoryID);
}
}
///添加删除确认对话框
DeleteBtn.Attributes.Add("onclick","return confirm('" + ASPNET2System.OPERATIONDELETEMESSAGE + "');");
}
private void BindBookData(int nCategoryID)
{
///从数据库获取信息
Book book = new Book();
SqlDataReader recb = book.GetBookByCategory(nCategoryID);
///绑定列表的数据
BookList.DataSource = recb;
BookList.DataTextField = "Name";
BookList.DataValueField = "BookID";
BookList.DataBind();
///关闭数据源
recb.Close();
}
protected void AddBtn_Click(object sender,EventArgs e)
{
Response.Redirect("~/DesktopModules/Book/AddBook.aspx?CategoryID=" + nCategoryID.ToString());
}
protected void UpdateBtn_Click(object sender,EventArgs e)
{
if (BookList.SelectedIndex <= -1)
{
///显示提示信息
Response.Write("<script>window.alert('" + ASPNET2System.LISTBOX_NO_SELECT_ITEM + "')</script>");
return;
}
Response.Redirect("~/DesktopModules/Book/UpdateBook.aspx?BookID=" + BookList.SelectedValue
+ "&CategoryID=" + nCategoryID.ToString());
}
protected void DeleteBtn_Click(object sender,EventArgs e)
{
if (BookList.SelectedIndex <= -1)
{
///显示提示信息
Response.Write("<script>window.alert('" + ASPNET2System.LISTBOX_NO_SELECT_ITEM + "')</script>");
return;
}
try
{
///定义类
Book book = new Book();
///删除操作
book.DeleteBook(Int32.Parse(BookList.SelectedValue));
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
///重新绑定数据
BindBookData(nCategoryID);
}
catch (Exception ex)
{
///显示删除操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
protected void PictureBtn_Click(object sender,EventArgs e)
{
if (BookList.SelectedIndex <= -1)
{
///显示提示信息
Response.Write("<script>window.alert('" + ASPNET2System.LISTBOX_NO_SELECT_ITEM + "')</script>");
return;
}
Response.Redirect("~/DesktopModules/Book/PictureManage.aspx?BookID=" + BookList.SelectedValue
+ "&CategoryID=" + nCategoryID.ToString());
}
protected void CommentBtn_Click(object sender,EventArgs e)
{
if (BookList.SelectedIndex <= -1)
{
///显示提示信息
Response.Write("<script>window.alert('" + ASPNET2System.LISTBOX_NO_SELECT_ITEM + "')</script>");
return;
}
Response.Redirect("~/DesktopModules/Book/CommentManage.aspx?BookID=" + BookList.SelectedValue
+ "&CategoryID=" + nCategoryID.ToString());
}
protected void ViewBtn_Click(object sender,EventArgs e)
{
if (BookList.SelectedIndex <= -1)
{
///显示提示信息
Response.Write("<script>window.alert('" + ASPNET2System.LISTBOX_NO_SELECT_ITEM + "')</script>");
return;
}
Response.Redirect("~/DesktopModules/Book/ViewBook.aspx?BookID=" + BookList.SelectedValue
+ "&CategoryID=" + nCategoryID.ToString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -