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

📄 studentreward.aspx.cs

📁 学生公寓管理系统使用说明: 1.服务器运行环境 SQL 2000 .NET FRAMEWORK 1.1 .NET FRAMEWORK 1.1 CHINESE (SIMPL
💻 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.Configuration;
namespace Manage
{
	/// <summary>
	/// StudentReward 的摘要说明。
	/// </summary>
	public class StudentReward : System.Web.UI.Page
	{
		protected System.Data.SqlClient.SqlConnection conn;
		protected System.Data.SqlClient.SqlCommand cmd;
		protected System.Data.SqlClient.SqlDataReader reader;
		protected string myConn;
		protected System.Web.UI.WebControls.Button Clear;
		protected System.Web.UI.WebControls.Button Ok;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Button See;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected string cmdText;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面

		}

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

		}
		#endregion

		
		private bool Empty()
		{
			System.Data.SqlClient.SqlCommand cmd2;
			System.Data.SqlClient.SqlDataReader reader2;
			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			cmd2=new System.Data.SqlClient.SqlCommand("select * from Reword where Student_ID='"+TextBox1.Text.ToString()+"'",conn);
			conn.Open();
			int i=0;
			reader2=cmd2.ExecuteReader();
			if(check(this.TextBox1.Text))
			{
				while(reader2.Read())
				{
					if(reader2["Student_ID"].ToString()==this.TextBox1.Text.ToString())
					{
						i=1;
						break;
					}
				}
			}

			conn.Close();
			if(i==1) return false;
			else return true;
		}

		private bool check(string ID)
		{
			System.Data.SqlClient.SqlCommand cmd2;
			System.Data.SqlClient.SqlDataReader reader2;
			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			cmd2=new System.Data.SqlClient.SqlCommand("select Student_ID from Student",conn);
			int i=0;
			conn.Open();
			reader2=cmd2.ExecuteReader();
			while(reader2.Read())
			{
				if(reader2["Student_ID"].ToString()==ID)

						i=1;
			}
			reader2.Close();
			conn.Close();
				if(i==1) return true;
				else  return false;
			
		}

		private void Ok_Click(object sender, System.EventArgs e)
		{
			
			DateTime now=new DateTime();
			System.Data.SqlClient.SqlDataReader reader4;
			now=System.DateTime.Now;
			System.Data.SqlClient.SqlCommand cmd3;
			System.Data.SqlClient.SqlCommand cmd4;
			string  time=now.Date.Year.ToString()+"-"+now.Date.Month.ToString()+"-"+now.Date.Day.ToString();
			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			try
			{
				if(check(this.TextBox1.Text))
			{
				if(Empty())
				{	
					conn.Open();
					cmd3=new System.Data.SqlClient.SqlCommand("insert into Reword (Student_ID,Reword_Info,Reword_Date) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+time+"')",conn);
					cmd3.ExecuteNonQuery();
					Response.Write("<script>alert('添加奖惩信息成功!')</script>");
				}
				else if(!Empty())
				{
					conn.Open();
					Response.Write("<script>alert('已存在记录的学号,更改请编辑后确认!')</script>");
					cmd4=new System.Data.SqlClient.SqlCommand("select * from Reword where Student_ID='"+TextBox1.Text+"'",conn);
					reader4=cmd4.ExecuteReader();
					if(reader4.Read())
						TextBox2.Text=reader4["Reword_Info"].ToString();
					this.Ok.Visible=false;
					this.Button1.Visible=true;
					this.TextBox1.ReadOnly=true;
				}
			}
			else
			{
				Response.Write("<script>alert('不存在该学号!')</script>");
								
			}
			conn.Close();
		}
		catch(Exception ex)
			{	
				
				 Response.Write("<script>alert('"+ex.Message+"')</script>");
			
			}
			
			
		}

		private void Clear_Click(object sender, System.EventArgs e)
		{
			this.TextBox1.Text="";
			this.TextBox2.Text="";
		}

		private void See_Click(object sender, System.EventArgs e)
		{
			    System.Data.SqlClient.SqlCommand cmd2;
				System.Data.SqlClient.SqlDataReader reader2;
				this.myConn=ConfigurationSettings.AppSettings["mySql"];
				this.conn=new System.Data.SqlClient.SqlConnection(myConn);
				conn.Open();
			    cmd2=new System.Data.SqlClient.SqlCommand("select * from Reword",conn);
				reader2=cmd2.ExecuteReader();
				if(check(this.TextBox1.Text))
				{
					while(reader2.Read())
					{
						if(reader2["Student_ID"].ToString()==this.TextBox1.Text.ToString())
						{
							this.TextBox2.Text=reader2["Reword_Info"].ToString();
							this.Ok.Visible=false;
							this.Button1.Visible=true;
							break;
						}
						else 
						{
							this.TextBox2.Text="该记录为空";
							this.Ok.Visible=true;
							this.Button1.Visible=false;
						}
					}
				}
				else 			
				{
					Response.Write("<script>alert('不存在该学号!')</script>");
					this.TextBox2.Text="";
				
				}
				conn.Close();
			
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			this.myConn=ConfigurationSettings.AppSettings["mySql"];
			this.conn=new System.Data.SqlClient.SqlConnection(myConn);
			System.Data.SqlClient.SqlCommand cmd5;
			conn.Open();
			cmd5=new System.Data.SqlClient.SqlCommand("update Reword set Reword_Info='"+TextBox2.Text.ToString()+"' where Student_ID='"+TextBox1.Text+"'",conn);
			cmd5.ExecuteNonQuery();
			conn.Close();
			Response.Write("<script>alert('修改奖惩信息成功!')</script>");
			this.Ok.Visible=true;
			this.Button1.Visible=false;
			this.TextBox1.ReadOnly=false;
		
			
		}

		


	}
}

⌨️ 快捷键说明

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