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

📄 admin_popedom.aspx.cs

📁 这个是用vc编写的新闻管理系统
💻 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 System.Configuration;
namespace WebNews.admin
{
	/// <summary>
	/// _1 的摘要说明。
	/// </summary>
	public class _1 : System.Web.UI.Page
	{   public string ClassName; 
		protected System.Web.UI.WebControls.CheckBox addNew;
		protected System.Web.UI.WebControls.CheckBox addNchk;
		protected System.Web.UI.WebControls.CheckBox chgnews;
		protected System.Web.UI.WebControls.CheckBox chknews;
		protected System.Web.UI.WebControls.CheckBox remark;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.WebControls.Label myLabel;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!Page.IsPostBack)
			{
				string userclass;
				userclass=(string)Session["userclass"];
				if(userclass.Trim()=="系统管理员")
				{
					validateCheckBox();
					bindRadioButtonList();
				}
				else Page.Visible=false;
			}  
		}
		private void validateCheckBox()
		{
			try
			{ 
				string con=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
				SqlConnection myConnection = new SqlConnection(con);//连接字符串
				myConnection.Open();
	        
				SqlDataAdapter myCommand = new SqlDataAdapter();  //创建SqlDataAdapter 类
			 	   
				myCommand.SelectCommand=new SqlCommand("sp_selAdminbyUserName",myConnection);		 //调用存储过程
				myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
				SqlParameter username=myCommand.SelectCommand.Parameters.Add("@username",SqlDbType.Char,40);	 //设置参数
				username.Value=Request["username"];
				myLabel.Text="用户"+Request["username"]+"的权限";					
				
				DataSet ds = new DataSet();			//建立并填充数据集
				myCommand.Fill(ds,"Admin");
				

		    DataRow dr;
				dr=ds.Tables["Admin"].Rows[0]  ;  //取得popedom字段
				
				ClassName=(string)dr["classname"];
				
				if(dr["popedom"]!=null)
				{
					string popedom=(string)dr["popedom"];	//验证是否有增加新闻权限
					int i=popedom.Length;
					string df=popedom.Replace("addnews","1");
					int j=df.Length ;
					if(i!=j)
					{
						addNew.Checked=true;
					}
					
					i=popedom.Length;			         //验证是否有增加新闻不需审核功能的权限
					df=popedom.Replace("addnchk","1");
					j=df.Length ;
					if(i!=j)
					{
						addNchk.Checked=true;
					}
					
					i=popedom.Length;			         //验证是否有修改新闻的权限
					df=popedom.Replace("chgnews","1");
					j=df.Length ;
					if(i!=j)
					{
						chgnews.Checked=true;
					}
					
					i=popedom.Length;			         //验证是否有审核新闻的权限
					df=popedom.Replace("chknews","1");
					j=df.Length ;
					if(i!=j)
					{
						chknews.Checked=true;
					}
					
					i=popedom.Length;			         //验证是否有管理评论的权限
					df=popedom.Replace("remark","1");
					j=df.Length ;
					if(i!=j)
					{
						remark.Checked=true;
					}
				}
					myConnection.Close();
			}
			catch(SqlException e)
			{
				Response.Write("Exception in Main: " + e.Message);	//出错处理

			}
		}
		private void bindRadioButtonList()
		{
			try
			{
				string con=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
				SqlConnection myConnection = new SqlConnection(con);//连接字符串
				myConnection.Open();
	        
				SqlDataAdapter selClassAll = new SqlDataAdapter();  //创建SqlDataAdapter 类
			 	   
				selClassAll.SelectCommand=new SqlCommand("sp_selFclassAll",myConnection);		 //调用存储过程
				selClassAll.SelectCommand.CommandType=CommandType.StoredProcedure ;
		   
				DataSet dt = new DataSet();
				selClassAll.Fill(dt);
			
				RadioButtonList1.DataSource=dt;									  //绑定RadioButtonList
				RadioButtonList1.DataTextField="className";
				RadioButtonList1.DataValueField="className";
				RadioButtonList1.DataBind();
				myConnection.Close();
				int i = 0;

				foreach(ListItem li in RadioButtonList1.Items)					 //选中分类名
				{
					if(li.Text ==ClassName)
					{
						li.Selected = true; 
					}
					i += 1;
				}
			}
			catch(SqlException e)
			{
				Response.Write("Exception in Main: " + e.Message);	//出错处理
        	}

}
		private void updateAdminPower()
		{
			string popedom="";
			if(addNew.Checked==true)
			{
				popedom="addnews,";
			}
			if(addNchk.Checked==true)
			{
				popedom+="addnchk,";
			}
			if(chgnews.Checked==true)
			{
				popedom+="chgnews,";
			}
			if(chknews.Checked==true)
			{
				popedom+="chknews,";
			}
			if(remark.Checked==true)
			{
				popedom+="remark,";
			}
			
		try
				{
					string con=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
					SqlConnection myConnection = new SqlConnection(con);//连接字符串
					myConnection.Open();                             //连接数据库
				
					SqlCommand updatePower=new SqlCommand("sp_updateAdminPower",myConnection);	  //调用存储过程
					updatePower.CommandType=CommandType.StoredProcedure;
				
					SqlParameter  Popedom=updatePower.Parameters.Add("@popedom",SqlDbType.NChar,200);			//设置参数
					SqlParameter  classname=updatePower.Parameters.Add("@classname",SqlDbType.Char,100);
					SqlParameter username=updatePower.Parameters.Add("@username",SqlDbType.Char,100);
				
					username.Value =Request["username"];
					Popedom.Value =popedom;
					classname.Value =RadioButtonList1.SelectedItem.Text;

					int r=updatePower.ExecuteNonQuery();	   //更新
				 
					if(r>0)
					{
						Response.Redirect("admin_user.aspx");		//返回"admin_user.aspx"
					}
			
				}
				catch(SqlException e)
				{
					Response.Write("Exception in Main: " + e.Message);	//出错处理
				}


		
		}

		#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.Submit.Click += new System.EventHandler(this.Submit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Submit_Click(object sender, System.EventArgs e)
		{
			if(Page.IsValid)
			{
				updateAdminPower();
			}
			}
	}
}

⌨️ 快捷键说明

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