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

📄 admin_login.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>
	/// admin_login 的摘要说明。
	/// </summary>
	public class admin_login : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox Username;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.TextBox Password;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
		protected System.Web.UI.WebControls.Button Submit;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!Page.IsPostBack)
			{
				Session["userclass"]="";
				Session["pwd"]=""	  ;
				Session["classname"]="";
				Session["username"]="";
			}

		

		}

		
		private void conn(string t1,string t2)	  //验证过程
		{
			try
			{
				string con=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
				SqlConnection myConnection = new SqlConnection(con);//连接字符串
				myConnection.Open();									 //连接数据库
		  
				SqlCommand cd=new SqlCommand("sp_selAdmin",myConnection);	//设置SQL命令
				cd.CommandType=CommandType.StoredProcedure;	  //调用存储过程

				SqlParameter username= cd.Parameters.Add("@username", SqlDbType.Char,240);		  //设置存储过程参数
				SqlParameter password= cd.Parameters.Add("@password", SqlDbType.NChar,240);
				username.Value=t1;
				password.Value=t2;

				SqlDataReader selreader ;	//设置SqlDataReader 类
				selreader=cd.ExecuteReader();				   //命令执行
				 
				if (selreader.Read()==true)					   //验证
				{

					Session["userclass"]=selreader.GetString(3);
					
					string	popedom=selreader.GetString(6);    //验证是否有增加新闻的功能
					Session["userclass"]=selreader.GetString(3);
					Session["classname"]=selreader.GetString(7);
					Session["popedom"]=selreader.GetString(6);
					Session["pwd"]=selreader.GetString(2);
					Session["id"]=selreader.GetInt64(0);
					Session["power"]=selreader.GetString(6);
					int i=popedom.Length;
					string df=popedom.Replace("addnews","1");
					Session["popedom"]=df;
					int j=df.Length;
					if(i!=j)
					{
						Session["addnews"]=1;

					}
					else  Session["addnews"]=0;
					
					i=popedom.Length;			         //验证是否有增加新闻不需审核功能的权限
					df=popedom.Replace("addnchk","1");
					j=df.Length ;
					if(i!=j)
					{
						Session["addnchk"]=1;

					}
					else Session["addnchk"]=0;
					
					i=popedom.Length;			         //验证是否有修改新闻的权限
					df=popedom.Replace("chgnews","1");
					j=df.Length ;
					if(i!=j)
					{
						Session["chgnews"]=1;
					}
					else  Session["chgnews"]=0;

					i=popedom.Length;			         //验证是否有审核新闻的权限
					df=popedom.Replace("chknews","1");
					j=df.Length ;
					if(i!=j)
					{
						Session["chknews"]=1;
					}
					else	Session["chknews"]=0;

					i=popedom.Length;			         //验证是否有管理评论的权限
					df=popedom.Replace("remark","1");
					j=df.Length ;
					if(i!=j)
					{
						Session["remark"]=1;
					}
					else  Session["remark"]=0;

					selreader.Close();		//关闭连接
					myConnection.Close();
					Response.Redirect("admin_main.htm");	//转向admin_main.htm
				}
				else 
				{
					selreader.Close();		//关闭连接
					myConnection.Close();
					Label1.Text="用户名或密码错误";

				}	
			}
			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) 
			{
				string username=Request["Username"]; //用户名
				string password=Request["Password"]; //密码
		  		Session["username"]=username; 
				conn(username,password);		 //验证用户密码
			}
		}
	}
}

⌨️ 快捷键说明

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