📄 roomlive.aspx.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>
/// RoomLive 的摘要说明。
/// </summary>
public class RoomLive : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button OK;
protected System.Web.UI.WebControls.Button Clear;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Data.SqlClient.SqlConnection conn;
protected System.Data.SqlClient.SqlCommand cmd;
protected string myConn;
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.OK.Click += new System.EventHandler(this.OK_Click);
this.Clear.Click += new System.EventHandler(this.Clear_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private bool check1(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 bool check2(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 Room_ID from Room",conn);
int i=0;
conn.Open();
reader2=cmd2.ExecuteReader();
while(reader2.Read())
{
if(reader2["Room_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)
{
if(check1(this.TextBox1.Text))
{
if(check2(this.TextBox2.Text))
{
this.myConn=ConfigurationSettings.AppSettings["mySql"];
this.conn=new System.Data.SqlClient.SqlConnection(myConn);
cmdText="update Student set Room_ID='"+TextBox2.Text+"'where Student_ID='"+TextBox1.Text+"'";
conn.Open();
cmd=new System.Data.SqlClient.SqlCommand(cmdText,conn);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('入住登记成功!')</script>");
conn.Close();
this.TextBox1.Text="";
this.TextBox2.Text="";
}
else Response.Write("<script>alert('不存在的寝室编号!')</script>");
}
else Response.Write("<script>alert('不存在的学号!')</script>");
}
private void Clear_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text="";
this.TextBox2.Text="";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -