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

📄 editcourse.ascx.cs

📁 电子选课系统 电子选课系统电子选课系统电子选课系统
💻 CS
字号:
namespace Park.CourseSystem
{
	using System;
	using System.Data;
	using System.Data.SqlClient;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using Park.Common;

	/// <summary>
	///		EditCourse 的摘要说明。
	/// </summary>
	public abstract class EditCourse : System.Web.UI.UserControl
	{
		protected Epico.Controls.List TeacherDropDownList;
		protected System.Web.UI.WebControls.DataGrid TeacherList;
		private object courseid;
		private void Page_Load(object sender, System.EventArgs e)
		{

			courseid=Session[SessionKey.CourseID];

			if(courseid==null||courseid.Equals(""))
				return;

			ProcessDeleted();
				
			ProcessParams();

			initializeList();
			
			LoadStatus();

			LoadData();

			Session[SessionKey.CourseID]=courseid;
   		}
		#region completed
		private void ProcessDeleted()
		{
			string id=Request["removeid"];
			if(id != null && !id.Equals("")) 
			{
				CourseDB.DeleteTeacher( (string)courseid ,id );
				// Redirect browser back to originating page
				Response.Redirect(Request.ApplicationPath);

			}
		}

		private void ProcessParams()
		{
			if(!this.IsPostBack) return;

			string action=Request["commit"];
			if ( action==null || action.Equals("")) return;
			if (action.Equals("更改"))
			{
				ChangeStatus();
			}
			else if (action.Equals("添加"))
			{
				AddTeacher();
			}
		}

		private void ChangeStatus()
		{
			CourseDB.ChangeCourseStatus((string)courseid);
		}
		private void LoadStatus()
		{
			CourseDB.GetCourseStatus((string)courseid,out coursename ,out coursestatus);
		}

		protected string coursestatus;

		protected string coursename;

		private void AddTeacher()
		{
			
			string teacherid =  Request["TeacherID"];
			if (teacherid==null || teacherid.Equals("")) return;

			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("CourseSystem_Add_Teacher", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter CourseID = new SqlParameter("@courseid", SqlDbType.Int);
			CourseID.Value = courseid;
			myCommand.Parameters.Add(CourseID);

			// Add Parameters to SPROC
			SqlParameter TeacherID = new SqlParameter("@teacherid", SqlDbType.NVarChar, 20);
			TeacherID.Value = teacherid;
			myCommand.Parameters.Add(TeacherID);

			// Execute the command
			myConnection.Open();

			myCommand.ExecuteNonQuery();
			myCommand.Dispose();
			myConnection.Dispose();
			
		}

		private void LoadData()
		{

			//Response.Write(courseid);

			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("CourseSystem_List_Teacher", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;


			// Add Parameters to SPROC
			SqlParameter CourseId = new SqlParameter("@courseid", SqlDbType.Int);
			CourseId.Value = courseid;
			myCommand.Parameters.Add(CourseId);


			myConnection.Open();

			SqlDataReader result = myCommand.ExecuteReader();


			TeacherList.DataSource = result;

			TeacherList.DataBind();
	
			result.Close();

			myCommand.Dispose();
			myConnection.Dispose();

		}

		private void initializeList()
		{
			SqlConnection myConnection=Utils.GetConnection();

			SqlCommand myCommand = new SqlCommand("CourseSystem_Get_TeacherList", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Execute the command
			myConnection.Open();

			SqlDataReader result =  myCommand.ExecuteReader();

			TeacherDropDownList.DataSource = result;
			TeacherDropDownList.Name = "TeacherID";

			TeacherDropDownList.TitleColumn="Name";
			TeacherDropDownList.ValueColumn="ID";

			//必须先绑定
			TeacherDropDownList.BindData();

			myCommand.Dispose();
			myConnection.Dispose();

		}

		private string getString(string val)
		{
			if ( val ==null ) return "";
			return val;
		}
		#endregion
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		设计器支持所需的方法 - 不要使用
		///		代码编辑器修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

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