コード例 #1
0
    protected void AddBtn_Click(object sender, EventArgs e)
    {
        ///如果页面输入内容合法
        if (Page.IsValid == true)
        {
            ///定义类User
            DocumentManager.User user = new User();
            try
            {
                ///添加新用户
                user.AddUser(UserName.Text.Trim(),
                             DocumentManager.User.Encrypt(Password.Text.Trim()),
                             Email.Text.Trim(),
                             RoleList.SelectedIndex);

                ///显示操作结果信息
                Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
            }
            catch (Exception ex)
            {
                ///显示添加操作中的失败、错误信息
                Response.Redirect("~/Main/ErrorPage.aspx?ErrorUrl="
                                  + ASPNET2System.RedirectErrorUrl(Request.RawUrl)
                                  + "&ErrorMessage=" + ex.Message.Replace("\n", " "));
            }
        }
    }
コード例 #2
0
    protected void deleteBtn_Click(object sender, ImageClickEventArgs e)
    {
        if (UserList.SelectedIndex > -1)
        {
            ///定义类User
            User user = new User();
            try
            {
                ///删除用户
                user.DeleteUser(Int32.Parse(UserList.SelectedValue));

                ///显示操作结果信息
                Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");

                ///重新绑定数据
                BindUserData();
            }
            catch (Exception ex)
            {
                ///显示添加操作中的失败、错误信息
                Response.Redirect("~/Main/ErrorPage.aspx?ErrorUrl="
                                  + ASPNET2System.RedirectErrorUrl(Request.RawUrl)
                                  + "&ErrorMessage=" + ex.Message.Replace("\n", " "));
            }
        }
        else
        {
            ///显示操作结果信息
            Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
        }
    }
コード例 #3
0
    protected void UpdateBtn_Click(object sender, EventArgs e)
    {
        ///判断用户是否登录
        if (Session["UserID"] == null)
        {
            return;
        }

        ///判断用户输入的旧密码是否正确
        User          user = new User();
        SqlDataReader recu = user.GetSingleUser(Int32.Parse(Session["UserID"].ToString()));

        if (recu.Read())
        {
            String str = DocumentManager.User.Encrypt(PasswordOld.Text.Trim());
            if (recu["Password"].ToString() != DocumentManager.User.Encrypt(PasswordOld.Text.Trim()))
            {
                ///显示操作结果信息
                Response.Write("<script>window.alert('" + ASPNET2System.PasswordErrorMESSAGE + "')</script>");
                return;
            }
        }
        else
        {
            ///显示操作结果信息
            Response.Write("<script>window.alert('" + ASPNET2System.PasswordErrorMESSAGE + "')</script>");
            return;
        }
        ///关闭数据读取器和数据源
        recu.Close();

        try
        {
            ///修改用户的密码
            user.UpdateUserPwd(Int32.Parse(Session["UserID"].ToString()),
                               DocumentManager.User.Encrypt(Password.Text.Trim()));

            ///显示操作结果信息
            Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
        }
        catch (Exception ex)
        {
            ///显示添加操作中的失败、错误信息
            Response.Redirect("~/Main/ErrorPage.aspx?ErrorUrl="
                              + ASPNET2System.RedirectErrorUrl(Request.RawUrl)
                              + "&ErrorMessage=" + ex.Message.Replace("\n", " "));
        }
    }