//通过登录名查询所有 public UserInfoTB GetSelectUserByLoginid(string UserName) { string sql = "select * from UserInfoTB where LoginId=@UserName"; UserInfoTB userinfo = new UserInfoTB(); try { DataTable dt = DBHelper.GetTable(sql, new SqlParameter("@UserName", UserName)); if (dt.Rows.Count == 0) { return(null); } else { foreach (DataRow row in dt.Rows) { userinfo.UID = (int)row["UID"]; userinfo.LoginId = (string)row["LoginID"]; userinfo.Password = (string)row["Password"]; userinfo.Telephone = (string)row["Telephone"]; userinfo.Email = (string)row["Email"]; userinfo.Question = (string)row["Question"]; userinfo.AKey = (string)row["aKey"]; userinfo.Remark = (row["Remark"] == DBNull.Value) ? "" : row[5].ToString(); } return(userinfo); } } catch (Exception e) { throw e; } }
protected void imgbtnadd_Click(object sender, ImageClickEventArgs e) { string loginID = txtUserName.Text.Trim(); int cnt = userinfo.IsHasUserName(loginID); if (cnt > 0) { lblMes.Text = "该用户名已被注册!"; } else { UserInfoTB u = new UserInfoTB(); u.LoginId = txtUserName.Text.Trim(); u.Password = txtPwd.Text.Trim(); u.Telephone = txtTel.Text.Trim(); u.Email = txtEmail.Text.Trim(); u.Question = txtQuestion.Text.Trim(); u.AKey = txtKey.Text.Trim(); u.Remark = txtRemark.Text.Trim(); int count = userinfo.InsertUserInfo(u); if (count > 0) { //Response.Redirect("~/Login.aspx"); Response.Write("<script>if (confirm ('注册成功!')=true) location.href='~/Login.aspx'</script>"); } else { Response.Write("<script>alert('注册失败!')</script>"); return; } } }
protected void imgbtnsave_Click(object sender, ImageClickEventArgs e) { if (Page.IsValid)//判断验证是否通过 { string loginid = lblid.Text; string pwd = txtpwd.Text; string tel = txttel.Text; string email = txtEmail.Text; string question = txtmq.Text; string akey = txtmw.Text; string remark = txtremark.Text; UserInfoTB us = new UserInfoTB(); us.LoginId = loginid; us.Password = pwd; us.Telephone = tel; us.Email = email; us.Question = question; us.AKey = akey; us.Remark = remark; int con = userinfomanager.UpdateUserInfoTB(us);//修改 if (con == 1) { lblMes.Text = "修改成功!"; txtpwd.Text = ""; txttel.Text = ""; txtEmail.Text = ""; txtmq.Text = ""; txtmw.Text = ""; txtremark.Text = ""; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Usermanager"] == null) { Response.Redirect("~/Login.aspx"); } else { if (!IsPostBack) { um = Session["UserManager"] as UserInfoTB; lblName.Text = um.LoginId; } } }
//添加用户 public int InsertUserInfo(UserInfoTB u) { string strsql = "insert into UserInfoTB(loginid,password,telephone,email,question,akey,remark) values(@loginid,@password,@telephone,@email,@question,@akey,@remark)"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@loginid", u.LoginId), new SqlParameter("@password", u.Password), new SqlParameter("@telephone", u.Telephone), new SqlParameter("@email", u.Email), new SqlParameter("@question", u.Question), new SqlParameter("@akey", u.AKey), new SqlParameter("@remark", u.Remark), }; return(DBHelper.ExecuteCommand(strsql, paras)); }
protected void bntNext_Click(object sender, EventArgs e) { string userId = txtUser.Text.Trim(); UserInfoTB user = userInfo.GetUserInfoByUserId(userId); if (user == null) { lblMessage.Text = "请输入正确的账号!"; } else { lblQuestion.Visible = true; lblValidate.Visible = true; lblKey.Visible = true; txtKey.Visible = true; BtnNext1.Visible = true; btnNext.Visible = false; lblMessage.Text = ""; lblValidate.Text = user.Question; } }
public bool Register(string userName, string Pwd, out UserInfoTB UserInfo) { //查询用户名是否存在 UserInfoTB user = userInfo.GetSelectUserByLoginid(userName); if (user == null) { UserInfo = null; return(false); } if (Pwd == user.Password) { UserInfo = user; return(true); } else { UserInfo = null; return(false); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Usermanager"] == null) { Response.Redirect("~/Login.aspx"); } else { if (!IsPostBack) { UserInfoTB user = Session["UserManager"] as UserInfoTB; lblid.Text = user.LoginId.ToString(); txtpwd.Text = user.Password.ToString(); txttel.Text = user.Telephone.ToString(); txtEmail.Text = user.Email.ToString(); txtmq.Text = user.Question.ToString(); txtmw.Text = user.AKey.ToString(); txtremark.Text = user.Remark.ToString(); } } }
//客户表 private static List <UserInfoTB> GetUserInfoTBBySql(string strsql) { List <UserInfoTB> list = new List <UserInfoTB>(); DataTable table = DBHelper.GetTable(strsql); foreach (DataRow row in table.Rows) { UserInfoTB us = new UserInfoTB(); us.UID = Convert.ToInt32(row["uid"]); us.LoginId = row["loginid"].ToString(); us.Password = row["password"].ToString(); us.Telephone = row["telephone"].ToString(); us.Email = row["email"].ToString(); us.Question = row["question"].ToString(); us.AKey = row["akey"].ToString(); us.Remark = row["remark"].ToString(); list.Add(us); } return(list); }
protected void BtnNext1_Click(object sender, EventArgs e) { string Key = txtKey.Text.Trim(); string userId = txtUser.Text.Trim(); UserInfoTB user = userInfo.GetUserInfoByUserId(userId); if (Key == user.AKey) { lblPwd.Visible = true; lblPwd1.Visible = true; txtPassword.Visible = true; txtPassword1.Visible = true; btnUpdate.Visible = true; BtnNext1.Visible = false; btnBack.Visible = true; lblMessage.Text = ""; } else { lblMessage.Text = "输入的答案不正确!"; } }
//修改 public int UpdateUserInfoTB(UserInfoTB us) { string sql = string.Format("Update UserInfoTB set Password=@Password,Telephone=@Telephone,Email=@Email,Question=@Question,aKey=@aKey,Remark=@Remark where LoginId=@LoginId"); try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@LoginId", us.LoginId), new SqlParameter("@Password", us.Password), new SqlParameter("@Telephone", us.Telephone), new SqlParameter("@Email", us.Email), new SqlParameter("@Question", us.Question), new SqlParameter("@aKey", us.AKey), new SqlParameter("@Remark", us.Remark), }; return(DBHelper.ExecuteCommand(sql, para)); } catch (Exception e) { Console.Write(e.Message); throw e; } }
//修改 public int UpdateUserInfoTB(UserInfoTB us) { return(userInfo.UpdateUserInfoTB(us)); }
public int InsertUserInfo(UserInfoTB u) { return(userInfo.InsertUserInfo(u)); }
//通过账号获取所有 public UserInfoTB GetUserInfoByUserId(string userid) { UserInfoTB user = userInfo.GetSelectUserByLoginid(userid); return(user); }