📄 admineight.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 System.Data.OleDb;
namespace KaoQin
{
/// <summary>
/// adminEight 的摘要说明。
/// </summary>
public class adminEight : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtCode;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox txtPwd;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.DataGrid data;
protected System.Web.UI.WebControls.Label info;
protected System.Data.DataSet ds;
protected System.Data.OleDb.OleDbDataReader reader;
protected System.Data.OleDb.OleDbConnection con;
protected System.Data.OleDb.OleDbCommand com;
protected System.Web.UI.WebControls.Button Button3;
protected System.Data.OleDb.OleDbDataAdapter da;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(System.Convert.ToString(Session["admin"]).Equals(""))
{
Response.Redirect("admin.aspx");
}
else
{
string strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("message.mdb")+";User Id=admin;Password=;";
con=new OleDbConnection(strcon);
if(!IsPostBack)
{
bind();
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.data.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.data.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.data_DeleteCommand);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
data.CurrentPageIndex=e.NewPageIndex;
bind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(txtCode.Text.Trim().Equals(""))
{
info.Text="管理员编号不能为空!";
}
else if(txtPwd.Text.Trim().Equals(""))
{
info.Text="管理员密码不能为空!";
}
else if(txtPwd.Text.Length<6)
{
info.Text="管理员密码不能小于6位!";
}
else if(txtName.Text.Trim().Equals(""))
{
info.Text="管理员姓名不能为空!";
}
else
{
info.Text="";
string sql2,sql3;
int count=0;
sql2="select adminId from admin where adminId='"+txtCode.Text.Trim()+"'";
con.Open();
com=new System.Data.OleDb.OleDbCommand(sql2,con);
reader=com.ExecuteReader();
while(reader.Read())
{
count++;
}
reader.Close();
com.Dispose();
con.Close();
if(count==0)
{
sql3="insert into admin values('"+txtCode.Text.Trim()+"','"+txtPwd.Text.Trim()+"','"+txtName.Text.Trim()+"')";
con.Open();
com=new System.Data.OleDb.OleDbCommand(sql3,con);
com.ExecuteNonQuery();
com.Dispose();
con.Close();
txtCode.Text="";
txtPwd.Text="";
txtName.Text="";
bind();
}
else
{
info.Text="你添加的管理员编号已存在!";
}
con.Close();
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
txtCode.Text="";
txtPwd.Text="";
txtName.Text="";
}
private void data_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id=(string)data.DataKeys[(int)e.Item.ItemIndex];
if(id.Trim().Equals("admin"))
{
info.Text="系统管理员不能删除!";
}
else
{
string sql4="delete from admin where adminId='"+id+"'";
con.Open();
com=new System.Data.OleDb.OleDbCommand(sql4,con);
com.ExecuteNonQuery();
com.Dispose();
con.Close();
bind();
}
}
public void bind()
{
con.Open();
ds=new DataSet();
string sql="select * from admin order by adminId desc";
da=new System.Data.OleDb.OleDbDataAdapter(sql,con);
da.Fill(ds,"admin");
da.Dispose();
con.Close();
data.DataSource=ds.Tables["admin"].DefaultView;
data.DataBind();
}
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("adminFive.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -