遗失的星空

导航

【Wonder原创】系统菜单设计【C#、ASP.NET、Oracle】三、ASP.NET页面

三、ASP.NET页面

1、登陆页面 login.aspx

 

login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<style type="text/css">
<!--
body,td,th
{
font-size
: 12px;
}
body
{
margin-left
: 0px;
margin-top
: 0px;
margin-right
: 0px;
margin-bottom
: 0px;
}
#lockWindow
{
position
:absolute;
text-align
:center;
left
:0px;
top
:0px;
width
:0;
height
:0;
z-index
:70;
background-color
: #CCCCCC;
filter
:alpha(opacity=60);
display
:none;
}
#MsgWindow
{
position
:absolute;
text-align
:center;
left
:0px;
top
:0px;
width
:0;
height
:0;
z-index
:100;
display
:none;
}
-->
</style>
<script language="javascript" type="text/javascript">

//------------------------------------------------------------------
//下面两个方法为锁定窗口和解除锁定窗口的方法
//在使用这个两个方法的时候请注意在使用的页面中加入如下HTML标记:
//<div align="center">
//<div id="lockWindow">
//</div>
//<div id="MsgWindow">
//<input type="button" name="Submit" value="解除锁定" onclick="unlockWindow()">
//</div>
//</div>
// 2007.11.22 ByPeter Start
//------------------------------------------------------------------
function lockWindow()
{
/*
锁定窗口的方法
*/
var lockDiv = document.getElementById("lockWindow");
var MsgWindow = document.getElementById("MsgWindow");
lockDiv.style.width
=document.body.scrollWidth;
lockDiv.style.height
=document.body.scrollHeight;
lockDiv.style.display
="block";
MsgWindow.style.top
=document.body.scrollHeight/4;
MsgWindow.style.left=document.body.scrollWidth/3;
MsgWindow.style.display="block";
document.getElementById(
"Info").innerText="登录仓储系统中...";
}
function unlockWindow()
{
/*
解除锁定窗口的方法
*/
var lockDiv = document.getElementById("lockWindow");
var MsgWindow = document.getElementById("MsgWindow");
lockDiv.style.width
=0;
lockDiv.style.height
=0;
lockDiv.style.display
="none";
MsgWindow.style.display
="none";
}
// 2007.11.22 By Peter End
//----------------------------------------------------------------------
//----------------------------------------------------------------------
function RecieveData(res)
{
/*
登录验证结果
*/
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async
="false";
xmlDoc.loadXML(res);
nodes
=xmlDoc.documentElement.childNodes;
var url=nodes.item(0).text;
var result=nodes.item(1).text;
var description=nodes.item(2).text;

if(result==0)//登录成功
window.top.location=url;
else
{
document.getElementById(
"Submit").disabled=false;
document.getElementById(
"Info").innerText=description;
}
}
function Login()
{
/*
进行登陆验证
*/
var strUserName=document.getElementById("TxtUserName").value;
var strPassword=document.getElementById("TxtUserPassword").value;
var strIsSavaPass=document.getElementById("CkbSavePassword").checked;
var drpDB = document.getElementById("drpDB");

if(strUserName=="")
{
document.getElementById(
"TxtUserName").focus();
document.getElementById(
"ValidateUserName").innerText = "提示:用户名不能为空";
return false;
}
else
{
document.getElementById(
"TxtUserPassword").focus();
document.getElementById(
"ValidateUserName").innerText="";
}

if(strPassword=="")
{
document.getElementById(
"ValidateUserPassword").innerText = "提示:密码不能为空";
return false;
}
else
{
document.getElementById(
"ValidateUserPassword").innerText="";
}

var txtInput="<?xml version='1.0' encoding='utf-8'?>"+
"<root>"+
"<UserName>"+strUserName+"</UserName>"+
"<Password>"+strPassword+"</Password>"+
"<IsSavaPass>"+strIsSavaPass+"</IsSavaPass>"+
"<dbName>"+drpDB.value+"</dbName>"+
"</root>";
lockWindow();
CallServer(txtInput,
"");
}

