rolelist.cs

来自「这是一个简单的论坛程序源码」· CS 代码 · 共 87 行

CS
87
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetFocus.Web.Core;

namespace NetFocus.Web.Applications.Forum
{
    public class RoleListControl : UserControl
    {
        protected Repeater list;

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack && !AjaxManager.IsCallBack)
            {
                BindData();
            }
            AjaxManager.Register(this, "AjaxMethod");
        }

        private void BindData()
        {
            if (list == null)
            {
                return;
            }
            list.DataSource = Roles.GetAllRoles();
            list.DataBind();
        }

        #region Ajax Method

        [AjaxMethod(IncludeControlValuesWithCallBack = false)]
        public int DeleteRole(int roleId)
        {
            Role role = Roles.GetRole(roleId);
            if (role == null)
            {
                return 0;
            }
            if (NetFocus.Web.Core.Configuration.Instance.IsCoreRole(role.Name))
            {
                return -1;
            }
            Roles.Delete(roleId);
            return 1;
        }

        [AjaxMethod(IncludeControlValuesWithCallBack = false)]
        public int DeleteRoles(string roleIds)
        {
            if (string.IsNullOrEmpty(roleIds))
            {
                return 0;
            }
            string[] roleIdArray = roleIds.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            int roleId = 0;
            foreach (string stringRoleId in roleIdArray)
            {
                try
                {
                    roleId = Int32.Parse(stringRoleId);
                }
                catch
                {
                    continue;
                }
                if (roleId > 0)
                {
                    int result = DeleteRole(roleId);
                    if (result != 1)
                    {
                        return result;
                    }
                }
            }
            return 1;
        }

        #endregion

    }
}

⌨️ 快捷键说明

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