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

📄 teacher.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>
	/// teacher 的摘要说明。
	/// </summary>
	public class teacher : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lbnumber;
		protected System.Web.UI.WebControls.Label lbname;
		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.TextBox txtterm;
		protected System.Web.UI.WebControls.TextBox txtphone;
		protected System.Web.UI.WebControls.Button btnexit;
		protected SqlConnection conn;
		protected SqlCommand myCmd;
		protected System.Web.UI.WebControls.DropDownList ddlcourse;
		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();
			conn=connDB.createConn();
			if(!IsPostBack)
			{
				this.toBind();
				this.bindDdlCourse();
			}
		}
		private void toBind()
		{
			string str_id=Session["id"].ToString();
			conn.Open();
			//执行存储过程
			myCmd=new SqlCommand();
			myCmd.Connection=conn;
			myCmd.CommandText="procSelTeacher";//procStudent是存储过程
			myCmd.CommandType=CommandType.StoredProcedure;
			myDr=myCmd.ExecuteReader();
			if(myDr.Read())
			{
				this.lbnumber.Text=myDr["Tnumber"].ToString().Trim();
				this.lbname.Text=myDr["Tname"].ToString().Trim();
				this.txtterm.Text=myDr["Term"].ToString().Trim();
				this.txtphone.Text=myDr["Phone"].ToString().Trim();
				this.txtemail.Text=myDr["E_mail"].ToString().Trim();
			}
			myDr.Close();
			conn.Close();
		}
		private void bindDdlCourse()
		{
			string str_sel="select CourseId,CourseName from Course";
			if(conn.State==ConnectionState.Closed)
			{
				conn.Open();
			}
			myCmd=new SqlCommand(str_sel,conn);
			myDr=myCmd.ExecuteReader();
			ddlcourse.DataSource=myDr;
			ddlcourse.DataTextField="CourseName";
			ddlcourse.DataBind();
		}
		private void ExecuteUpdate()
		{
			string str_id=Session["id"].ToString();
			string str_course=ddlcourse.SelectedValue.ToString();
			string str_term=this.txtterm.Text.Trim().Replace("'","''");
			string str_phone=this.txtphone.Text.Trim().Replace("'","''");
			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 Teacher set CourseName='"+str_course+"',Term='"+str_term+"',Phone='"+str_phone+"', E_mail='"+str_email+"' where TeacherId='"+str_id+"'";
			}
			else
			{
				str_update="update Teacher set CourseName='"+str_course+"',Term='"+str_term+"',Phone='"+str_phone+"', E_mail='"+str_email+"' where TeacherId='"+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.txtterm.Enabled=true;
			this.txtpwd.Enabled=true;
			this.txtphone.Enabled=true;
			this.txtemail.Enabled=true;
		}

		private void btnsubmit_Click(object sender, System.EventArgs e)
		{
			if(this.IsValid)
			{
				this.ExecuteUpdate();
			}
		}

		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 + -