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 admin where admin_name='{0}' and admin_pwd='{1}'", txtAccount.Text, txtPassword.Text); SqlDataReader dr = DbManger.ExceRead(strsql); if (dr.Read()) { int admin_id = Int32.Parse(dr["admin_id"].ToString()); Session.Timeout = 20; Session["admin_id"] = admin_id; Session["admin_name"] = txtAccount.Text; Session["admin_pwd"] = txtPassword.Text; Response.Write("<script>alert('" + Session["admin_name"].ToString() + "用户登录成功!')</script>"); Response.Redirect("index.aspx"); } else { Response.Write("<script>alert('用户名密码不正确!')</script>"); } dr.Close(); #endregion } else { Response.Write("<script>alert('验证码不正确')</script>"); } #endregion }
protected void Page_Load(object sender, EventArgs e) { //1.判断是否有用户 if (Session["userid"] != null && Session["userid"].ToString() != "") { if (!IsPostBack) { string strsql = string.Format("select * from member where id = '{0}'", Session["userid"].ToString()); SqlDataReader dr = DbManger.ExceRead(strsql); if (dr.Read()) { txtUser.Text = dr["LoginName"].ToString(); txtPassword.Text = dr["LoginPwd"].ToString(); if (dr["Sex"].ToString() == "男") { radlSex.SelectedIndex = 0; } else if (dr["Sex"].ToString() == "女") { radlSex.SelectedIndex = 1; } txtBirth.Text = dr["Birth"].ToString(); switch (dr["Eduation"].ToString()) { case "大专": dropEducation.SelectedIndex = 0; break; case "本科": dropEducation.SelectedIndex = 1; break; case "硕士": dropEducation.SelectedIndex = 2; break; case "博士": dropEducation.SelectedIndex = 3; break; default: dropEducation.SelectedIndex = 0; break; } txtAddress.Text = dr["Address"].ToString(); txtCall.Text = dr["Phone"].ToString(); txtEmail.Text = dr["Email"].ToString(); txtZip.Text = dr["Zip"].ToString(); Image1.ImageUrl = dr["head"].ToString(); } } } else { Response.Redirect("Login.aspx"); } }
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 member where LoginName='{0}' and LoginPwd='{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 member set LoginTimes=LoginTimes+1 where Id={0}", userid); if (DbManger.ExceSQL(sql)) { Response.Write("<script>alert('更新成功!')</script>"); //Response.Redirect("myhome/UpdatePic.aspx"); Response.Redirect("Product.aspx"); } else { Response.Write("<script>alert('不成功!')</script>"); } } else { Response.Write("<script>alert('用户名密码不正确!')</script>"); } dr.Close(); #endregion } else { Response.Write("<script>alert('验证码不正确')</script>"); } #endregion }
protected void btnReg_Click(object sender, EventArgs e) { #region //String str = "注册信息为<br/>"; //str +="用户账号:"+ txtAccount.Text +"<br/>"; //str += "出生年月:" + txtBirth.Text + "<br/>"; //str += "联系地址:" + txtAddress.Text + "<br/>"; //str += "联系电话:" + txtTel.Text + "<br/>"; //str += "电子邮箱:" + txtEmail.Text + "<br/>"; //str += "邮政编码:" +txtPostCode.Text + "<br/>"; //str += "性别:" + rdolSex.SelectedValue + "<br/>"; //str += "学历:" + ddlEdu.SelectedValue+ "<br/>"; //String strAttention = "你关注的类型为:"; //for (int i = 0; i < chlAttention.Items.Count;i++ ) //{ // if(chlAttention.Items[i].Selected) // { // strAttention += chlAttention.Items[i].Text + ""; // } //} //str += strAttention; ////Response.Write(str); //Response.Write("<script>alert('"+str+"')</script>"); #endregion #region 检测同名用户 /** * //创建连接对象 * SqlConnection con = new SqlConnection(); * con.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; * con.Open(); * * //创建命令对象 * SqlCommand com = new SqlCommand(); * com.Connection = con; * com.CommandText = string.Format("select * from member where LoginName = '{0}'", txtAccount.Text); * * //执行命令对象,返回数据阅读器 * SqlDataReader dr = com.ExecuteReader(); * if (dr.HasRows) * { * Response.Write("<script>alert('该用户已存在!')</script>"); * } * * else * { #region 数据库连接数据库 * string username = txtAccount.Text; * string pwd = txtPassword.Text; * string sex = rdolSex.SelectedItem.ToString(); * string birth = txtBirth.Text; * string educate = ddlEdu.SelectedItem.ToString(); * string address = txtAddress.Text; * string tel = txtTel.Text; * string zip = txtPostCode.Text; * string email = txtEmail.Text; * string regdate = DateTime.Now.ToShortDateString(); * string strSql = string.Format("insert into member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, sex, birth,educate,tel,address,zip,email,regdate); * //创建连接对象 * SqlConnection cn = new SqlConnection(); * cn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; * cn.Open(); * * //创建命令对象 * SqlCommand cm = new SqlCommand(); * cm.Connection = cn; * cm.CommandText = strSql; * * //执行命令对象,返回数据阅读器 * if (cm.ExecuteNonQuery() > 0) * { * Response.Write("<script>alert('注册成功')</script>"); * } #endregion * } #endregion #region dataset对象,断开式连接 * //创建连接对象 * SqlConnection conn = new SqlConnection(); * conn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; * conn.Open(); * * //创建命令对象 * SqlCommand comm = new SqlCommand(); * comm.Connection = conn; * comm.CommandText = string.Format("select * from member where LoginName = '{0}'", txtAccount.Text); * * DataSet ds= new DataSet(); * SqlDataAdapter da = new SqlDataAdapter(); * da.SelectCommand = comm; * da.Fill(ds,"member"); * if (ds.Tables["member"].Rows.Count > 0) * { * Response.Write("<script>alert('该用户已存在!')</script>"); * } * else * { #region 数据库连接数据库 * string username = txtAccount.Text; * string pwd = txtPassword.Text; * string sex = rdolSex.SelectedItem.ToString(); * string birth = txtBirth.Text; * string educate = ddlEdu.SelectedItem.ToString(); * string address = txtAddress.Text; * string tel = txtTel.Text; * string zip = txtPostCode.Text; * string email = txtEmail.Text; * string regdate = DateTime.Now.ToShortDateString(); * string strSql = string.Format("insert into member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, sex, birth, educate, tel, address, zip, email, regdate); * //创建连接对象 * SqlConnection cn = new SqlConnection(); * cn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; * cn.Open(); * * //创建命令对象 * SqlCommand cm = new SqlCommand(); * cm.Connection = cn; * cm.CommandText = strSql; * * //执行命令对象,返回数据阅读器 * if (cm.ExecuteNonQuery() > 0) * { * Response.Write("<script>alert('注册成功')</script>"); * } #endregion * }**/ #endregion #region 数据操作类 string strsql = string.Format("select * from member where LoginName = '{0}'", 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 sex = rdolSex.SelectedItem.ToString(); string birth = txtBirth.Text; //string educate = ddlEdu.SelectedItem.ToString(); 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 member values (0,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','',0,'')", username, pwd, birth, tel, address, zip, email, regdate); //执行命令对象,返回数据阅读器 if (DbManger.ExceSQL(strsql)) { Response.Write("<script>alert('注册成功')</script>"); } #endregion } #endregion }