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

📄 sectionadmins.cs

📁 这是一个简单的论坛程序源码
💻 CS
字号:
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 SectionAdmins : UserControl
    {
        protected CheckBoxList userList;
        protected ResourceButton saveButton;

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack && !AjaxManager.IsCallBack)
            {
                BindData();
            }
            saveButton.Click += new EventHandler(SaveSectionAdmins);
        }

        private void BindData()
        {
            if (userList == null)
            {
                return;
            }

            Role role = Roles.GetRole(Configuration.Instance.ForumSectionAdminRoleName);
            
            if (role != null)
            {
                userList.DataSource = Roles.GetRoleUsers(role.RoleId);
                userList.DataTextField = "UserName";
                userList.DataValueField = "UserId";
                userList.DataBind();

                Section section = BusinessManager.GetSection(WebContext.Current.SectionId);

                if (section != null && section.AdminRoleUserList != null)
                {
                    foreach (RoleUser roleUser in section.AdminRoleUserList)
                    {
                        foreach (ListItem item in userList.Items)
                        {
                            if (item.Value == roleUser.UserId.ToString())
                            {
                                item.Selected = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        private void SaveSectionAdmins(object sender, EventArgs e)
        {
            Section section = BusinessManager.GetSection(WebContext.Current.SectionId);

            if (section != null)
            {
                List<string> userIdList = new List<string>();
                List<string> userNameList = new List<string>();
                foreach (ListItem item in userList.Items)
                {
                    if (item.Selected)
                    {
                        userIdList.Add(item.Value);
                        userNameList.Add(item.Text);
                    }
                }
                section.AdminUserIds = string.Join(",", userIdList.ToArray());
                section.AdminUserNames = string.Join(",", userNameList.ToArray());
                BusinessManager.UpdateSection(section);
            }
        }
    }
}

⌨️ 快捷键说明

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