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

📄 tec.aspx.cs

📁 这是暑假做的一个选课系统,可以供学习ASP的朋友借鉴
💻 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 class_kinghome
{
	/// <summary>
	/// stuinfo 的摘要说明。
	/// </summary>
	public class tec : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox pas;
		protected System.Web.UI.WebControls.Label info;
		protected System.Web.UI.WebControls.Button find;
		protected System.Web.UI.WebControls.Button add;
		protected System.Web.UI.WebControls.Button del;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.TextBox manager;
		protected System.Web.UI.WebControls.Button enter;
		protected System.Web.UI.WebControls.TextBox dept;
		protected System.Web.UI.WebControls.TextBox stuname;
		protected System.Web.UI.WebControls.TextBox stuno;
		protected System.Web.UI.WebControls.TextBox stusex;
		public string getdept;
		public string getstuname;
		public string getstusex;
		public string getstuno;
		protected System.Web.UI.WebControls.Label change;
		protected System.Web.UI.WebControls.Button condel;

	
		private void Page_Load(object sender, System.EventArgs e)
		{
				Session.Timeout=30; 
			getdept=dept.Text;
			getstuname=stuname.Text ;
			getstusex=stusex.Text;
			
			getstuno=stuno.Text;
			DataGrid1.PagerStyle.Visible=true;
			
		}
		public void manaenter(object sender, System.EventArgs e)
		{
			if (manager.Text==ConfigurationSettings.AppSettings["managername"]&&pas.Text==ConfigurationSettings.AppSettings["password"])
			{
				Session["ifenter"]="hasenter";
				info.Text="欢迎管理员登陆!";
			}
			else
				info.Text="请确认输入!";
		}
		public void find_Click(object sender, System.EventArgs e)
		{
				SqlConnection Con = new SqlConnection("Data Source=HSJ;Initial Catalog=class;User ID=sa;Pwd=hsj;");  
			string sel;
				
			SqlDataAdapter Cmd ;
				
			sel="select * from tea WHERE "+checkstr(getdept,"tdept")+checkstr(getstuname,"tname")+checkstr(getstusex,"tpost")+checkstr(getstuno,"tno");
			if(sel.EndsWith("and")==true)
				sel=sel.Remove(sel.Length-3,3);  
					
			Cmd=new SqlDataAdapter(sel,Con);
			DataSet ds=new DataSet();
			Cmd.Fill(ds,"stu");
			DataGrid1.DataSource=ds.Tables["stu"].DefaultView;
			DataGrid1.DataBind();
				
		}
		public void addstu(object sender, System.EventArgs e)
		{
				try
		 {
			 if (Session["ifenter"]=="hasenter")
			 {
				 if ((getdept=="")||(getstuname=="")||(getstuno==""))
			 
					 change.Text="必须项没有填写!";
				 else 
				 
				 {
					 change.Text="正在操作";
					 SqlConnection Con = new SqlConnection("Data Source=HSJ;Initial Catalog=class;User ID=sa;Pwd=hsj;");
					 string sql = "insert into tea (tno,tname,tdept,tpost) values ('" + getstuno + "','"+getstuname + "','" + getdept + "','" +getstusex  +"')";
					 SqlCommand addCommand =new SqlCommand(sql,Con);
					 addCommand.Connection.Open();
					 addCommand.ExecuteNonQuery();
					 addCommand.Connection.Close();
					 change.Text="操作成功";
					 stuno.Text="";
					 stuname.Text="";
					 stusex.Text="";
					 dept.Text="";
				 }
			 }
			 else
				 change.Text="你还没登陆!";
		 }
			catch
				{change.Text="处理数据时出错";}
		}
		public void delstu(object sender, System.EventArgs e)
		{
			string delsql;
			if (Session["ifenter"]=="hasenter")
			{
				SqlConnection Con = new SqlConnection("Data Source=HSJ;Initial Catalog=class;User ID=sa;Pwd=hsj;");
				delsql  = "DELETE FROM tea WHERE "+checkstr(getdept,"tdept")+checkstr(getstuname,"tname")+checkstr(getstusex,"tpost")+checkstr(getstuno,"tno");
				if(delsql.EndsWith("and")==true)
					delsql=delsql.Remove(delsql.Length-3,3);  
				SqlCommand delCommand =new SqlCommand(delsql,Con);
				delCommand.Connection.Open();
				delCommand.ExecuteNonQuery();
				delCommand.Connection.Close();
				change.Text="操作成功";
				condel.Visible=false;
			}
			else
				change.Text="你还没登陆!";
		}
		public string checkstr(string a,string b)
		{
				if (a!="")
			 a=" "+b+"='"+a+"' and";
			return a;
		}
		public void showdel(object sender, System.EventArgs e)
		{
				find_Click(sender,e);
			condel.Visible=true;
			change.Text="将要删除以下记录!";
		}
				#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.find.Click += new System.EventHandler(this.find_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

	
	}
}

⌨️ 快捷键说明

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