⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 administrator.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite.Admin.User
{
    using AjaxControlToolkit;
    using PowerEasy.AccessManage;
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Controls;
    using PowerEasy.Enumerations;
    using PowerEasy.Model.UserManage;
    using PowerEasy.UserManage;
    using PowerEasy.Web.UI;
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class Administrator : AdminPage
    {
        protected Button BtnCancle;
        protected Button BtnSubmit;
        protected CheckBox ChkEnableModifyPassword;
        protected CheckBox ChkEnableMultiLogin;
        protected CheckBox ChkIsLock;
        protected CompareValidator CompareValidator1;
        protected HiddenField HdnBelongToRole;
        protected HyperLink HypAddUser;
        protected Label LabTip;
        protected AlternateLiteral LblTitle;
        protected ListBox LstBelongToRole;
        protected ListBox LstNotBelongRole;
        protected PasswordStrength PasswordStrength2;
        protected RadioButton RadPurview1;
        protected RadioButton RadPurview2;
        protected PowerEasy.Controls.RequiredFieldValidator RequiredFieldValidator1;
        protected PowerEasy.Controls.RequiredFieldValidator RequiredFieldValidator2;
        protected HtmlTableRow RolePurview;
        protected ScriptManager SmgeRegion;
        protected ExtendedSiteMapPath SmpNavigator;
        protected TextBox TxtAdminName;
        protected TextBox TxtPassword;
        protected TextBox TxtPassword2;
        protected TextBox TxtUserName;
        protected RegularExpressionValidator ValeUserName;
        protected RegularExpressionValidator ValgTextMaxLength;
        protected PowerEasy.Controls.RequiredFieldValidator ValrUserPassword;

        private void AddAdmin()
        {
            UserInfo usersByUserName = Users.GetUsersByUserName(this.TxtUserName.Text.Trim());
            if (usersByUserName.IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户名不存在!");
            }
            AdministratorInfo adminInfo = new AdministratorInfo();
            adminInfo.AdminName = this.TxtAdminName.Text.Trim();
            adminInfo.UserName = this.TxtUserName.Text.Trim();
            adminInfo.IsLock = this.ChkIsLock.Checked;
            adminInfo.EnableModifyPassword = this.ChkEnableModifyPassword.Checked;
            if (string.IsNullOrEmpty(this.TxtPassword.Text.Trim()))
            {
                AdminPage.WriteErrMsg("管理员密码不能为空");
            }
            else
            {
                adminInfo.AdminPassword = StringHelper.MD5(this.TxtPassword.Text);
            }
            adminInfo.EnableMultiLogin = this.ChkEnableMultiLogin.Checked;
            if (Administrators.IsExist(adminInfo.AdminName))
            {
                AdminPage.WriteErrMsg("已经存在同样的管理员名!");
            }
            if (!Administrators.GetAdministratorByUserName(usersByUserName.UserName).IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户已经被添加为管理员了!");
            }
            if (Administrators.Add(adminInfo))
            {
                if (this.RadPurview1.Checked)
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, "0");
                }
                else
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, this.HdnBelongToRole.Value);
                }
                AdminPage.WriteSuccessMsg("添加管理员成功!", "AdministratorManage.aspx");
            }
            else
            {
                AdminPage.WriteErrMsg("添加管理员失败!");
            }
        }

        protected void BelongToRole(ListControl dropName, int adminId)
        {
            if (adminId != 0)
            {
                IList<RoleInfo> roleListByRoleId = UserRole.GetRoleListByRoleId(adminId);
                if (roleListByRoleId.Count > 0)
                {
                    dropName.Items.Clear();
                    dropName.DataSource = roleListByRoleId;
                    dropName.DataBind();
                }
                else
                {
                    dropName.Items.Clear();
                }
            }
        }

        protected void BtnCancle_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Server.Transfer("AdministratorManage.aspx");
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (base.IsValid)
            {
                if (string.Compare(BasePage.RequestString("Action"), "Modify", true) == 0)
                {
                    this.ModifyAdmin();
                }
                else
                {
                    this.AddAdmin();
                }
            }
        }

        private void InitModify()
        {
            int adminId = BasePage.RequestInt32("AdminId");
            AdministratorInfo administratorByAdminId = Administrators.GetAdministratorByAdminId(adminId);
            if (administratorByAdminId.IsNull)
            {
                AdminPage.WriteErrMsg("不存在此管理员");
            }
            if (RoleMembers.GetRoleIdListByAdminId(adminId).IndexOf("0") >= 0)
            {
                this.RadPurview1.Checked = true;
                this.RadPurview2.Checked = false;
                this.RolePurview.Style.Add("display", "none");
            }
            this.TxtAdminName.Text = administratorByAdminId.AdminName;
            this.TxtUserName.Text = administratorByAdminId.UserName;
            this.ChkEnableMultiLogin.Checked = administratorByAdminId.EnableMultiLogin;
            this.ViewState["AdminName"] = administratorByAdminId.AdminName;
            this.ViewState["UserName"] = administratorByAdminId.UserName;
            this.ChkEnableModifyPassword.Checked = administratorByAdminId.EnableModifyPassword;
            this.ChkIsLock.Checked = administratorByAdminId.IsLock;
            if (PEContext.Current.Admin.AdministratorInfo.AdminId == adminId)
            {
                this.ChkIsLock.Enabled = false;
            }
            this.TxtAdminName.Enabled = false;
            this.ViewState["Password"] = administratorByAdminId.AdminPassword;
            this.ValrUserPassword.Enabled = false;
            this.CompareValidator1.Enabled = false;
            this.LabTip.Text = "<font color=red>不修改密码请保持为空!</font>";
            if (!administratorByAdminId.EnableModifyPassword && !PEContext.Current.Admin.IsSuperAdmin)
            {
                this.TxtPassword.Enabled = false;
                this.TxtPassword2.Enabled = false;
                this.LabTip.Visible = false;
                this.ChkEnableModifyPassword.Enabled = false;
            }
        }

        private void ModifyAdmin()
        {
            AdministratorInfo administratorByAdminId = Administrators.GetAdministratorByAdminId(BasePage.RequestInt32("AdminId"));
            if (string.IsNullOrEmpty(this.TxtPassword.Text.Trim()))
            {
                administratorByAdminId.AdminPassword = this.ViewState["Password"].ToString();
            }
            else
            {
                administratorByAdminId.AdminPassword = StringHelper.MD5(this.TxtPassword.Text);
            }
            if ((!administratorByAdminId.EnableModifyPassword && (administratorByAdminId.AdminPassword != this.ViewState["Password"].ToString())) && !PEContext.Current.Admin.IsSuperAdmin)
            {
                AdminPage.WriteErrMsg("没有修改密码的权限!");
            }
            if (administratorByAdminId.AdminPassword != this.ViewState["Password"].ToString())
            {
                administratorByAdminId.LastModifyPasswordTime = new DateTime?(DateTime.Now);
            }
            if (string.Compare(this.TxtUserName.Text.Trim(), this.ViewState["UserName"].ToString(), true) != 0)
            {
                UserInfo usersByUserName = Users.GetUsersByUserName(this.TxtUserName.Text.Trim());
                if (usersByUserName.IsNull)
                {
                    AdminPage.WriteErrMsg("此前台用户名不存在!");
                }
                if (!Administrators.GetAdministratorByUserName(usersByUserName.UserName).IsNull)
                {
                    AdminPage.WriteErrMsg("此前台用户已经被添加为管理员了!");
                }
            }
            administratorByAdminId.UserName = this.TxtUserName.Text.Trim();
            administratorByAdminId.IsLock = this.ChkIsLock.Checked;
            administratorByAdminId.EnableModifyPassword = this.ChkEnableModifyPassword.Checked;
            administratorByAdminId.EnableMultiLogin = this.ChkEnableMultiLogin.Checked;
            if (Administrators.Update(administratorByAdminId))
            {
                if (this.RadPurview1.Checked)
                {
                    RoleMembers.AddMemberToRoles(administratorByAdminId.AdminId, "0");
                }
                else
                {
                    RoleMembers.AddMemberToRoles(administratorByAdminId.AdminId, this.HdnBelongToRole.Value);
                }
                AdminPage.WriteSuccessMsg("修改管理员成功!", "AdministratorManage.aspx");
            }
            else
            {
                AdminPage.WriteErrMsg("修改管理员失败!");
            }
        }

        public void NotBelongRoleDataBind(ListControl dropName, int adminId)
        {
            IList<RoleInfo> roleList;
            if (adminId == 0)
            {
                roleList = UserRole.GetRoleList(0, 0);
            }
            else
            {
                roleList = UserRole.GetRoleListNotInRole(adminId);
            }
            if (roleList.Count > 0)
            {
                dropName.Items.Clear();
                dropName.DataSource = roleList;
                dropName.DataBind();
            }
            else
            {
                dropName.Items.Clear();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            RolePermissions.BusinessAccessCheck(OperateCode.AdministratorManage);
            string str = BasePage.RequestString("UserName");
            if (!string.IsNullOrEmpty(str))
            {
                this.TxtUserName.Text = str;
            }
            if (!base.IsPostBack)
            {
                int adminId = BasePage.RequestInt32("AdminId");
                this.RadPurview1.Attributes.Add("onclick", "javascript:RadPurview(0);");
                this.RadPurview2.Attributes.Add("onclick", "javascript:RadPurview(1);");
                this.NotBelongRoleDataBind(this.LstNotBelongRole, adminId);
                this.BelongToRole(this.LstBelongToRole, adminId);
                this.BtnSubmit.OnClientClick = "return GetBelongToRole(" + this.LstBelongToRole.ClientID + ");";
                if (string.Compare(BasePage.RequestString("Action"), "Modify", true) == 0)
                {
                    this.InitModify();
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -