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

📄 role.aspx.cs

📁 很不错的公文流转系统
💻 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 ;
using OI.DatabaseOper;

namespace OI.Manage
{
	/// <summary>
	/// role 的摘要说明。
	/// </summary>
	public class role : OI.PageBase
	{
		protected System.Web.UI.WebControls.TextBox Txt_role_depiction;
		protected System.Web.UI.WebControls.ListBox Lst_roles;
		protected System.Web.UI.WebControls.TextBox Txt_role_name;
		protected System.Web.UI.WebControls.ImageButton Btn_add;
		protected System.Web.UI.WebControls.ImageButton Btn_modify;
		protected System.Web.UI.WebControls.ImageButton Btn_shift;
		protected System.Web.UI.WebControls.ImageButton Btn_cancer;
		protected System.Web.UI.WebControls.ImageButton Btn_del;
		protected System.Web.UI.WebControls.ImageButton  Btn_Power;
		protected System.Web.UI.WebControls.ImageButton ImageButtonpower;
		protected System.Web.UI.WebControls.Label LabelRolePression;
		protected System.Web.UI.WebControls.ListBox ListBoxRolePression;
	    protected DatabaseConnect Dbc =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 ;
			}
			       	
			Btn_add.Attributes["onclick"]="return check()";
			Btn_modify.Attributes["onclick"]="return check()";
			Btn_del.Attributes["onclick"]="return confirm('你是否确定要删除')";     
			if (Page.IsPostBack )
			{
			}
			else
			{
				DisplayRoles();
				//状态设置
                Btn_modify.Visible =false;
				Btn_shift.Visible=false;
				Btn_del.Visible =false;
				//Btn_Power.Visible=false;

				//
			}
            
		}
		private void DisplayRoles()
		{
			string strsql ="select roleid,rolename from accounts_roles order by rolename ";
			DataSet ds=new DataSet ();
			ds=Dbc.getBinding (strsql,"s");
			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 ();
		}

//		private void Open_server()
//		{
//			string open="server=sql;uid=sa;pwd=;data source=csx; database=oa ";
//		
//			try
//			{
//				Conn=new SqlConnection (open);
//				Conn.Open ();
//			}
//			catch
//			{
//				Page.RegisterStartupScript ("","<script>alert('不能正确打开服务器,请检查服务器的配置')</script>");
//			
//			}
//		}


		#region Web 窗体设计器生成的代码
		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.Btn_add.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtonadd_Click);
			this.Btn_modify.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtonmodify_Click);
			this.Btn_cancer.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtoncancer_Click);
			this.Btn_del.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtondelete_Click);
			this.ImageButtonpower.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtonpower_Click);
			this.Btn_shift.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtonshift_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
        
		
		private void Lst_roles_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string strsql="select * from accounts_roles where roleid="+Lst_roles.SelectedValue ;
			string strsql1="select ModuleName from dbo.Models inner join  dbo.Account_RolePermission on dbo.Models.ModuleID=dbo.Account_RolePermission.ModuleID where dbo.Account_RolePermission.RoleID="+Lst_roles.SelectedValue;
			DataSet ds=new DataSet ();
			
			ds=Dbc.getBinding (strsql,"s");
			ArrayList al=Dbc.getData(strsql1);
			ListBoxRolePression.DataSource=al;
			ListBoxRolePression.DataBind();
			if(al.Count!=0)
			{
				LabelRolePression.Visible=true;
				ListBoxRolePression.Visible=true;
			}
			else
			{
				LabelRolePression.Visible=false;
				ListBoxRolePression.Visible=false;
			}
			Txt_role_name.Text =ds.Tables[0].Rows [0]["rolename"].ToString ();
			Txt_role_depiction.Text =ds.Tables[0].Rows[0]["Description"].ToString (); 
			Btn_modify.Visible =true;
			Btn_shift.Visible=true;
			Btn_del.Visible =true;
			//Btn_Power.Visible=true;
			Btn_add.Visible =false;
			Btn_cancer.Visible =false;
			
		}


		
		
		
		private void ImageButtonadd_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			string strsql;
			Txt_role_depiction.Text=Txt_role_depiction.Text.Replace ("'","'");
			strsql="select count(*) from accounts_roles where RoleName='"+Txt_role_name.Text+"'";
			// SqlCommand c=new SqlCommand (strsql,Conn);
			//			object o=c.ExecuteScalar ();
			string o=Dbc.GetValueBySql (strsql);
			int number =int.Parse (o);
			if ( number >0)
			{
				Page.RegisterStartupScript ("","<script>alert('角色名称\""+Txt_role_name.Text+ "\"己经存在');</script>");
				return ;
			}
			strsql="insert into accounts_roles values('"+Txt_role_name.Text +"','"+Txt_role_depiction.Text +"')"    ;
			try
			{
			  
				Dbc.ExecuteSQL (strsql);
			}
			catch
			{

			}
			Response.Redirect ("role.aspx");
			
		}

		private void ImageButtonmodify_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			string strsql;
			Txt_role_depiction.Text=Txt_role_depiction.Text.Replace ("'","'");
			strsql="select count(*) from accounts_roles where RoleName='"+Txt_role_name.Text+"' and roleid !=" +Lst_roles.SelectedValue  ;
			string o=Dbc.GetValueBySql (strsql);
			int number =int.Parse (o);
			if ( number >0)
			{
				Page.RegisterStartupScript ("","<script>alert('角色名称\""+Txt_role_name.Text+ "\"己经存在');</script>");
				return ;
			}
			strsql="update  accounts_roles set RoleName='"+Txt_role_name.Text +"',Description='"+Txt_role_depiction.Text +"' where roleid =" +Lst_roles.SelectedValue    ;
			try
			{
				Dbc.ExecuteSQL (strsql);
				
			}
			catch
			{

			}
			Response.Redirect ("role.aspx");
		}

		private void ImageButtonshift_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
//			Btn_modify.Visible =false;
//			Btn_shift.Visible=false;
//			Btn_del.Visible =false;
//			//Btn_Power.Visible=false;
//			Btn_add.Visible =true;
//			Btn_cancer.Visible =true;
//			Lst_roles.SelectedItem.Selected =false; 
//			Txt_role_name.Text ="";
//			Txt_role_depiction.Text ="";
			Response.Redirect("role.aspx");
		
		}

		private void ImageButtoncancer_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Txt_role_name.Text ="";
			Txt_role_depiction.Text ="";
		}

		private void ImageButtondelete_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Lst_roles.SelectedValue  =="")
			{
				Page.RegisterStartupScript ("","<script>alert('请选择一个角色')</script>");
				return ;
			}
			
			string strsql="select count(*) from account_rolepermission where roleid="+Lst_roles.SelectedValue ;
			string number=  Dbc.GetValueBySql (strsql);
			if (int.Parse (number) >0)
			{
				Page.RegisterStartupScript ("","<script>alert('请先删除角色:"+Lst_roles.SelectedItem.Text  +"的权限,再删除此角色 ')</script>");
				return ;
			}
			strsql="delete from accounts_roles where Roleid="+Lst_roles.SelectedValue ;
			Dbc.ExecuteSQL (strsql);

			
			
			Response.Redirect ("role.aspx");
		} 

		private void ImageButtonpower_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Lst_roles.SelectedValue  =="")
			{
				Page.RegisterStartupScript ("","<script>alert('请选择一个角色')</script>");
				return ;
			}
			Response.Redirect ("RolePower.aspx?roleid="+Lst_roles.SelectedValue);
		}

		private void Btn_shift_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
		
		}

	
		
	 
	}
}

⌨️ 快捷键说明

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