protected void btnReg_Click(object sender, EventArgs e) { #region 数据操作类 string strsql = string.Format("select * from [dbo].[user] where userName = '******'", txtAccount.Text); SqlDataReader myread = DbManger.ExceRead(strsql); if (myread.Read()) { Response.Write("<script>alert('该用户已存在!')</script>"); } else { #region 数据库连接数据库 string username = txtAccount.Text; string pwd = txtPassword.Text; string address = txtAddress.Text; string tel = txtTel.Text; string zip = txtPostCode.Text; string email = txtEmail.Text; string regDate = DateTime.Now.ToShortDateString(); strsql = string.Format("insert into [dbo].[user] values ('{0}' ,'{1}','{2}' ,'{3}' ,'{4}' ,'{5}','','{6}')", username, pwd, tel, email, address, zip, regDate); //执行命令对象,返回数据阅读器 if (DbManger.ExceSQL(strsql)) { RegisterClientScriptBlock("01", "<script>alert('注册成功')</script>"); //Response.Write("<script>alert('注册成功')</script>"); Response.Redirect("Login.aspx"); } #endregion } #endregion }
protected void btnLogin_Click(object sender, EventArgs e) { #region 用户登录处理 string check = Request.Cookies["checkcode"].Value.ToString(); if (check == txtCheckcode.Text) { #region 使用数据访问类来完成登陆 string strsql = string.Format("select * FROM [dbo].[user] where userName='******' and userPwd='{1}'", txtAccount.Text, txtPassword.Text); SqlDataReader dr = DbManger.ExceRead(strsql);; if (dr.Read()) { int userid = Int32.Parse(dr["id"].ToString()); Session.Timeout = 20; Session["userid"] = userid; Session["username"] = txtAccount.Text; Response.Write("<script>alert('" + Session["username"].ToString() + "用户登录成功!')</script>"); string sql = string.Format("update [dbo].[user] set LoginTimes=LoginTimes+1 where id={0}", userid); if (DbManger.ExceSQL(sql)) { Response.Write("<script>alert('更新成功!')</script>"); //Response.Redirect("myhome/UpdatePic.aspx"); Response.Redirect("index.aspx"); } else { Response.Write("<script>alert('不成功!')</script>"); } } else { Response.Write("<script>alert('用户名密码不正确!')</script>"); } dr.Close(); #endregion } else { Response.Write("<script>alert('验证码不正确')</script>"); } #endregion }