/// <summary> /// 修改密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEditPwd_Click(object sender, EventArgs e) { string oriPwd = this.txtOriPwD.Text.Trim(); string newPwd = txtNewPwd.Text; string newrepPwd = txtRepPwd.Text; YC_User u = new YC_User(); u.Name = Session["UName"].ToString(); u.Password = oriPwd; if (BLL.UserBLL.AuthPwd(u) == 0) { ClientScript.RegisterClientScriptBlock(this.GetType(), "authfailure", "<script>alert(\"原始密码错误!\")</script>"); } else if (newPwd == "" || newrepPwd == "") { ClientScript.RegisterClientScriptBlock(this.GetType(), "authfailure", "<script>alert(\"密码不能为空!\")</script>"); } else if (newPwd != newrepPwd) { ClientScript.RegisterClientScriptBlock(this.GetType(), "authfailure", "<script>alert(\"两次输入不一致!\")</script>"); } else { u.Password = newPwd; if (BLL.UserBLL.updatePwd(u) == 1) { ClientScript.RegisterClientScriptBlock(this.GetType(), "authfailure", "<script>alert(\"密码修改成功!\");location.href=\"index.aspx\"</script>"); Session["UName"] = null; } } }
/// <summary> /// 登录 /// </summary> /// <param name="user"></param> /// <returns></returns> public static int Login(YC_User user) { //根据用户名获取id user.Uid = Convert.ToInt32(DAL.UserServer.selectIDbyName(user.Name)); int isAdmin = Convert.ToInt32(DAL.UserServer.isAdmin(user.Uid)); if (isAdmin == 0) { return(0); } int loginre = Convert.ToInt32(DAL.UserServer.login(user)); return(loginre); }
/// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { YC_User u = new YC_User(); u.Sex = this.ddlsex.SelectedIndex; u.Nickname = labNick.Text; u.Qq = labQQ.Text; u.Phone = labPhone.Text; u.Uid = BLL.UserBLL.selectIDByName(Session["UName"].ToString()); if (BLL.UserBLL.UpdateaUInfo(u) == 1) { ClientScript.RegisterClientScriptBlock(this.GetType(), "usucc", "<script>alert(\"修改资料成功!\")</script>"); } }
public void UserisExists() { string name = Request.QueryString["Name"].ToString(); YC_User u = new YC_User(); u.Name = name; if (BLL.UserBLL.isExists(u) == 1) { Response.Write("1");//存在 } else { Response.Write("0"); } }
public void Login() { string name = Request.Form["Name"]; string pwd = Request.Form["Pwd"]; YC_User u = new YC_User(); u.Name = name; u.Password = pwd; if (BLL.UserBLL.login(u) == 1) { Session["UName"] = name;//登录成功写入Session Response.Write("1"); } else { Response.Write("0"); } }
public void RegUser() { string name = Request.Form["Name"]; string pwd = Request.Form["Pwd"]; YC_User u = new YC_User(); u.Name = name; u.Nickname = name; u.Password = pwd; u.Address = "四川"; u.Sex = 0; u.Phone = "18381506390"; u.Qq = "1031893464"; int i = BLL.UserBLL.regUser(u); Response.Write(i); }
/// <summary> /// 行数据绑定时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (this.GridView1.EditIndex == e.Row.RowIndex) { ///设置性别 DropDownList ddlsex = e.Row.FindControl("ddlsex") as DropDownList; if (ddlsex != null) { //男:1 女:0 Label labUid = e.Row.FindControl("labUid") as Label; YC_User user = AdminUserManagerBLL.selectOneByUID(Convert.ToInt32(labUid.Text)); ddlsex.SelectedIndex = user.Sex; } ///设置是否启用 /* * <asp:TemplateField > * <HeaderTemplate > * 启用 * </HeaderTemplate> * <ItemTemplate> * <asp:Label ID="labEnable" runat="server" Text='<%#Eval("Enable") %>'></asp:Label> * </ItemTemplate> * <EditItemTemplate> * <asp:DropDownList runat="server" ID="ddlenable" > * <asp:ListItem Text="是" Value="1"></asp:ListItem> * <asp:ListItem Text="否" Value="0"></asp:ListItem> * </asp:DropDownList> * </EditItemTemplate> * <FooterTemplate> * * </FooterTemplate> * </asp:TemplateField> * DropDownList ddlenable = e.Row.FindControl("ddlenable") as DropDownList; * if (ddlsex != null) * { * //男:1 女:0 * Label labUid = e.Row.FindControl("labUid") as Label; * YC_User user = AdminUserManagerBLL.selectOneByUID(Convert.ToInt32(labUid.Text)); * ddlsex.SelectedIndex = user.Enable; * } */ } }
//查询一个用户的信息 public static YC_User selectOneByUID(int UID) { DataTable table = DAL.UserServer.selectOneByuid(UID).Tables[0]; YC_User user = new YC_User(); user.Uid = UID; user.Name = table.Rows[0][1].ToString(); user.Nickname = table.Rows[0][2].ToString(); user.Password = table.Rows[0][3].ToString(); user.Address = table.Rows[0][4].ToString(); user.Sex = Convert.ToInt32(table.Rows[0][5]); user.Admin = Convert.ToInt32(table.Rows[0][6]); user.Phone = table.Rows[0][7].ToString(); user.Qq = table.Rows[0][8].ToString(); user.Enable = Convert.ToInt32(table.Rows[0][9]); user.Headimg = table.Rows[0][10].ToString(); user.Money = Convert.ToDouble(table.Rows[0][11]); return(user); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["UName"] == null) { Response.Redirect("index.aspx"); return; } string uname = Session["UName"].ToString(); int uid = BLL.UserBLL.selectIDByName(uname); YC_User user = BLL.UserBLL.SelectUInfo(uid); labName.Text = user.Name; labNick.Text = user.Nickname; labPhone.Text = user.Phone; labQQ.Text = user.Qq; ddlsex.SelectedIndex = user.Sex; } }
protected void btnLogin_Click(object sender, EventArgs e) { YC_User user = new YC_User(); user.Name = txtUname.Text.Trim(); user.Password = txtPwd.Text.Trim(); int re = AdminLoginBLL.Login(user); if (re == 1) { //存入session Session["adminuser"] = user.Name; Response.Redirect("Panel.aspx"); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "loginfail", "<script>loginfail();</script>"); } }
//点击更新时 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { YC_User user = new YC_User(); user.Uid = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].FindControl("labUid") as Label).Text); // user.Name= (this.GridView1.Rows[e.RowIndex].FindControl("labName") as Label).Text; user.Nickname = (this.GridView1.Rows[e.RowIndex].FindControl("txtNick") as TextBox).Text; user.Sex = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].FindControl("ddlsex") as DropDownList).SelectedValue); user.Address = (this.GridView1.Rows[e.RowIndex].FindControl("txtAddress") as TextBox).Text; user.Phone = (this.GridView1.Rows[e.RowIndex].FindControl("txtPhone") as TextBox).Text; user.Qq = (this.GridView1.Rows[e.RowIndex].FindControl("txtQQ") as TextBox).Text; // user.Enable = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].FindControl("ddlenable") as DropDownList).SelectedValue); // user.Headimg= (this.GridView1.Rows[e.RowIndex].FindControl("imghead") as Image).ImageUrl; if (BLL.AdminUserManagerBLL.UpdateUser(user) == 1) { ClientScript.RegisterClientScriptBlock(this.GetType(), "updateSucc", "<script>updateSucc();</script>"); this.GridView1.EditIndex = -1; bind(); } }
/// <summary> /// 通过uid查询用户资料 /// </summary> /// <param name="uid"></param> /// <returns></returns> public static YC_User SelectUInfo(int uid) { DataTable dt = DAL.UserServer.selectOneByuid(uid).Tables[0]; DataRow dr = dt.Rows[0]; YC_User u = new YC_User(); u.Uid = Convert.ToInt32(dr["UID"]); u.Name = dr["Name"].ToString(); u.Nickname = dr["NickName"].ToString(); u.Password = dr["PassWord"].ToString(); u.Address = dr["Address"].ToString(); u.Sex = Convert.ToInt32(dr["Sex"]); u.Admin = Convert.ToInt32(dr["Admin"]); u.Phone = dr["Phone"].ToString(); u.Qq = dr["QQ"].ToString(); u.Enable = Convert.ToInt32(dr["Enable"]); u.Headimg = dr["headImg"].ToString(); u.Money = Convert.ToDouble(dr["Moneysum"]); u.RegDateTime = dr["RegDateTime"].ToString(); return(u); }
/// <summary> /// 删除用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public static object delete(YC_User user) { sqltext = "delete from [dbo].[YC_User] where UID='" + user.Uid + "'"; return(SQLHELPER.ExecuteNonQuery(sqltext)); }
/// <summary> /// 后台管理中,管理员只能更新一部分用户资料 /// </summary> /// <param name="U"></param> /// <returns></returns> public static object UpdateaPart(YC_User U) { sqltext = " update [dbo].[YC_User] set [NickName]='" + U.Nickname + "',[Sex]='" + U.Sex + "',[Address]='" + U.Address + "',[Phone]='" + U.Phone + "',[QQ]='" + U.Qq + "' where [UID]='" + U.Uid + "'"; return(SQLHELPER.ExecuteNonQuery(sqltext)); }
/// <summary> /// 更新用户资料 /// </summary> /// <param name="U"></param> /// <returns></returns> public static int UpdateaUInfo(YC_User U) { return(Convert.ToInt32(DAL.UserServer.UpdateaPart(U))); }
/// <summary> /// 修改密码 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int updatePwd(YC_User u) { return(Convert.ToInt32(DAL.UserServer.updatePwd(u))); }
/// <summary> /// 验证密码是否和传入的密码一致 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int AuthPwd(YC_User u) { return(Convert.ToInt32(DAL.UserServer.AuthPwd(u))); }
/// <summary> /// 用户登录 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int login(YC_User u) { return(Convert.ToInt32(DAL.UserServer.login(u))); }
/// <summary> /// 查看用户是否存在 用户名 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int isExists(YC_User u) { return(Convert.ToInt32(DAL.UserServer.isExists(u))); }
/// <summary> /// 注册用户 /// </summary> /// <param name="u"></param> /// <returns></returns> public static int regUser(YC_User u) { return(Convert.ToInt32(DAL.UserServer.add(u))); }
/// <summary> /// 判断输入的用户名对应的密码是否一致 是返回1,不是返回0 /// </summary> /// <param name="u"></param> /// <returns></returns> public static object AuthPwd(YC_User u) { sqltext = " select count(*) from [dbo].[YC_User] where [Name]='" + u.Name + "' AND [PassWord]='" + u.Password + "'"; return(SQLHELPER.ExecuteScalar(sqltext)); }
//更新用户信息(一部分) public static int UpdateUser(YC_User u) { return(Convert.ToInt32(DAL.UserServer.UpdateaPart(u))); }
/// <summary> /// 登录 /// </summary> /// <param name="user"></param> /// <returns></returns> public static object login(YC_User user) { sqltext = " select count(*) from [dbo].[YC_User] where [Name]='" + user.Name + "' and [PassWord]='" + user.Password + "'"; return(SQLHELPER.ExecuteScalar(sqltext)); }
//更新用户资料 public static object update(YC_User user) { sqltext = "insert into [dbo].[YC_User]([Name],[NickName],[PassWord],[Address],[Sex],[Admin],[Phone],[QQ],Enable)values('" + user.Name + "','" + user.Nickname + "','" + user.Password + "','" + user.Address + "','" + user.Sex + "','" + user.Admin + "','" + user.Phone + "','" + user.Qq + "','1')"; return(SQLHELPER.ExecuteNonQuery(sqltext)); }
/// <summary> /// 更新密码 传入用户名 和密码 /// </summary> /// <param name="u"></param> /// <returns></returns> public static object updatePwd(YC_User u) { sqltext = " update [dbo].[YC_User] set [PassWord]='" + u.Password + "' where [Name]='" + u.Name + "'"; return(SQLHELPER.ExecuteNonQuery(sqltext)); }
/// <summary> /// 增加用户 /// </summary> public static object add(YC_User user) { sqltext = "insert into [dbo].[YC_User]([Name],[NickName],[PassWord],[Address],[Sex],[Admin],[Phone],[QQ],Enable,Moneysum,RegDateTime)values('" + user.Name + "','" + user.Nickname + "','" + user.Password + "','" + user.Address + "','" + user.Sex + "','" + 0 + "','" + user.Phone + "','" + user.Qq + "','1','0.00',convert(char(10),getdate(),120)+' '+Convert(varchar(8),Getdate(),108))"; return(SQLHELPER.ExecuteNonQuery(sqltext)); }
/// <summary> /// 查看是否存在这个用户 /// </summary> /// <param name="u"></param> /// <returns></returns> public static object isExists(YC_User u) { sqltext = "select count(*) from [dbo].[YC_User] where [Name]='" + u.Name + "'"; return(SQLHELPER.ExecuteScalar(sqltext)); }