Пример #1
0
        protected void btnChangePwd_Click(object sender, EventArgs e)
        {
            SysAdmin user = new SysAdmin();

            user = (SysAdmin)Session["Currentuser"];
            string newpwd = txtNewPwd.Text.Trim();
            string oldpwd = txtOldPwd.Text.Trim();

            try
            {
                if (user.LoginPwd != oldpwd)
                {
                    ltaMsg.Text = "<script>alert('原密码错误!')</script>";
                }
                else
                {
                    AdminServices.ChangePwd(user, newpwd);
                    Session["Currentuser"] = user;
                    ltaMsg.Text            = "<script>alert('修改成功!');location='../Default.aspx'</script>";
                }
            }
            catch (Exception ex)
            {
                ltaMsg.Text = "<script>alert('" + ex.Message + "')</script>";
                throw ex;
            }
        }
Пример #2
0
        protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
        {
            //[1]Ecapusilate login information
            SysAdmin objAdmin = new SysAdmin()
            {
                LoginId  = Convert.ToInt32(this.txtUserId.Text.Trim()),
                LoginPwd = this.txtPwd.Text.Trim()
            };

            //[2]Using Data Accessing class to query user information
            try
            {
                objAdmin = new AdminService().AdminLogin(objAdmin);
                if (objAdmin == null)
                {
                    this.ltaInfo.Text = "<script>alert('User name or password is wrong')</script>";
                }
                else
                {
                    Session["CurrentUser"] = objAdmin;
                    Response.Redirect("~/Default.aspx", false);
                }
            }
            catch (Exception ex)
            {
                this.ltaInfo.Text = "<script>alert('" + ex.Message + "')</script>";
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["CurrentUser"] == null)
     {
         Response.Redirect("~/AdminLogin.aspx");
     }
     else
     {//If user login successfully it will display user information
         SysAdmin objAdmin = (SysAdmin)Session["CurrentUser"];
         this.ltaUserName.Text = "Welcome back: " + objAdmin.AdminName;
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["Currentuser"] == null)
     {
         Response.Redirect("~/AdminLogin.aspx");
     }
     else
     {
         SysAdmin user = (SysAdmin)Session["Currentuser"];
         ltaUserName.Text = "欢迎您:" + user.AdminName;
     }
 }
Пример #5
0
 private void CheckLoginInfo()
 {
     if (File.Exists("sysAdmins.sys"))//如果本地有保存登录信息
     {
         admin = adminService.ReadLoginInfo();
         if (Convert.ToDateTime(admin.LastLoginTime).AddDays(10) > DateTime.Now)
         {
             //如果登录信息没有失效,则显示登录信息
             this.txtLoginId.Text    = admin.LoginId.ToString();
             this.txtLoginPwd.Text   = admin.LoginPwd;
             this.ckbSavePwd.Checked = true;
         }
     }
 }
Пример #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //判断用户是否登录
     if (Session["CurrentUser"] == null)
     {
         Response.Redirect("~/AdminLogin.aspx");
     }
     else
     {
         //显示登录用户信息
         SysAdmin objAdmin = (SysAdmin)Session["CurrentUser"];
         this.ltaUserName.Text = "欢迎您:&nbsp;" + objAdmin.AdminName;
     }
 }
