protected void Register_Click(object sender, EventArgs e) { { if (TextBox_emailreg.Text == "") { Response.Write("<script>window.alert('没有输入邮箱');</script>"); return; } else if (TextBox_name.Text == "") { Response.Write("<script>window.alert('没有输入用户名');</script>"); return; } else if (TextBox_password.Text == "") { Response.Write("<script>window.alert('没有输入密码');</script>"); return; } SqlConnection conn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=yijia;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT *FROM user_info where email = '"+ TextBox_emailreg.Text.Trim() +"'", conn); SqlDataReader sdr = cmd.ExecuteReader(); sdr.Read(); int x = 0; if (sdr.HasRows) { Response.Write("<script>window.alert('邮箱已经存在,不可以重复注册');</script>"); return; } else if (TextBox_yanzhengma.Text != (String)Session["yanzheng"]) { Label1.ForeColor = System.Drawing.Color.Red; Label1.Text = "验证码不正确,请检查你的邮件"; return; } else if (x == 0) { sdr.Close(); string time = DateTime.Now.ToString(); String MD5 = public_function.Md5Hash(TextBox_password.Text); cmd.CommandText = "insert into user_info (email,name,password,time) values ('" + TextBox_emailreg.Text + "','" + TextBox_name.Text + "','" + MD5 + "','" + time + "')"; string rows_effedted = cmd.ExecuteNonQuery().ToString(); conn
时间: 2024-02-14 08:14:15 浏览: 28
这段代码是一个C#的后端代码,用来实现用户注册功能。首先会检查用户是否输入了邮箱、用户名和密码,如果没有则提示用户输入。然后会连接到数据库,查询该邮箱是否已经被注册过,如果是则提示用户邮箱已经存在不能重复注册。接着会检查用户输入的验证码是否正确,如果不正确则提示用户验证码不正确。最后会将用户的邮箱、用户名、密码和注册时间插入到数据库中。
相关问题
protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton8_Click(object sender, EventArgs e) { Response.Redirect("MMPwd.aspx"); } protected void LinkButton1_Click(object sender, EventArgs e) { Response.Redirect("ModifyMyInfo.aspx"); } protected void LinkButton9_Click1(object sender, EventArgs e) { Response.Redirect("MyOrder.aspx"); } protected void LinkButton2_Click(object sender, EventArgs e) { Response.Redirect("MyComment.aspx"); }
这是一个 C# 代码片段,包含了几个事件处理方法。其中, "Page_Load" 方法是页面加载时的事件处理程序,这里没有具体的实现代码。其他三个方法是响应页面上 LinkButton 控件的点击事件,分别是 "LinkButton8_Click"、"LinkButton1_Click" 和 "LinkButton9_Click1" 方法,它们的作用是将用户重定向到其他页面,分别是修改密码页面、修改个人信息页面和我的订单页面。还有一个 "LinkButton2_Click" 方法,用于重定向到我的评论页面。
protected void Page_Load(object sender, EventArgs e) { Label1 .Text =__________["TextBox1"]; int time = DateTime.Now.__________.CompareTo(13); string str; if (time > 0) str = "下午好!"; else if (time < 0) str = "上午好!"; else str = "中午好!"; Label2.Text =__________ ; }
在下划线处应该填写的代码是:
- TextBox1.Text:获取文本框 TextBox1 中的文本。
- TimeOfDay:获取当前时间的时间部分。
所以可以填写如下代码:
```
Label1.Text = TextBox1.Text;
int time = DateTime.Now.TimeOfDay.CompareTo(new TimeSpan(13, 0, 0));
string str;
if (time > 0) str = "下午好!";
else if (time < 0) str = "上午好!";
else str = "中午好!";
Label2.Text = str;
```
解释一下代码的作用:
- 第一行,将文本框 TextBox1 中的文本赋值给标签 Label1 的 Text 属性。
- 第二行,获取当前时间的时间部分,并与下午 1 点比较。如果当前时间晚于下午 1 点,返回正数;如果早于下午 1 点,返回负数;如果等于下午 1 点,返回 0。
- 第三行,定义一个字符串变量 str,用于保存问候语。
- 第四行,根据比较结果判断当前是上午、下午还是中午,并将问候语赋值给 str 变量。
- 第五行,将 str 变量的值赋值给标签 Label2 的 Text 属性,显示问候语。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)