Exemplo n.º 1
0
        //用户登录
        protected void btn_login_Click(object sender, EventArgs e)
        {
            //封装用户名和密码
            SysAdmin objAdmin = new SysAdmin()
            {
                LoginId  = Convert.ToInt16(this.txtUserId.Text.Trim()),
                LoginPwd = this.txtPwd.Text.Trim()
            };

            try
            {
                objAdmin = new AdminDao().AdminLogin(objAdmin); //根据用户名或密码查询
                if (objAdmin == null)                           //提示用户登录名或密码
                {
                    this.ltaInfo.Text = "<script type='text/javascript'>alert('用户名或密码错误!')</script>";
                }
                else    //保存用户对象,并跳转到首页
                {
                    Session["CurrentUser"] = objAdmin;
                    Response.Redirect("~/Default.aspx");
                }
            }
            catch (Exception ex)
            {
                this.ltaInfo.Text = "<script type='text/javascript'>alert('" + ex.Message + "')</script>";
            }
        }
Exemplo n.º 2
0
        //修改登录密码
        protected void btnChangePwd_Click(object sender, EventArgs e)
        {
            if (((SysAdmin)Session["CurrentUser"]).LoginPwd !=
                this.txtOldPwd.Text.Trim())
            {
                this.ltaMsg.Text = "<script type='text/javascript'>alert('原密码不正确!')</script>";
                return;
            }
            AdminDao objAdminDao = new AdminDao();
            SysAdmin objAdmin    = new SysAdmin()
            {
                LoginId  = ((SysAdmin)Session["CurrentUser"]).LoginId,
                LoginPwd = this.txtNewPwd.Text.Trim()
            };

            try
            {
                objAdminDao.ModifyPwd(objAdmin);//修改密码
                this.ltaMsg.Text =
                    "<script type='text/javascript'>alert('用户密码修改成功!');location='../Default.aspx'</script>";
            }
            catch (Exception ex)
            {
                this.ltaMsg.Text = "<script type='text/javascript'>alert('" + ex.Message + "')</script>";
            }
        }