function Reset()
{
obj.select();
obj.focus();
}
</script>
</head>
<body style="margin:0px 0px 0px 0px" background="image/BG-MAIN.gif">
<div align="center" style="width:100%">
<div id="lockWindow">
</div>
<div id="MsgWindow" align="center">
<table width="400" border="0" cellspacing="1" bgcolor="#3399FF">
<tr>
<td width="400" height="25" bgcolor="#3399FF">登录信息提示</td>
</tr>
<tr>
<td height="50" bgcolor="#FFFFFF">
<div id="Info" class="word_red" align="center">登 录 仓 储 系 统 中...</div>
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input type="button" name="Submit" value="确定" disabled="disabled" onclick="unlockWindow()"
style
="border:0px;width: 50px" />
</td>
</tr>
</table>
</div>
</div>
<form id="Form1" method="post" runat="server" defaultfocus="TxtUserName">
<table id="tableContent" width="100%" border="0" align="center">
<tr style="height:20">
<td colspan="2" width="100%" style=" background-image:url(image/BG-TOP.gif); background-repeat: repeat-x; height: 80pt;">

</td>
</tr>
<tr>
<td class="area_slogen" colspan="2" align="center" height="20"> 仓储系统登陆页面
</td>
</tr>
<tr>
<td class="area_slogeContent" colspan="2" height="80">
<br />

<p align="center">&nbsp;&nbsp; 名:<input id="TxtUserName" type="text" name="textfield" style="width:150px" />
<br />
<span id="ValidateUserName" class="word_red"></span>
</p>

<p align="center">&nbsp; &nbsp;&nbsp; 码:<input id="TxtUserPassword" type="password" name="textfield2" style="width:150px" />
<br />
<span id="ValidateUserPassword" class="word_red"></span>
</p>
<p align="center">
&nbsp; &nbsp;&nbsp; 境:<select id="drpDB" name="drpDB" style="width:150px" runat="server">

</select></p>
<p align="center">
<input id="CkbSavePassword" type="checkbox" value="checkbox" name="checkbox" /> &nbsp;记住密码
</p>
<p align="center" class="form_content">
<input class="ButtonStyle" id="BtnSubMit" type="submit" value="登入" onclick="Login();return false;" />

<input onclick="Reset()" type="button" value="重置" id="Button1" class="ButtonStyle" />
</p>
<p class="form_content" align="center"></p>
<p class="form_content" align="center"></p>
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
var obj = document.getElementById("TxtUserName");
obj.focus();
</script>
</form>
</body>
</html>

login.aspx.cs

 

login.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 Daxon.Mes.Common;
using System.Data.SqlClient;

public partial class login : System.Web.UI.Page, ICallbackEventHandler
{
protected string strResult = string.Empty;

protected void Page_Load(object sender, System.EventArgs e)
{
//如果用户已经通过了验证,则让其转向NoAccess.aspx页面
if (!IsPostBack)
{
string cbReference = ClientScript.GetCallbackEventReference(this, "arg", "RecieveData", "context");
string callbackscript = " function CallServer(arg,context)" + "{" + cbReference + "};";
Page.ClientScript.RegisterClientScriptBlock(
this.GetType(), "CallServer", callbackscript, true);

DataSet ds
= new DataSet();
string str = Server.MapPath("DBList.xml");
ds.ReadXml(str);
if( ds!=null)
BaseCommon.BindToSelect(drpDB, ds.Tables[
0], "name", "name");

if (User.Identity.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
}
}


public void RaiseCallbackEvent(string txtInput)
{
if (txtInput != null)
{
strResult
= txtInput;
System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument();
xmlDoc.LoadXml(txtInput);

string strUserName = xmlDoc.DocumentElement.SelectSingleNode("/root/UserName").InnerText;
string strPassword = xmlDoc.DocumentElement.SelectSingleNode("/root/Password").InnerText;
bool boolIsSavePass = bool.Parse(xmlDoc.DocumentElement.SelectSingleNode("/root/IsSavaPass").InnerText);
string strDBName = xmlDoc.DocumentElement.SelectSingleNode("/root/dbName").InnerText;
strResult
= UserLogin(strUserName, strPassword, boolIsSavePass, strDBName);
}
}
public string GetCallbackResult()
{
return strResult;
}


protected string UserLogin(string strUserName, string strUserPwd, bool boolIsSavePass,string dbName)
{
string result = UserMenuData.UserLogin(dbName,strUserName,strUserPwd);
System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument();
xmlDoc.LoadXml(result);
string strResult = xmlDoc.DocumentElement.SelectSingleNode("/root/result").InnerText;
string strDescription = xmlDoc.DocumentElement.SelectSingleNode("/root/Description").InnerText;
strUserName
= xmlDoc.DocumentElement.SelectSingleNode("/root/username").InnerText;
string strUrl = string.Empty;

if (strResult.Equals("0"))//result=0时 description 为 Dept
{
FormsAuthenticationTicket ticket
= new FormsAuthenticationTicket( //建立身份验证票对象
1,
strUserName,
DateTime.Now,
DateTime.Now.AddDays(
1.0),
boolIsSavePass,
dbName,
"/");
string hashTicket = FormsAuthentication.Encrypt(ticket); //加密序列化验证票为字符串
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket); //根据身份验证票对象生成cookies对象
//设置有效期
if (boolIsSavePass == true)//如果为True,把cookies的有效期设为1年
{
cookie.Expires
= DateTime.Now.AddDays(365);
}
Response.Cookies.Add(cookie);
//把cookies对象写到客户端
ticket = null;
cookie
= null;
if (Session["IsUserRateCounted"] != null && Session["IsUserRateCounted"].ToString().Equals("N"))
{
try
{

}
catch
{ }
}
//获取用户开始请求的网页
strUrl = FormsAuthentication.GetRedirectUrl(FormsAuthentication.FormsCookieName, false);
}

string strReturn = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<Url>" + strUrl + "</Url>" + //如果验证正确返回转向的Url,否则为空
"<result>" + strResult + "</result>" + //0:失败 1:成功
"<Description>" + strDescription + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return strReturn;
}

}

2、菜单页面 left.aspx

 

left.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="left.aspx.cs" Inherits="left" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Left</title>
<script language="javascript" type="text/javascript">
var lastnode = "";
function SetNode()
{
var node = event.srcElement;
node.style.color
="#ff0f00";
if(lastnode!="" && lastnode!=node)
{
lastnode.style.color
="";
}
lastnode
=node;
}
</script>
</head>
<body style="background-image: url(image/BG-LEFT1.gif); margin:0;">
<form id="Form1" method="post" runat="server">
<div class="leftBar">
<asp:Label ID="lblWelcome" runat="server" Font-Size="9pt"></asp:Label>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">[登出]</asp:LinkButton><br />
<asp:TreeView ID="treeMenu" runat="server" OnTreeNodeCheckChanged="treeMenu_TreeNodeCheckChanged" MaxDataBindDepth="10" ImageSet="Arrows" NodeIndent="10" ExpandDepth="1">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding
="0px" />
<NodeStyle Font-Names="Verdana" ForeColor="Black" HorizontalPadding="5px"
NodeSpacing
="0px" VerticalPadding="0px" />
</asp:TreeView>

</div>
</form>
</body>
</html>

left.aspx.cs

 

left.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 Daxon.Mes.Common;
using System.Text;
using System.Data.OracleClient;

public partial class left : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
if (!IsPostBack)
{
FormsIdentity fi
= (FormsIdentity)System.Web.HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket
= fi.Ticket;
string userData = ticket.UserData;

string username = User.Identity.Name;
this.lblWelcome.Text = userData+" 欢迎您: " + username;
TreeViewOp tvop
= new TreeViewOp();
tvop.BindToSystemMenu(treeMenu,UserMenuData.GetUserMenu(username,
"0"),"cmid","cmname","cmpvp","cmurl","cmtarget");
}
treeMenu.Attributes.Add(
"onclick", "SetNode()");
}

}
/// <summary>
/// 打开URL,并定位到main框架
/// </summary>
/// <param name="url"></param>
/// <param name="target"></param>
private void OpenToMain(string url, string target)
{
StringBuilder ghq
= new StringBuilder();
ghq.Append(
"<script language=javascript>\n");
ghq.Append(
"window.open(" + "'" + url + "'" + ",'" + target + "');" + "\n");
ghq.Append(
"</script>");
ClientScript.RegisterStartupScript(
this.GetType(), "", ghq.ToString());
}


protected void treeMenu_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
OpenToMain(e.Node.NavigateUrl, e.Node.Target);
}

/// <summary>
/// 登出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton1_Click(object sender, EventArgs e)
{
/********************************************************************
函数名称: LinkButton1_Click
功能描述: 响应重新登录按钮的click事件,实现用户可以重新登陆功能
原作者: Wonder Wang
原作日期: 2007/12/5
修改者:
修改日期:
备注:
********************************************************************
*/
Session[
"IsUserRateCounted"] = "N";
System.Web.Security.FormsAuthentication.SignOut();

//让window.parent.left.location转向index_left.aspx页面
//在index_left.aspx页面的page_load有判断用户是否通过验证
//因为此时已经把用户身份注销,所以最终在window.parent.main会显示login.aspx页面
//并隐藏window.parent.bodyFrame中的其他框架页面,参见:index_left.aspx

ClientScript.RegisterClientScriptBlock(
this.GetType(), "RedirectLoginPage", "<script language='javascript'>window.parent.top.location='login.aspx';</script>");
}
}

 

 

3、权限设置页面 UserRight.aspx

 

UserRight.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserRight.aspx.cs" Inherits="Sys_UserRight" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>权限设置</title>

<script src="../javascript/TreeView2.js" language="javascript" type="text/javascript"></script>

</head>
<body>
<form id="form1" runat="server">
<table class="table1">
<tr>
<td class="fmtitle">
页面功能:权限设置
</td>
</tr>
</table>
<div >
<table class="table_600">
<tr>
<td>
<asp:DropDownList ID="drpQueryCondition" runat="server">
<asp:ListItem Value="userid" Selected="True">工号</asp:ListItem>
<asp:ListItem Value="username" >英文名</asp:ListItem>
<asp:ListItem Value="dept">部门</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtQueryText" runat="server"></asp:TextBox>
<asp:Button ID="btnInquire" runat="server" Text="查询用户" OnClick="btnInquire_Click" />
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GvUserInfo" runat="server" PageSize="5" AutoGenerateColumns="False"
OnRowEditing
="GvUserInfo_RowEditing" OnRowUpdating="GvUserInfo_RowUpdating" AllowPaging="True"
OnPageIndexChanging
="GvUserInfo_PageIndexChanging" OnRowCancelingEdit="GvUserInfo_RowCancelingEdit"
OnRowDataBound
="GvUserInfo_RowDataBound" EmptyDataText="<table cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; rules=&quot;rows&quot; border=&quot;0&quot; id=&quot;ctl00_ContentPlaceHolder1_GvUserInfo&quot; style=&quot;border-width:0px;border-style:None;width:100%;border-collapse:collapse;&quot;><tr class=&quot;title_word&quot; align=&quot;left&quot; style=&quot;background-color:#A3C2E1;font-weight:bold;&quot;><th scope=&quot;col&quot;>姓名</th><th scope=&quot;col&quot;>权限</th><th scope=&quot;col&quot;>部门</th><th scope=&quot;col&quot;>状态</th><th scope=&quot;col&quot;>&nbsp;</th><th scope=&quot;col&quot;>&nbsp;</th><th scope=&quot;col&quot;>&nbsp;</th></tr><tr class=&quot;form_content&quot; onmouseover=&quot;currentcolor=this.style.backgroundColor;this.style.backgroundColor='#cce6cf',this.style.fontWeight='';&quot; onmouseout=&quot;this.style.backgroundColor=currentcolor,this.style.fontWeight='';&quot; style=&quot;color:#333333;background-color:#E7E7FF;&quot;><td colspan=&quot;7&quot; style=&quot;background-color:Red;&quot;>目前无资料!</td></tr></table>"
OnSelectedIndexChanging
="GvUserInfo_SelectedIndexChanging" OnRowDeleting="GvUserInfo_RowDeleting">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="英文名" ReadOnly="True"></asp:BoundField>
<asp:TemplateField HeaderText="权限">
<EditItemTemplate>
<asp:DropDownList ID="drpAuth" runat="server">
<asp:ListItem Value="ADMIN">ADMIN</asp:ListItem>
<asp:ListItem Value="USER">USER</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblAuth" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="部门">
<EditItemTemplate>
<asp:DropDownList ID="drpDept" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDept" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="状态">
<EditItemTemplate>
<asp:CheckBox ID="chkStatus" runat="server" Text="Active" Checked="false"></asp:CheckBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="授权">
<ItemStyle ForeColor="Blue" />
</asp:CommandField>
<asp:CommandField ShowEditButton="True">
<ItemStyle ForeColor="Blue" />
</asp:CommandField>
<asp:CommandField ShowDeleteButton="True">
<ItemStyle ForeColor="Blue" />
</asp:CommandField>
<asp:TemplateField HeaderText="中文名">
<EditItemTemplate>
<asp:TextBox ID="txtCName" runat="server" Text='<%# Eval("CName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCName" runat="server" Text='<%# Bind("CName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="工号">
<EditItemTemplate>
<asp:Label ID="lblWorkid" runat="server" Text='<%# Bind("userid") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblWorkid" runat="server" Text='<%# Bind("userid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<hr style="background-color: Blue;" />
<asp:Panel ID="pan1" runat="server">
<table>
<tr>
<td style="border-right-style: solid; border-right-color: blue">
<asp:Button ID="Button2" runat="server" Text="保存授权" OnClick="BtnSaveItemRoute_Click" />
<asp:Button ID="Button3" runat="server" OnClick="BtnReset_Click" Text="重置" />
<br />
<asp:Label ID="Label3" runat="server" Text="您正在给"></asp:Label>
<asp:Label ID="lblUserName" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="分配权限:"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="(保存之后即可预览用户菜单)"></asp:Label>
<asp:Button ID="btnExUserTree" runat="server" Text="展开/收起" CommandName="1" OnCommand="btnExCo_Command" /></td>
<td>
<asp:Label ID="Label4" runat="server" Text="该用户菜单预览:"></asp:Label>
<asp:Button ID="btnExUserMenu" runat="server" Text="展开/收起" CommandName="3" OnCommand="btnExCo_Command" /></td>
</tr>
<tr>
<td style="vertical-align: top; border-right-style: solid; border-right-color: Blue">
<asp:TreeView ID="treeMenuData" runat="server" OnTreeNodeCheckChanged="treeMenuData_TreeNodeCheckChanged" />
<br />
<asp:Button ID="BtnSaveItemRoute" runat="server" Text="保存授权" OnClick="BtnSaveItemRoute_Click" />
<asp:Button ID="BtnReset" runat="server" Text="重置" OnClick="BtnReset_Click"></asp:Button>
</td>
<td style="vertical-align: top; text-align: ">
<asp:TreeView ID="treeUserMenu" runat="server" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>

 

UserRight.aspx.cs

 

UserRight.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 Daxon.Mes.Common;

public partial class Sys_UserRight : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
pan1.Visible
= false;
BindDataToGridView();
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n","")));
}
}
//绑定事件
treeMenuData.Attributes.Add("onclick", "OnTreeNodeChecked('" + treeMenuData.ClientID + "')");
Page.MaintainScrollPositionOnPostBack
= true;
}

#region GridView 事件响应

protected void GvUserInfo_RowEditing(object sender, GridViewEditEventArgs e)
{
GvUserInfo.EditIndex
= e.NewEditIndex;
GvUserInfo.SelectedIndex
= -1;
BindDataToGridView();
this.pan1.Visible = false;
}

protected void GvUserInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GvUserInfo.EditIndex
= -1;
GvUserInfo.SelectedIndex
= -1;
BindDataToGridView();
}

protected void GvUserInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GvUserInfo.PageIndex
= e.NewPageIndex;
GvUserInfo.EditIndex
= -1;
GvUserInfo.SelectedIndex
= -1;
BindDataToGridView();
}

protected void GvUserInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GvUserInfo.SelectedIndex
= -1;
GvUserInfo.EditIndex
= -1;
try
{
#region 获取参数值
string ename = GvUserInfo.DataKeys[e.RowIndex].Values["UserName"].ToString();
string dept = ((DropDownList)GvUserInfo.Rows[e.RowIndex].FindControl("drpDept")).SelectedItem.Value.ToString();
string authtype = ((DropDownList)GvUserInfo.Rows[e.RowIndex].FindControl("drpAuth")).SelectedItem.Value.ToString();
bool chkStatus = ((CheckBox)GvUserInfo.Rows[e.RowIndex].FindControl("chkStatus")).Checked;
string cname = ((TextBox)GvUserInfo.Rows[e.RowIndex].FindControl("txtCName")).Text.Trim();
int strStatus = 0;
if (chkStatus == true)
{
strStatus
= 1;
}
#endregion
string strResult = UserMenuData.UpdateUserInfo(ename, authtype, dept, strStatus, User.Identity.Name,cname);

#region 处理结果

System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument();
xmlDoc.LoadXml(strResult);
string result = xmlDoc.DocumentElement.SelectSingleNode("/root/result").InnerText;
string msg = xmlDoc.DocumentElement.SelectSingleNode("/root/Description").InnerText;

if (result.Equals("0"))//处理成功
{
BindDataToGridView();
}
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(msg));
#endregion
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n","")));
}
}

protected void GvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState.ToString().IndexOf("Edit") == -1 && e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#cce6cf',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

string value = Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["UserType"].ColumnName));

if (value.ToUpper().Equals("ADMIN"))
{
e.Row.Cells[
4].Enabled = false;
}
((Label)e.Row.FindControl(
"lblAuth")).Text = value;
value
= Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["Department"].ColumnName));
((Label)e.Row.FindControl(
"lblDept")).Text = value;
value
= Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["Status"].ColumnName));
if (value == "1")
((Label)e.Row.FindControl(
"lblStatus")).Text = "Active";
else
((Label)e.Row.FindControl(
"lblStatus")).Text = "UnActive";

}

if (e.Row.RowState.ToString().IndexOf("Edit") >= 0)
{
//绑定编辑行的下拉列表drpDept
DropDownList drp = (DropDownList)e.Row.FindControl("drpDept");
DataTable dt
= CReportData.GetRcsysBasicInfo("DEPT", "%");
WebControlOp.BindDataToDrpList(drp, dt,
"SData", "Sdata");

string value = Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["Department"].ColumnName));
ListItem li
= drp.Items.FindByValue(value);
if (li != null)
{
int index = drp.Items.IndexOf(li);
drp.SelectedIndex
= index;
}
else
drp.SelectedIndex
= 0;

//绑定编辑行的下拉列表drpAuth
DropDownList drpAuth = (DropDownList)e.Row.FindControl("drpAuth");
string valueAuth = Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["UserType"].ColumnName));
li
= drpAuth.Items.FindByValue(valueAuth);
if (li != null)
{
int index = drpAuth.Items.IndexOf(li);
drpAuth.SelectedIndex
= index;
}
else
drpAuth.SelectedIndex
= 0;

//绑定编辑行的CheckBox chkStatus
CheckBox chk = (CheckBox)e.Row.FindControl("chkStatus");
string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, ((DataTable)this.GvUserInfo.DataSource).Rows[0].Table.Columns["Status"].ColumnName));
if (status == "1")
chk.Checked
= true;
}
if (e.Row.RowType == DataControlRowType.Pager)
{
TableRow row
= e.Row.Controls[0].Controls[0].Controls[0] as TableRow;
foreach (TableCell cell in row.Cells)
{
Control lb
= cell.Controls[0];
if (lb is Label)
((Label)lb).ForeColor
= System.Drawing.Color.Red;
}
}
}

protected void GvUserInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GvUserInfo.SelectedIndex
= -1;
GvUserInfo.EditIndex
= -1;
try
{
string workid = ((Label)GvUserInfo.Rows[e.RowIndex].FindControl("lblWorkid")).Text.Trim();

string strResult = UserMenuData.DeleteUserInfo(workid);

#region 处理结果

System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument();
xmlDoc.LoadXml(strResult);
string result = xmlDoc.DocumentElement.SelectSingleNode("/root/result").InnerText;
string msg = xmlDoc.DocumentElement.SelectSingleNode("/root/Description").InnerText;

if (result.Equals("0"))//处理成功
{
BindDataToGridView();
}
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(msg));
#endregion
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n", "")));
}
}

protected void GvUserInfo_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string ename = GvUserInfo.Rows[e.NewSelectedIndex].Cells[0].Text;
lblUserName.Text
= ename;
ResetUserTree(ename);
}

/// <summary>
/// 设置TreeView,ToolTip 属性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void treeMenuData_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
string modifyFlag = e.Node.ToolTip.ToString();

if (modifyFlag == "0")
e.Node.ToolTip
= "1";
else
e.Node.ToolTip
= "0";
}
#endregion

#region 自定义方法

private void BindDataToGridView()
{
string strQueryCondition = drpQueryCondition.SelectedValue.ToString();//查询根据的条件
string strQueryText = txtQueryText.Text.ToString(); //查询输入的value

if (strQueryText.Trim().Length == 0)
strQueryText
= "%";

System.Data.DataTable dsUserInfo
= new DataTable();
try
{
dsUserInfo
= UserMenuData.GetUserList(strQueryCondition,strQueryText);

GvUserInfo.DataSource
= dsUserInfo;
GvUserInfo.DataKeyNames
= new string[] { "UserName" };
GvUserInfo.DataBind();
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n","")));
}
}

private void ResetUserTree(string username)
{
pan1.Visible
= true;
DataTable dt
= UserMenuData.GetUserMenu(username, "0");

TreeViewOp tv
= new TreeViewOp();
tv.BindToTreeView(treeMenuData, UserMenuData.GetSystemMenu(
"0"), "cmid", "cmname", "cmpvp", true);
tv.SetTreeViewCheckBox(treeMenuData, dt,
"cmid", "cmpvp");
tv.BindToTreeView(treeUserMenu, dt,
"cmid", "cmname", "cmpvp", false);

}

#endregion

#region 按钮事件
protected void btnInquire_Click(object sender, EventArgs e)
{
try
{
pan1.Visible
= false;

BindDataToGridView();
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n","")));
}
}

protected void BtnSaveItemRoute_Click(object sender, EventArgs e)
{
#region 获取菜单字符串
string strAllow = ",";
string strDeny = ",";
if (treeMenuData.Nodes.Count > 0)
{
TreeViewOp tv
= new TreeViewOp();
tv.GetSelected(treeMenuData.Nodes[
0], true);
strAllow
= tv.AllowString;
strDeny
= tv.DenyString;
}
#endregion

try
{
string strResult = UserMenuData.UpdateUserRight(lblUserName.Text, strAllow, strDeny, User.Identity.Name);

#region 处理结果

System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument();
xmlDoc.LoadXml(strResult);
string result = xmlDoc.DocumentElement.SelectSingleNode("/root/result").InnerText;
string msg = xmlDoc.DocumentElement.SelectSingleNode("/root/Description").InnerText;

if (result.Equals("0"))//处理成功
{
if (treeMenuData.Nodes.Count > 0)
{
ResetUserTree(lblUserName.Text);
treeUserMenu.ExpandAll();
}
}
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(msg));

#endregion
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "Alert", BaseCommon.GetMsgStr(ex.Message.Replace("\r\n", "")));
}
}

protected void BtnReset_Click(object sender, EventArgs e)
{
if (treeMenuData.Nodes.Count > 0)
{
DataTable dt
= UserMenuData.GetUserMenu(lblUserName.Text, "0");
TreeViewOp tv
= new TreeViewOp();
tv.ClearTreeViewCheckStatus(treeMenuData.Nodes[
0]);
tv.SetTreeViewCheckBox(treeMenuData, dt,
"cmid", "cmpvp");
}
}

/// <summary>
/// 展开or收起TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExCo_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "1":
treeMenuData.ExpandAll();
btnExUserTree.CommandName
= "2";
break;
case "2":
treeMenuData.CollapseAll();
btnExUserTree.CommandName
= "1";
break;
case "3":
treeUserMenu.ExpandAll();
btnExUserMenu.CommandName
= "4";
break;
case "4":
treeUserMenu.CollapseAll();
btnExUserMenu.CommandName
= "3";
break;
default:
break;
}
}
#endregion


}

 

posted on 2010-09-28 16:08  遗失的星空  阅读(326)  评论(0编辑  收藏  举报