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

📄 st_addgrade.aspx.cs

📁 学生管理系统(asp.net+sql server)
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;

namespace STGROUP
{
	/// <summary>
	/// ST_addgrade 的摘要说明。
	/// </summary>
	public class ST_addgrade : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox st_tbx_studentid;
		protected System.Web.UI.WebControls.Button st_btn_add;
		protected System.Web.UI.WebControls.Label st_lbl_note;
		protected System.Web.UI.WebControls.TextBox st_tbx_term;
		protected System.Web.UI.WebControls.CustomValidator st_cv_id;
		protected System.Web.UI.WebControls.DropDownList st_ddl_course;
		protected System.Web.UI.WebControls.TextBox st_tbx_grade;
	    SqlConnection st_conn;
		private void Page_Load(object sender, System.EventArgs e)
		{
			string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
			// 在此处放置用户代码以初始化页面
			st_conn=new SqlConnection(st_connstr);	
		}

		#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.st_tbx_studentid.TextChanged += new System.EventHandler(this.st_tbx_studentid_TextChanged);
			this.st_cv_id.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.st_cv_id_ServerValidate);
			this.st_btn_add.Click += new System.EventHandler(this.st_btn_add_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void st_btn_add_Click(object sender, System.EventArgs e)
		{
			string st_sqlstr="update ST_student_course set ST_Student_grade=@Student_grade where ST_Student_id=@Student_id and  ST_Course_id=@Course_id and ST_Course_year=@Course_year";
			 SqlCommand st_comm=new SqlCommand(st_sqlstr,st_conn);
			 st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50));
			 st_comm.Parameters["@Student_id"].Value=st_tbx_studentid.Text;
			 st_comm.Parameters.Add(new SqlParameter("@Course_id",SqlDbType.VarChar,50));
			 st_comm.Parameters["@Course_id"].Value=st_ddl_course.SelectedItem.Value;
			 st_comm.Parameters.Add(new SqlParameter("@Course_year",SqlDbType.Char,10));
			 st_comm.Parameters["@Course_year"].Value=st_tbx_term.Text;
			st_comm.Parameters.Add(new SqlParameter("@Student_grade",SqlDbType.Int,4));
			st_comm.Parameters["@Student_grade"].Value=st_tbx_grade.Text;
			 st_comm.Connection.Open();
			try
			{
				st_comm.ExecuteNonQuery();
			    Response.Redirect("ST_grade_manage.aspx");
				
			}
			catch(SqlException)
			{
				st_lbl_note.Text="添加失败";
				st_lbl_note.Style["color"]="red";
			}
			 st_comm.Connection.Close();			
		 	
		}
		

		private void st_cv_id_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
		{
			string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
			st_conn=new SqlConnection(st_connstr);
			st_conn.Open();
			string st_sqlstr="select * from ST_student where ST_Student_id='"+st_tbx_studentid.Text+"'";
			SqlCommand st_comm=new SqlCommand(st_sqlstr,st_conn);
			SqlDataReader st_dr=st_comm.ExecuteReader();
			if(st_dr.Read())
			{
				args.IsValid=true;
			}
			else
			{
				args.IsValid=false;
			}
			st_conn.Close();
		
		}



		private void st_tbx_studentid_TextChanged(object sender, System.EventArgs e)
		{		
			//课程名称下拉列表框绑定
			string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
			SqlConnection st_conn0=new SqlConnection(st_connstr);
				st_conn0.Open ();
				string st_sql1="select ST_course.* from ST_student_course,ST_course where ST_student_course.ST_Student_id='"+st_tbx_studentid.Text+"'and ST_student_course.ST_Course_id=ST_course.ST_Course_id";
				SqlCommand st_comm1=new SqlCommand  (st_sql1,st_conn0);
				SqlDataReader st_dr1=st_comm1.ExecuteReader ();
				while(st_dr1.Read ())
				{
					st_ddl_course.Items .Add (new ListItem(st_dr1["ST_Course_name"].ToString() ,st_dr1["ST_Course_id"].ToString()) );
				}
				st_conn0.Close ();
			
		}

		
	}
}

⌨️ 快捷键说明

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