📄 applysingle.aspx.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;
namespace WebApplication8.firstPage
{
/// <summary>
/// applySingle 的摘要说明。
/// </summary>
public class applySingle : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText userName;
protected System.Web.UI.HtmlControls.HtmlInputText studentNO;
protected System.Web.UI.HtmlControls.HtmlInputText teacher;
protected System.Web.UI.HtmlControls.HtmlInputText realName;
protected System.Web.UI.HtmlControls.HtmlInputText password_;
protected System.Web.UI.HtmlControls.HtmlInputText password;
protected System.Web.UI.HtmlControls.HtmlInputButton submit;
protected System.Web.UI.WebControls.Label hint;
protected System.Web.UI.WebControls.DropDownList class_;
protected System.Web.UI.HtmlControls.HtmlInputButton cancel;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Connection connection = new Connection(Application["market"].ToString());
SqlDataReader reader = connection.execute("select * from Class");
while(reader.Read())
{
class_.Items.Add(new ListItem(reader["className"].ToString(),"0"));
}
reader.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.submit.ServerClick += new System.EventHandler(this.submit_ServerClick);
this.cancel.ServerClick += new System.EventHandler(this.cancel_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void submit_ServerClick(object sender, System.EventArgs e)
{
if((userName.Value.Length == 0)||(password.Value != password_.Value)||(realName.Value.Length == 0)
||(teacher.Value.Length == 0)||(password.Value.Length == 0)||(class_.Items.Count ==0))
{
hint.Text = "填写的信息不正确,请重新填写!";
}
else
{
Connection connection = new Connection(Application["market"].ToString());
SqlDataReader reader = connection.execute("SELECT * from Single where studentNO='"+studentNO.Value+"'");
if(reader.HasRows)
{
reader.Close();
hint.Text = "对不起,学号为"+studentNO.Value+"的同学已经注册过了";
}
else
{
reader.Close();
reader = connection.execute("select * from Single where userName='"+userName.Value+"'");
if(reader.HasRows)
{
reader.Close();
hint.Text = "对不起,用户名"+userName.Value+"已经被使用,请使用其它的用户名";
}
else
{
reader.Close();
connection.execute("insert into Single values ('"+userName.Value+"','"+password.Value+"','"+realName.Value+"','"+class_.Items[class_.SelectedIndex].Text
+"','"+teacher.Value+"','"+studentNO.Value+"','10000','个人',0)");
Session["type"] = "个人";
Session["studentNO"] = studentNO.Value;
Session["userName"] = userName.Value;
Response.Write("<script language=javascript>alert('注册成功.进入首页');this.location.href='index.aspx';</script>");
}
}
}
}
private void cancel_ServerClick(object sender, System.EventArgs e)
{
Response.Redirect("../login.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -