📄 authoritymanage.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.SqlClient;
//该源码下载自www.51aspx.com(51aspx.com)
namespace Service
{
/// <summary>
/// Summary description for AuthorityManage.
/// </summary>
public partial class AuthorityManage : System.Web.UI.Page
{
public String sOperation = "";
public String sLinkName = "";
protected void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
else
{
String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString()));
if(sUserRoleName.IndexOf("Admin") == -1)
{
Response.Redirect("~/Default.aspx");
}
}
if(!Page.IsPostBack)
{
BindUserData();
BindRoleData();
BindUserRoleData(Int32.Parse(UserList.SelectedValue));
}
if(Request.Params["LinkID"] != null)
{
GetLinkName(Request.Params["LinkID"].ToString());
}
}
private void GetLinkName(String sLinkID)
{
String[] aName = new String[2];
aName = GlobalVarables.GetLinkName(sLinkID);
if(GlobalVarables.aLinkName.Count > 0)
{
sOperation = aName[0].ToString();
sLinkName = aName[1].ToString();
}
}
private void BindUserData()
{
UserList.Items.Clear();
UserDB user = new UserDB();
SqlDataReader recu = user.GetUsers();
UserList.DataSource = recu;
UserList.DataTextField = "UserName";
UserList.DataValueField = "ID";
UserList.DataBind();
recu.Close();
}
private void BindRoleData()
{
RoleList.Items.Clear();
RoleDB role = new RoleDB();
SqlDataReader recr = role.GetRoles();
RoleList.DataSource = recr;
RoleList.DataTextField = "RoleName";
RoleList.DataValueField = "ID";
RoleList.DataBind();
recr.Close();
if(RoleList.Items.Count > 0)
{
ApplyOwner.Enabled = true;
}
else
{
ApplyOwner.Enabled = false;
}
}
private void BindUserRoleData(int nUserID)
{
if(UserList.Items.Count > 0)
{
UserDB user = new UserDB();
SqlDataReader recu = user.GetSingleUser(nUserID);
while(recu.Read())
{
RoleName.Text = recu["RoleName"].ToString();
}
recu.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void UserList_SelectedIndexChanged(object sender, System.EventArgs e)
{
BindUserRoleData(Int32.Parse(UserList.SelectedValue));
}
protected void ApplyOwner_Click(object sender, System.EventArgs e)
{
if(UserList.SelectedIndex > -1 && RoleList.SelectedIndex > -1)
{
UserDB user = new UserDB();
try
{
user.UpdateUserRole(Int32.Parse(UserList.SelectedValue),Int32.Parse(RoleList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
BindUserRoleData(Int32.Parse(UserList.SelectedValue));
ClearingSelected(RoleList);
}
else
{
Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
}
}
private void ClearingSelected(ListBox listBox)
{
for(int i = 0; i < listBox.Items.Count; i++)
{
listBox.Items[i].Selected = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -