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

📄 student.aspx.cs

📁 yi ge xue sheng cheng ji guan li xi tong de yuan ma .
💻 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;

namespace myResult
{
	/// <summary>
	/// student 的摘要说明。
	/// </summary>
	public class student : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lbname;
		protected System.Web.UI.WebControls.Label lbclass;
		protected System.Web.UI.WebControls.TextBox txtpwd;
		protected System.Web.UI.WebControls.TextBox txtemail;
		protected System.Web.UI.WebControls.Button btnmake;
		protected System.Web.UI.WebControls.Button btnsubmit;
		protected System.Web.UI.WebControls.Label lbnumber;
		protected SqlConnection conn;
		protected SqlCommand myCmd;
		protected System.Web.UI.WebControls.Button btnexit;
		protected System.Web.UI.WebControls.DataGrid dgResult;
		protected System.Web.UI.WebControls.RegularExpressionValidator revpwd;
		protected System.Web.UI.WebControls.RegularExpressionValidator revemail;
		protected System.Web.UI.WebControls.ValidationSummary vsShow;
		protected SqlDataReader myDr;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string str_user=Session["user"].ToString();//Session传值
				conn=connDB.createConn();
				if(!Page.IsPostBack)
				{
					this.toBind();
					this.bindDg();
				}
		}
		private void toBind()
		{
			string str_id=Session["id"].ToString();
			conn.Open();
			//执行存储过程
			myCmd=new SqlCommand();
			myCmd.Connection=conn;
			myCmd.CommandText="procShowStudent";//procStudent是存储过程
			myCmd.CommandType=CommandType.StoredProcedure;
			SqlParameter param=new SqlParameter("@Aid",SqlDbType.Int);
			param.Value=str_id;
			param.Direction=ParameterDirection.Input;
			myCmd.Parameters.Add(param);
			myDr=myCmd.ExecuteReader();
			if(myDr.Read())
			{
				this.lbnumber.Text=myDr["Snumber"].ToString().Trim();
				this.lbname.Text=myDr["Sname"].ToString().Trim();
				this.lbclass.Text=myDr["ClassName"].ToString().Trim();
				this.txtemail.Text=myDr["E_mail"].ToString().Trim();
			}
			myDr.Close();
			conn.Close();
		}
		private void bindDg()
		{
			string str_user=Session["user"].ToString();
			string str_sel="select CourseName,Result from Results where Snumber='"+str_user+"'";
			if(conn.State==ConnectionState.Closed)
			{
				conn.Open();
			}
			myCmd=new SqlCommand();
			myCmd.Connection=conn;
			myCmd.CommandText=str_sel;
			myDr=myCmd.ExecuteReader();
			if(myDr.Read())
			{
				dgResult.DataSource=myDr;
				dgResult.DataBind();
			}
			myDr.Close();
			conn.Close();
		}
		private void ExecuteUpdate()
		{
			string str_id=Session["id"].ToString();
			string str_pwd=this.txtpwd.Text.Trim().Replace("'","''");
			string str_pwdMD5=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_pwd,"MD5").ToString();
			string str_email=this.txtemail.Text.Trim().Replace("'","''");
			string str_update="";
			if(str_pwd=="")
			{
				str_update="update Student set E_mail='"+str_email+"' where StudentId='"+str_id+"'";
			}
			else
			{
				str_update="update Student set Spassword='"+str_pwdMD5+"',E_mail='"+str_email+"' where StudentId='"+str_id+"'";
			}
			if(conn.State==ConnectionState.Closed)
			{
				conn.Open();
			}
			myCmd=new SqlCommand();
			myCmd.Connection=conn;
			myCmd.CommandText=str_update;
			myCmd.CommandType=CommandType.Text;
			myCmd.ExecuteNonQuery();
			conn.Close();
			string Dhtmlalert="";
			Dhtmlalert += "<script language=javascript>";
			Dhtmlalert += "alert('修改成功!');";
			Dhtmlalert += "</script>";
			Page.RegisterClientScriptBlock("alert_news",Dhtmlalert);//向客户端发出脚本快
		}

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

		}
		#endregion

		private void btnmake_Click(object sender, System.EventArgs e)
		{
			this.txtpwd.Enabled=true;
			this.txtemail.Enabled=true;
		}

		private void btnsubmit_Click(object sender, System.EventArgs e)
		{
			if(this.txtpwd.Text=="")
			{
				Page.RegisterStartupScript("show_message","<script language='javascript'>alert('密码不能为空!');</script>");
			}
			else
			{
				this.ExecuteUpdate();
				this.toBind();
			}
		}

		private void btnexit_Click(object sender, System.EventArgs e)
		{
			Session.Remove("user");
			Session.Remove("id");
			Response.Redirect("user.aspx");
		}
	}
}

⌨️ 快捷键说明

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