enablePasswordRetrieval="false"enablePasswordReset="true"requiresQuestionAndAnswer="false"requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"minRequiredPasswordLength="6"minRequiredNonalphanumericCharacters="0"passwordAttemptWindow="10"
applicationName="/"/>
3.3A后台主要代码
3.3.1注册模块
只有注册成为用户之后才能使用本系统,注册需要输入用户名,密码,再次输入密码等等,然后点击注册按钮,其具体效果图如图2所示:
图2用户注册界面
namespacereport.lib
{
publicpartialclassregist:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringusers=this.TextBox1.Text.Trim();
stringpass=this.TextBox2.Text.Trim();
stringpass1=this.TextBox3.Text.Trim();
stringsname=this.TextBox4.Text.Trim();
stringsex="";
stringage=this.TextBox5.Text.Trim();
stringaddress=this.TextBox6.Text.Trim();
stringtell=this.TextBox7.Text.Trim();
if(RadioButton1.Checked==true)
{
sex=RadioButton1.Text;
}
else
{
sex=RadioButton2.Text;
}
stringsqlStr="selectusersfromstudentwhereusers='"+users+"'";
DBdb=newDB();
boolcount=db.GetReader(sqlStr).HasRows;
if(count)
Response.Write("");
else
if(this.TextBox1.Text!
="")
{
stringsqlStr1="insertintostudent(users,pass,sname,sex,age,address,tell)values('"+users+"','"+pass+"','"+sname+"','"+sex+"','"+age+"','"+address+"','"+tell+"')";
intcount1=db.ExectSql(sqlStr1);
if(count1>0)
{
Response.Write("");
Clear();
}
else
{
Response.Write("");
}
}
}
publicvoidClear()
{
this.TextBox1.Text="";
this.TextBox2.Text="";
this.TextBox3.Text="";
this.TextBox4.Text="";
this.TextBox5.Text="";
this.TextBox6.Text="";
this.TextBox7.Text="";
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
Response.Redirect("登录.aspx");
}
}
}
3.3.2登陆界面
用户注册后便可登录,输入用户名和密码,点击登录按钮便可成功登陆,具体效果如图3所示
图3登陆界面
namespacereport.lib
{
publicpartialclasssecond:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringusers=this.TextBox1.Text.Trim();
stringpass=this.TextBox2.Text.Trim();
stringsqlStr="selectusersfromstudentwhereusers='"+users+"'andpass='"+pass+"'";
DBdb=newDB();
SqlDataReaderdr=db.GetReader(sqlStr);
dr.Read();
if(dr.HasRows)
{
//Session["sno"]=dr.GetValue(0);
Session["Role"]=dr.GetValue(0);
if(dr.GetValue(0)==null)
{
Response.Redirect("about.aspx");
}
else
{
Response.Redirect("main.aspx");
}
}
else
{
Response.Write("");
}
dr.Close();
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
Response.Redirect("注册.aspx");
}
}
}
3.3.3用户管理
用户登陆成功后便可进入用户管理页面,选择是否为管理员。
具体效果如图4所示
图4用户管理界面
namespacereport.lib
{
publicpartialclassuser:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!
IsPostBack)
{
dbind();
}
}
publicvoiddbind()
{
SqlConnectionmyCon=DB.GetConnection();
myCon.Open();
stringsqlStr="select*fromstudent";
SqlDataAdaptermyDa=newSqlDataAdapter(sqlStr,myCon);
DataSetmyDs=newDataSet();
myDa.Fill(myDs);
GridView1.DataSource=myDs;
GridView1.DataBind();
myCon.Close();
}
protectedvoidGridView1_RowEditing1(objectsender,GridViewEditEventArgse)
{
GridView1.EditIndex=e.NewEditIndex;
this.dbind();
}
protectedvoidGridView1_OnRowUpdating1(objectsender,GridViewUpdateEventArgse)
{
intid=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
stringsname=((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString();
stringtell=((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
stringRole=((CheckBox)(this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Checked.ToString();
stringsqlStr="updatestudentsetsname='"+sname+"',tell='"+tell+"',Role='"+Role+"'whereusers="+id;
DBdb=newDB();
db.ExectSql(sqlStr);
GridView1.EditIndex=-1;
dbind();
}
protectedvoidGridView1_OnRowCancelingEdit1(objectsender,GridViewCancelEditEventArgse)
{
GridView1.EditIndex=-1;
this.dbind();
}
protectedvoidGridView1_OnRowDeleting(objectsender,GridViewDeleteEventArgse)
{
DBdb=newDB();
intid=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
stringsqlStr="deletefromstudentwhereusers="+id;
db.ExectSql(sqlStr);
GridView1.EditIndex=-1;
dbind();
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
Response.Redirect("second.aspx");
}
//protectedvoidGridView1_OnRowDataBound(objectsender,GridViewRowEventArgse)
//{
//if(e.Row.RowType==DataControlCellType.DataRow)
//{
//((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick","returnconfirm(“确定删除");
//dbind();
//}
//}
}
}
3.3.4管理员界面
用户通过输入账号密码,为管理员进入此页面,具体效果如图6所示
图5管理员界面
namespacereport.lib
{
publicpartialclassadminu:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!
IsPostBack)
{
dbind();
}
}
publicvoiddbind()
{
SqlConnectionmyCon=DB.GetConnection();
myCon.Open();
stringsqlStr="select*fromstudent";
SqlDataAdaptermyDa=newSqlDataAdapter(sqlStr,myCon);
DataSetmyDs=newDataSet();
myDa.Fill(myDs);
GridView1.DataSource=myDs;
GridView1.DataBind();
myCon.Close();
}
protectedvoidGridView1_RowEditing1(objectsender,GridViewEditEventArgse)
{
GridView1.EditIndex=e.NewEditIndex;
this.dbind();
}
protectedvoidGridView1_OnRowUpdating1(objectsender,GridViewUpdateEventArgse)
{
intid=Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
stringsname=((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString();
stringtell=((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
stringRole=((CheckBox)(this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Checked.ToString();
stringsqlStr="updatestudentsetsname='"+sname+"',tell='"+tell+"',Role='"+Role+"'whereusers="+id;
DBdb=newDB();
db.ExectSql(sqlStr);
GridView1.EditIndex=-1;
dbi