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

📄 webusercontrol1.ascx.cs

📁 一款很好的在线考试系统的毕业设计
💻 CS
字号:
namespace OLTestS
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Data.SqlClient;

	/// <summary>
	///		WebUserControl1 的摘要说明。
	/// </summary>
	public class WebUserControl1 : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label2;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		
			if ((Convert.ToInt32(Session["Login"])==1)||(Convert.ToInt32(Session["Login"])==2))
			{
			  
				Button3.Visible=true;				
				Label1.Visible=false;
				TextBox1.Visible=false;
				Label2.Visible=false;
				TextBox2.Visible=false;				
				Button2.Visible=false;
				DropDownList1.Visible=false;
				
				Label3.Text="欢迎:"+Session["Name"].ToString();
             }
			else
			{
				Button3.Visible=false;				
				Label1.Visible=true;
				TextBox1.Visible=true;
				Label2.Visible=true;
				TextBox2.Visible=true;				
				Button2.Visible=true;
				DropDownList1.Visible=true;
				
				Label3.Text="";
			}
           
		}

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

		}
		#endregion


		


		private void Button2_Click(object sender, System.EventArgs e)
		{
			if(DropDownList1.Items[1].Selected)
			{
				try
				{
					SqlConnection cn=new SqlConnection("server=.;uid=sa;database=nTest");
					SqlDataAdapter da=new SqlDataAdapter();
					da.SelectCommand=new SqlCommand();
					da.SelectCommand.Connection=cn;
					da.SelectCommand.CommandText="Adminloginproc";
					da.SelectCommand.CommandType=CommandType.StoredProcedure;
					SqlParameter dsp1=new SqlParameter("@Name",SqlDbType.Char,10);
					SqlParameter dsp2=new SqlParameter("@Password",SqlDbType.Char,10);
					SqlParameter dsp3=new SqlParameter("@result",SqlDbType.Int);
					dsp3.Direction=ParameterDirection.Output;
					dsp1.Value=TextBox1.Text;
					dsp2.Value=TextBox2.Text;
					da.SelectCommand.Parameters.Add(dsp1);
					da.SelectCommand.Parameters.Add(dsp2);
					da.SelectCommand.Parameters.Add(dsp3);
					DataSet ds=new DataSet();
					da.Fill(ds);

					int Result=Convert.ToInt32(da.SelectCommand.Parameters["@result"].Value);
			
					if (Result==1)
					{
                  
					
					
						Session["Name"]=TextBox1.Text;
						Session["Login"]=2;
						this.Response.Redirect("Login.aspx");
					}
					else
					{
						Label3.Text="密码错误或用户名无效!";
					}
				}
				catch
				{
					Label3.Text="该用户不存在!";
				}
			}
			else
			{
				try
				{
					SqlConnection cn=new SqlConnection("server=.;uid=sa;database=nTest");
					SqlDataAdapter da=new SqlDataAdapter();
					da.SelectCommand=new SqlCommand();
					da.SelectCommand.Connection=cn;
					da.SelectCommand.CommandText="Loginproc";
					da.SelectCommand.CommandType=CommandType.StoredProcedure;
					SqlParameter dsp1=new SqlParameter("@StuNo",SqlDbType.Char,10);
					SqlParameter dsp2=new SqlParameter("@Password",SqlDbType.Char,10);
					SqlParameter dsp3=new SqlParameter("@result",SqlDbType.Int);
					dsp3.Direction=ParameterDirection.Output;
					dsp1.Value=TextBox1.Text;
					dsp2.Value=TextBox2.Text;
					da.SelectCommand.Parameters.Add(dsp1);
					da.SelectCommand.Parameters.Add(dsp2);
					da.SelectCommand.Parameters.Add(dsp3);
					DataSet ds=new DataSet();
					da.Fill(ds);
				
				

					int Result=Convert.ToInt32(da.SelectCommand.Parameters["@result"].Value);
					if (Result==1)
					{
						Session["Name"]=TextBox1.Text;
						Session["Login"]=1;
						this.Response.Redirect("Login.aspx");
					}
					else
					{
						Label4.Text="密码错误或用户名无效!";
					}
				
				}
				catch
				{
					Label4.Text="该用户不存在!";
				}
			}

		}


		private void Button3_Click(object sender, System.EventArgs e)
		{
			Session["Login"]=0;
			this.Response.Redirect("Login.aspx");
		}


	}
}

⌨️ 快捷键说明

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