Пример #7
0
        /// <summary>
        /// 修改管理员密码
        /// </summary>
        /// <param name="objAdmin"></param>
        /// <returns></returns>
        public int ModifyPwd(SysAdmin objAdmin)
        {
            string sql = "update Admins set LoginPwd='{0}' where LoginId={1}";

            sql = string.Format(sql, objAdmin.LoginPwd, objAdmin.LoginId);
            try
            {
                return(SQLHelper.Update(sql));
            }
            catch (SqlException)
            {
                throw new Exception("应用程序和数据库连接出现问题!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
        {
            int      LoginId  = Convert.ToInt32(txtUserId.Text);
            String   LoginPwd = Convert.ToString(txtPwd.Text).Trim();
            SysAdmin user     = new SysAdmin();

            user.LoginId  = LoginId;
            user.LoginPwd = LoginPwd;
            user          = AdminServices.LoginCheck(user);
            if (user == null)
            {
                ltaInfo.Text = "<script type='text/javascript'> alert('账号或密码错误,请重试!')</script>";
            }
            else
            {
                Session["CurrentUser"] = user;
                Response.Redirect("~/Default.aspx");
            }
        }
        protected void btnChangePwd_Click(object sender, EventArgs e)
        {
            //Decide whehter original password is right
            SysAdmin objAdmin = (SysAdmin)Session["CurrentUser"];

            if (objAdmin.LoginPwd != this.txtOldPwd.Text.Trim())
            {
                this.ltaMsg.Text = "<script>alert('Original password isn not right')</script>";
                //this.ltaMsg.Text = "<script>alert('hahaha')</script>";
                return;
            }
            //Encapusilate new password
            objAdmin.LoginPwd = this.txtNewPwd.Text.Trim();
            //Use backend method to change password
            try
            {
                new AdminService().ModifyPwd(objAdmin);
                this.ltaMsg.Text = "<script>alert('Password is modified successfully');location='../Default.aspx'</script>";
            }
            catch (Exception ex)
            {
                this.ltaMsg.Text = "<script>alert('" + ex.Message + "')";
            }
        }
Пример #10
0
        //用户登录
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //int a = 100;
            //Console.WriteLine(a);
            //SysAdmin admin1 = new SysAdmin();
            //Console.WriteLine(admin1.GetType().ToString());
            //return;

            //【1】数据验证
            if (this.txtLoginId.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入登录账号!", "登录提示");
                this.txtLoginId.Focus();
                return;
            }
            if (this.txtLoginPwd.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入登录密码!", "登录提示");
                this.txtLoginPwd.Focus();
                return;
            }
            //验证登录账号必须是数字(可以使用正则表达式,只需要了解,会用即可,如果感兴趣,可以自己研究怎么写)


            //【2】对象封装(把用户输入的数据封装为对象,用对象属性承载数据)
            admin = new SysAdmin
            {
                LoginId  = Convert.ToInt32(this.txtLoginId.Text.Trim()),
                LoginPwd = this.txtLoginPwd.Text.Trim()
            };
            //【3】调用后台数据访问方法验证
            try
            {
                admin = adminService.AdminLogin(admin);
            }
            catch (Exception ex)
            {
                MessageBox.Show("用户登录发生异常!具体错误:" + ex.Message, "登录错误");
                return;
            }
            if (admin != null)//如果账号和密码是正确的
            {
                //【1】验证账号状态是否允许
                if (admin.AdminStatus == 1)
                {
                    //【2】把当前登录用户的信息保存起来(后面有可能用到)
                    Program.currentAdmin = admin;
                    //【3】如果有权限,那么可以在这个根据登录信息查询权限...(如果数据访问类中写了,此处就不要写,建议大家写到这个地方)

                    //【4】判断用户是否需要记住密码和登录账号
                    if (this.ckbSavePwd.Checked)
                    {
                        admin.LastLoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    }
                    else //如果没有选中,有两种方式:1.可以删除保存的文件  2.在当前日期前面减去大于10的天数
                    {
                        //比如是2020-12-30
                        admin.LastLoginTime = DateTime.Now.AddDays(-11).ToString("yyyy-MM-dd HH:mm");
                    }
                    adminService.SaveLoginInfo(admin);//保存登录信息

                    //【5】写入登录日志...(什么时候登录的,登录的IP地址是什么,登录名是谁...我们在课程8 就有讲解...)

                    //【6】关闭登录窗体
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("当前用户为禁止登录状态,请联系管理员!", "登录提示");
                }
            }
            else
            {
                MessageBox.Show("用户名或密码错误!", "登录提示");
            }
        }