⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userpowermanage.aspx.cs

📁 很不错的公文流转系统
💻 CS
字号:
using System; 
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Diagnostics;
using OI.DatabaseOper;
namespace OI.Manage
{
	/// <summary>
	/// userPowerManage 的摘要说明。
	/// </summary>
	public class userPowerManage : OI.PageBase
	{
		protected System.Web.UI.WebControls.CheckBoxList CheckBoxListPowers;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Button ButtonSave;
		protected System.Web.UI.WebControls.Label LabelMsg;
		protected System.Web.UI.WebControls.ListBox Lst_roles;
		protected DatabaseConnect op=new DatabaseConnect();
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if (Session["userid"]==null)
			{
				Response.Write ("<script>alert('超时,请重新登录');top.location.href='../userpass.aspx';</script>");
				return ;
			}
			if(!Page.IsPostBack)
			{
				//BindListBox();//绑定所有可用的用户
				
				DisplayRoles();
				BindCheckBoxList();//取得所有可用的权限
			}
		}
		/// <summary>
		/// 绑定所有可用的用户
		/// </summary>
		private void BindListBox() {
			string sql="select [name],[id] from staff";
			Lst_roles.DataSource=op.getBinding(sql,"Staff");
			Lst_roles.DataTextField="Name";
			Lst_roles.DataValueField="Id";
			Lst_roles.DataBind();		
		}
		private void DisplayRoles()
		{
			string strsql ="select roleid,rolename from accounts_roles order by rolename ";
		
			DataSet ds=new DataSet ();
			ds=op.getBinding (strsql,"t");
			Lst_roles.DataSource =ds.Tables[0];
			Lst_roles.DataTextField =ds.Tables[0].Columns["rolename"].ToString ();
			Lst_roles.DataValueField =ds.Tables[0].Columns["roleid"].ToString ();
			Lst_roles.DataBind ();
		}
		/// <summary>
		/// 绑定选定的用户所拥有的权限
		/// </summary>
		/// <param name="userid"></param>
		private void BindCheckBoxList(string userid) 
		{
		
			  string    sql="select * from account_rolepermission where roleid="+userid;
		
			if(op.getData(sql).Count>0) //有用户有权限的情况
			{
				
				BindCheckBoxList();
				string osql="select ModuleID from account_rolepermission where roleid="+userid+" order by [ID]";
				System.Collections.ArrayList al=op.getData(osql);
						
				for(int i=0;i<CheckBoxListPowers.Items .Count ;i++)
				{
					for(int j=0;j<al.Count ;j++)
					{
						if(CheckBoxListPowers.Items [i].Value .Trim ().Equals (al[j].ToString ().Trim ()))
							CheckBoxListPowers.Items [i].Selected =true;
					}
				}

			}
			else   //用户没有设定权限的情况
			{
				for(int i=0;i<CheckBoxListPowers.Items.Count;i++) 
				{
					CheckBoxListPowers.Items [i].Selected =false;
				
				}
			}
		}
		/// <summary>
		/// 取得所有可用的权限
		/// </summary>
		private void BindCheckBoxList() {			
		    string resql="select moduleid ,modulename from models ";
			CheckBoxListPowers.DataSource=op.getBinding(resql,"Powers");
			CheckBoxListPowers.DataTextField="modulename";
			CheckBoxListPowers.DataValueField="moduleid";
			CheckBoxListPowers.DataBind();	
			for(int i=0;i<CheckBoxListPowers.Items.Count;i++){
				CheckBoxListPowers.Items[i].Selected=false;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Lst_roles.SelectedIndexChanged += new System.EventHandler(this.Lst_roles_SelectedIndexChanged);
			this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ButtonSave_Click(object sender, System.EventArgs e) {

				if(Lst_roles.SelectedIndex>-1){			
					System.Collections.ArrayList al=new System.Collections.ArrayList();
					string sql1="delete from account_rolepermission where roleid='"+Lst_roles.SelectedItem.Value+"'";
					al.Add((object)sql1);//将删除语句加入事务以备处理
					string sql="";								
					for(int i=1;i<CheckBoxListPowers.Items.Count+1;i++) {
							if(CheckBoxListPowers.Items[i-1].Selected){ //如果选定就记录他的Id号								
								sql="insert into account_rolepermission  values('"+Lst_roles.SelectedItem.Value+"','"+CheckBoxListPowers.Items[i-1].Value +"')";//写入数据库
								//sql="insert into account_rolepermission  values('"+CheckBoxListPowers.Items[i-1].Value+"','"+Lst_roles.SelectedItem.Value +"')";//写入数据库
								al.Add((object)sql);	
							}						
						}				
					if(op.ExecuteTransaction(al)) {
						LabelMsg.Text="权限处理成功";			
					}
				}
				else {
					
					Page.RegisterStartupScript ("","<script>alert('请选择要设定权限的用户')</script>");
				}
		}
		private void Lst_roles_SelectedIndexChanged(object sender, System.EventArgs e) {
			BindCheckBoxList(Lst_roles.SelectedItem.Value);
			LabelMsg.Text="";
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -