📄 add.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.Data.SqlClient;
namespace gllbysj
{
/// <summary>
/// add 的摘要说明。
/// </summary>
public class add : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.LinkButton lbt1;
protected System.Web.UI.WebControls.LinkButton lbt2;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label Label5;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//this..Attributes.Add("onclick","window.close()");//
}
public bool isname()
{
SqlConnection cn=db.createcon();
string sql="select * from user1 where name='"+this.TextBox1.Text+"'";
cn.Open();
SqlCommand cm=new SqlCommand(sql,cn);
SqlDataReader da=cm.ExecuteReader();
if(da.Read())
{
return false;
cn.Close();
}
else
{
return true;
cn.Close();
}
//cn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lbt1.Click += new System.EventHandler(this.lbt1_Click);
this.lbt2.Click += new System.EventHandler(this.lbt2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
//this.btnClose.Attributes.Add("onclick","window.close()");//
// window.close();
}
private void lbt2_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text="";
this.TextBox2.Text="";
this.TextBox3.Text="";
this.TextBox4.Text="";
}
private void lbt1_Click(object sender, System.EventArgs e)
{
if(this.Page.IsValid)
{
if(this.isname())
{
SqlConnection con=db.createcon();
con.Open();
string str="insert into user1(name,password,mail) values('"+this.TextBox1.Text+"','"+this.TextBox2.Text+"','"+this.TextBox4.Text+"')";
SqlCommand cmm=new SqlCommand(str,con);
cmm.ExecuteNonQuery();
con.Close();
Response.Write("<script language=javascript>alert('注册成功!')</script>");
Response.Write("<script language=javascript>window.close()</script>");
}
else
{
Response.Write("<script language=javascript>alert('该用户名已注册过')</script>");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -