📄 adduser.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class AddUser : System.Web.UI.Page
{
//连接数据库
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["news_manageConnectionString"].ConnectionString);
string name;
string pwd;
clsAddUser clsadduser = new clsAddUser();
protected void Page_Load(object sender, EventArgs e)
{
}
//判断用户是否存在
public bool check()
{
string str = "select count(*) from t_news_user where userName='" + name + "' and userPassword= '" + pwd + "'";
conn.Open();
SqlCommand com = new SqlCommand(str, conn);
int i = Convert.ToInt32(com.ExecuteScalar());
conn.Close();
if (i > 0)
{
return false;
}
else
{
return true;
}
}
//添加按钮
protected void Button2_Click(object sender, EventArgs e)
{
name = this.txtName.Text;
pwd = this.txtPwd.Text;
int i = Convert.ToInt32(this.txtAffirm.Text);
bool bc = check();
if (bc)
{
bool b = clsadduser.insert(name, pwd, i);
if (b == true)
{
Response.Write("<script language=javascript> window.alert('恭喜你,添加成功!')</script>");
}
else
{
Response.Write("<script language=javascript> window.alert('抱歉,您添加失败!')</script>");
}
}
else
{
Response.Write("<script language=javascript> window.alert('对不起,用户名已经存在!')</script>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.txtAffirm.Text = "";
this.txtName.Text = "";
this.txtPwd.Text = "";
this.txtQueren.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -