您的位置:首页 > 其它

第六章 用户权限管理(五) -- 用户登录管理

2012-09-19 09:13 148 查看
6.6 角色用户管理设计与实现

6.6.3 用户登录管理

用户登录管理首先由管理员为用户设置用户名和密码,如上一页的图6.17所示。

如图6.19所示,电子政务系统的工作界面由几个框架页面组成。用户在调用系统首页面Index.aspx时,如果未登录,系统将跳转到登录页面Login.aspx。用户登录后,左侧框架页面将根据登录用户的角色权限显示不同的工作菜单。






图6.19 政务系统首页

如图6.19所示,在系统主页面的左侧菜单,用户可以随时点击“修改密码”菜单进行密码修改;可以点击顶部框架页面的退出按钮,退出登录;退出登录后的顶部框架页面将显示如图中箭头所指的登录控件,用户可以重新登录。

与用户登录管理相关的程序代码如下:

1、Index.aspx文件代码

<%@ Page language="c#" Codebehind="Index.aspx.cs"

Inherits="workflow.Index" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>无标题文档</title>

</head>

<frameset rows="100,*,50" frameborder="NO" border="0" framespacing="0">

<frame src="Top.aspx" name="topFrame" scrolling="NO" noresize>

<frameset cols="190,*" frameborder="NO" border="0" framespacing="0">

<frame src="Left.aspx" name="leftFrame" scrolling="YES" noresize>

<frame src="chaoqiliuchengliebiao.htm" name="mainFrame">

</frameset>

<frame src="bottom.htm" name="bottomFrame" scrolling="NO" noresize>

</frameset>

<noframes>

<body>

</body>

</noframes>

</html>

Index.aspx.cs文件代码:

....

namespace workflow

{

public class Index : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

if(! IsPostBack)

{

if(Session["userid"] == null)

Response.Redirect("./Login.aspx");

}

}

}

}

2、Left.aspx文件代码

......

<html>

<body>

<form id="Form1" method="post" runat="server">

<table cellSpacing="0" cellPadding="0" width="100%" border="0">

<tr>

<td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px"><br>

<% if(officeresourcetypeds != null)

{

for(int i=0;i<officeresourcetypeds.Tables[0].Rows.Count;i++)

{

%>

<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>

<tr><td><DIV class="parent">

<table width="100%" border="0" cellspacing="0" cellpadding="3">

<tr>

<td class="boxtitle"><a href="#" onclick="">

<%=officeresourcetypeds.Tables[0].Rows[i]["CategoryName"].ToString()%></a>

</td>

</tr>

</table></DIV>

<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"

cellpadding="0">

<tr>

<td class="boxcontent"><DIV class="child">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<% linkresourceds=basemanager.GetOfficeLinkResource(rolesds,

officeresourcetypeds.Tables[0].Rows[i]["CateGoryID"].ToString());

if(linkresourceds != null)

{

for(int j=0;j<linkresourceds.Tables[0].Rows.Count;j++)

{

%>

<TR>

<TD align="center" width="20%" height="25"><IMG height="4"

src="images/dot.gif" width="4"></TD>

<TD width="80%">

<A href="<%=linkresourceds.Tables[0].Rows[j]["Link"]

.ToString()%>" target="mainFrame">

<%=linkresourceds.Tables[0].Rows[j]["ResourceName"].ToString()%>

</A>

</TD>

</TR>

<% }

}

%>

</table></DIV>

</td></tr>

</table>

</td></tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr><td height="7"></td>

</tr>

</table>

<% }

}

%>

</td></tr>

</table>

<table cellSpacing="0" cellPadding="0" width="100%" border="0">

<tr><td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px">

<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>

<tr><td><DIV class="parent" id="KB1Parent">

<table width="100%" border="0" cellspacing="0" cellpadding="3">

<tr><td class="boxtitle">

<a href="#" onclick="">个人信息维护</a>

</td></tr>

</table></DIV>

<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"

cellpadding="0">

<tr><td class="boxcontent"><DIV class="child" id="KB1Child">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<TR><TD align="center" width="20%" height="25">

<IMG height="4" src="images/dot.gif" width="4">

</TD>

<TD width="80%">

<A href="UpdatePassword.aspx" target="mainFrame">修改密码</A>

</TD>

</TR>

</table></DIV>

</td></tr></table>

</td></tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr><td height="7"></td></tr>

</table>

</td></tr>

</table>

</form>

</body>

</HTML>

Left.aspx.cs文件代码

namespace workflow

{

public class Left : System.Web.UI.Page

{

protected DataSet rolesds=null;

protected DataSet officeresourcetypeds=null;

protected DataSet linkresourceds=null;

protected UserManagement basemanager;

private void Page_Load(object sender, System.EventArgs e)

{

if(! IsPostBack)

{

if(Session["userid"] == null)

Response.Redirect("./Message.aspx");

basemanager=new UserManagement();

rolesds=basemanager.GetRoles(Session["userid"].ToString());

if(rolesds != null)

officeresourcetypeds=basemanager.GetOfficeResourceType(rolesds);

}

}





3、Top.aspx文件代码

....

<form id="Form1" method="post" runat="server">

<script language="javascript">

function DateDemo(){

var d, s ;

d = new Date();

s = d.getYear()+"-";

s += (d.getMonth() + 1) + "-";

s += d.getDate() ;

return(s);

}

</script>

<table cellSpacing="0" cellPadding="0" width="100%" border="0">

......

<tr>

<td class="headerbottom" id="Header1_CellLogin" colSpan="2">

<table cellSpacing="0" cellPadding="0" width="100%" border="0">

<tr>......

<td align="right" width="52%">

<%

if(Session["userid"]!=null)

{

%>

<font color="white">

<asp:label id="Label1" runat="server" ForeColor="White"></asp:label>

<span id="Header1_Label1"> 

今天是<script>document.write(DateDemo());</script>

<asp:linkbutton id="LinkButton1" runat="server">[退出]</asp:linkbutton>

</span></font>

<%

}

else

{

%>

<font color="white">用户名:</font>

<asp:TextBox id="TextBox1" runat="server" Columns="16"></asp:TextBox>

<font color="white">密码: </font>

<asp:TextBox id="TextBox2" runat="server" Columns="16"

TextMode="Password"></asp:TextBox>

<asp:LinkButton id="LinkButton2" runat="server">[登录]</asp:LinkButton>

<asp:Label id="Label2" runat="server" ForeColor="Red"></asp:Label>

<%

}

%>

</td></tr>

</table>

</td></tr>

</table>

......

</form>

Top.aspx.cs文件代码

namespace workflow

{

public class Top : System.Web.UI.Page

{

protected System.Web.UI.WebControls.LinkButton LinkButton1;

protected System.Web.UI.WebControls.TextBox TextBox1;

protected System.Web.UI.WebControls.TextBox TextBox2;

protected System.Web.UI.WebControls.LinkButton LinkButton2;

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)

{

if(! IsPostBack)

{

if(Session["userid"]==null)

Label1.Text="您还没有登录";

else

{

string strSql="select EmployeeName from Employees where EmployeeID=(select

EmployeeID from Users where UserID="+Session["userid"].ToString ()+")";

DataSet ds=new DataAccess.Base().SQLExeDataSet(strSql);

Label1.Text="您好,"+ds.Tables[0].Rows[0]["EmployeeName"].ToString ();

}

}

Label2.Text="";

}

//退出按钮

private void LinkButton1_Click(object sender, System.EventArgs e)

{

Session["userid"]=null;

Response.Write(" <script>window.parent.frames['mainFrame'].location.href

='Message.aspx';</script> ");

}

//登录按钮

private void LinkButton2_Click(object sender, System.EventArgs e)

{

string username=TextBox1.Text.Trim();

string password=TextBox2.Text.Trim();

UserManagement management=new UserManagement();

string userid=management.UserAuthentication(username,password);

if(userid == null)

{

Label2.Text="用户名或密码错误!";

return;

}

Session["userid"]=userid;

Response.Write(" <script>window.parent.location.href='Index.aspx';</script> ");

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