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

📄 login.aspx.cs

📁 网上自动答疑系统(C#)
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace dayi
{
	/// <summary>
	/// login 的摘要说明。
	/// </summary>
	public class login : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.CheckBox isMaster;
		protected System.Web.UI.WebControls.TextBox txtUserPwd;
		protected System.Web.UI.WebControls.TextBox txtUserName;
		protected System.Web.UI.WebControls.Label lblMsg;
		protected System.Web.UI.WebControls.Panel PanLogin;
		protected System.Web.UI.WebControls.Label lblLoginMsg;

		dayi.controlDatabase cd=new controlDatabase();

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["userName"].ToString()=="")
			{
				this.PanLogin.Visible=true;
			}
			else
			{
				this.PanLogin.Visible=false;
				if(Session["userType"].ToString()=="user")
				{
					//普通用户
					this.lblLoginMsg.Text="<a href=userCenter.htm target=dayiMain>用户管理中心</a> <a href=exitLogin.aspx target=dayiMain>退出登录</a>";
				}
				else if(Session["userType"].ToString().IndexOf("master")>-1)
				{
					//栏目管理员
					this.lblLoginMsg.Text="<a href=masterCenter.htm target=dayiMain>用户管理中心</a> <a href=exitLogin.aspx target=dayiMain>退出登录</a>";
				}
			}
		}

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

		}
		#endregion

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			//登录系统
			//未登录
			string userName=this.txtUserName.Text.Trim().Replace("'","");
			string userPwd=this.txtUserPwd.Text.Trim().Replace("'","");
			userPwd=FormsAuthentication.HashPasswordForStoringInConfigFile(userPwd,"sha1");//加密
			string userType=(this.isMaster.Checked)?"master":"user";
			string sql="select * from [user] where userName='"+userName+"' and userPwd='"+userPwd+"' and locked='0'";
			if(userType=="master")
			{
				sql="select * from [master] where masterName='"+userName+"' and masterPwd='"+userPwd+"' and locked='0' and agreed='1'";
			}
			try
			{
				if(cd.catchRecord(sql))
				{
					Session["userName"]=userName;
					Session["userType"]="user";
					//得到管理员管理栏目的ID
					if(userType=="master")
					{
						DataTable dt=cd.getDataTable("select * from [board] where [boardMaster]='"+userName+"' and rootID=0");
						if(dt.Rows.Count>0)
						{
							Session["userType"]=userType+dt.Rows[0]["boardID"].ToString().Trim();
						}
						Response.Redirect("masterCenter.htm");
					}
					else
					{
						Response.Redirect("userCenter.htm");
					}
				}
				else
				{
					this.lblMsg.Text="<b>可能出现以下错误:</b><br>1、用户名或密码错误;<br>2、未通过管理员验证;<br>3、此帐户已被锁定。<br>具体请联系管理员";
				}
			}
			catch(Exception)
			{
				//Response.Redirect("err.aspx?err="+ee.Message);
			}
		}
	}
}

⌨️ 快捷键说明

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