📄 addbooktype.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;
namespace WebShop
{
/// <summary>
/// AddBookType 的摘要说明。
/// </summary>
public class AddBookType : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid dg_booktype;
protected System.Web.UI.WebControls.ImageButton ib_savecontinue;
protected System.Web.UI.WebControls.ImageButton ib_saveexit;
protected System.Web.UI.WebControls.ImageButton ib_exit;
protected System.Web.UI.WebControls.TextBox tb_booktype;
protected System.Web.UI.WebControls.TextBox tb_memo;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
protected System.Web.UI.WebControls.Literal ErrMsg;
DataAccessLayer.BookType myBookType=new DataAccessLayer.BookType ();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
ViewState["BookTypeSort"]="";
GridBind();
}
ErrMsg.Visible =false;
}
/// <summary>
/// 绑定到datagrid中
/// </summary>
private void GridBind()
{
DataView myDv;
myDv=myBookType.GetBookType();
if(!object.Equals(ViewState["BookTypeSort"],null))
myDv.Sort =ViewState["BookTypeSort"].ToString() ;
dg_booktype.DataSource =myDv;
dg_booktype.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ib_savecontinue.Click += new System.Web.UI.ImageClickEventHandler(this.ib_savecontinue_Click);
this.ib_saveexit.Click += new System.Web.UI.ImageClickEventHandler(this.ib_saveexit_Click);
this.ib_exit.Click += new System.Web.UI.ImageClickEventHandler(this.ib_exit_Click);
this.dg_booktype.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_booktype_ItemCreated);
this.dg_booktype.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_booktype_ItemCommand);
this.dg_booktype.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_booktype_SortCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ib_exit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("BookManage.aspx");
}
private void ib_saveexit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
myBookType.Add(tb_booktype.Text.Trim(),tb_memo.Text.Trim());
Response.Redirect("BookManage.aspx");
}
catch(Exception er)
{
ShowErrMsg(er.Message);
}
}
private void ib_savecontinue_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
myBookType.Add(tb_booktype.Text.Trim(),tb_memo.Text.Trim());
GridBind();
tb_booktype.Text="";
tb_memo.Text ="";
}
catch(Exception er)
{
ShowErrMsg(er.Message);
}
}
private void dg_booktype_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.Image TempImg;
TempImg=(System.Web.UI.WebControls.Image)e.Item.FindControl("ib_delete") ;
if(object.Equals(TempImg,null)==false)
{
TempImg.Attributes.Add("onClick","javascript:return confirm('你能确定要删除此书籍类型吗?')");
}
}
/// <summary>
/// 弹出对话框,显示错误消息
/// </summary>
/// <param name="err">错误消息内容</param>
private void ShowErrMsg(string err)
{
string str;
str="<script language='javascript'>";
str+=" alert('" +err + "')";
str+="</script>";
ErrMsg.Visible=true;
ErrMsg.Text=str;
}
private void dg_booktype_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int id;
System.Web.UI.Control temp;
temp=(System.Web.UI.Control)e.CommandSource;
if (temp.ID=="ib_delete")
{
try
{
id=int.Parse(e.Item.Cells[0].Text);
myBookType.delete(id);
GridBind();
}
catch(Exception er)
{
ShowErrMsg(er.Message);
}
}
}
private void dg_booktype_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(e.SortExpression==ViewState["BookTypeSort"].ToString() )
{
ViewState["BookTypeSort"]=ViewState["BookTypeSort"]+" desc";
}
else
{
ViewState["BookTypeSort"]=e.SortExpression;
}
GridBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -