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

📄 moderatedforums.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
            else {	// we are viewing the users who can moderate a particular forum
                // display the user's name
                bndcolTmp = new BoundColumn();
                bndcolTmp.HeaderStyle.CopyFrom(this._headerStyle);
                bndcolTmp.ItemStyle.CopyFrom(this._itemStyle);
                bndcolTmp.DataField = "UserName";
                bndcolTmp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                bndcolTmp.HeaderText = "User";
                dgModeratedForums.Columns.Add(bndcolTmp);
            }
				
            // display whether or not the user receives email notification
            bndcolTmp = new BoundColumn();			
            bndcolTmp.DataField = "EmailNotification";
            bndcolTmp.HeaderStyle.CopyFrom(this._headerStyle);
            bndcolTmp.ItemStyle.CopyFrom(this._itemStyle);
            bndcolTmp.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            bndcolTmp.HeaderText = "Email Notification";
            bndcolTmp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bndcolTmp.DataFormatString = "{0:g}";
            dgModeratedForums.Columns.Add(bndcolTmp);

            // display the date they were given administration of this forum
            bndcolTmp = new BoundColumn();			
            bndcolTmp.DataField = "DateCreated";
            bndcolTmp.HeaderStyle.CopyFrom(this._headerStyle);
            bndcolTmp.ItemStyle.CopyFrom(this._itemStyle);
            bndcolTmp.HeaderText = "Date Assigned";
            bndcolTmp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bndcolTmp.DataFormatString = "{0:g}";
            dgModeratedForums.Columns.Add(bndcolTmp);
        }



	

        /***********************************************************************
        dgModeratedForums_RemoveForum Event Handler
        -------------------------------------------
            This event handler is fired when the user clicks on the Remove Forum button.
            This can only happen if we are viewing the forums a particular user can
            moderate.  The RemoveModeratedForumForUser method of the Users class
            does all the leg work for us.
        ************************************************************************/
        private void dgModeratedForums_RemoveForum(Object sender, DataGridCommandEventArgs e) {
            // remove the selected moderated forum for the particular user
            int iForumID = Convert.ToInt32(e.Item.Cells[1].Text);
			
            ModeratedForum forum = new ModeratedForum();
            forum.Username = Username;
            forum.ForumID = iForumID;
			
            Users.RemoveModeratedForumForUser(forum);

            // rebind the datagrid
            RebindData();
        }



        /***********************************************************************
        void RebindData function
        ------------------------
            This function is called from the UserAdmin and EditForum Web controls
            to bind the necessary Web controls within the ModeratedFroums Web control.			
        ************************************************************************/
        /// <summary>
        /// This method is called from the UserAdmin and EditForum Web controls
        /// to bind the necessary Web controls within the ModeratedFroums Web control.
        /// </summary>
        /// <remarks>This method is synonymous to other Web control's DataBind() method.
        /// This Web control, however, does not have a DataSource property.  Rather, this
        /// property is hard-coded in the control.</remarks>
        public void RebindData() {
            // make sure CreateChildControls has been called.
            this.EnsureChildControls();

            // determine if we are viewing a list of forums that a user can moderate...
            if (Mode == ModeratedForumMode.ViewForUser) {
                // databind the moderated forums datagrid
                dgModeratedForums.DataSource = Users.GetForumsModeratedByUser(Username);
                dgModeratedForums.DataBind();
				

                // databind the listbox of forum names
                ModeratedForumCollection forumsNotModerated = Users.GetForumsNotModeratedByUser(Username);

                // did we get any forums back?
                if (forumsNotModerated.Count > 0) {
                    ((Panel) FindControl("panelAddForum")).Visible = true;
                    ((ListBox) FindControl("lstForums")).DataSource = forumsNotModerated;
                    ((ListBox) FindControl("lstForums")).DataBind();
                }
                else {
                    ((Panel) FindControl("panelAddForum")).Visible = false;
                }
            }
            else {	// or if we are viewing a list of users that can moderate a forum
                // databind the list of moderators datagrid
                dgModeratedForums.DataSource = Moderate.GetForumModerators(ForumID);
                dgModeratedForums.DataBind();

            }
        }

		


        /************ PROPERTY SET/GET STATEMENTS **************/
        /// <summary>
        /// Specifies the style for the table headers in the DataGrid.
        /// </summary>
        public TableItemStyle DataGridHeaderStyle {
            get  {  return _headerStyle;  }
        }

        /// <summary>
        /// Specifies the style for each item in the DataGrid.
        /// </summary>
        public TableItemStyle DataGridItemStyle {
            get  {  return _itemStyle;  }
        }

        /// <summary>
        /// When Mode is set to ViewForUser, you must specify the Username of the
        /// user whose list of moderated forums you wish to view.
        /// <seealso cref="Mode"/>
        /// </summary>
        /// <remarks>If Mode is set to ViewForUser and Username is not specified, an
        /// Exception will be thrown.</remarks>
        public String Username {
            get {
                if (ViewState["username"] == null) return "";
                return (String) ViewState["username"];
            }
            set { ViewState["username"] = value; }
        }
		
        /// <summary>
        /// When Mode is set to ViewForForum, you must specify the ForumID of the
        /// forum whose list of moderators you wish to view.
        /// <seealso cref="Mode"/>
        /// </summary>
        /// <remarks>If Mode is set to ViewForForum and ForumID is not specified, an
        /// Exception will be thrown.</remarks>
        public int ForumID {
            get {
                if (ViewState["forumID"] == null) return -1;
                return (int) ViewState["forumID"];
            }
            set { ViewState["forumID"] = value; }
        }

        /// <summary>
        /// Specifies the CellPadding for the DataGrid.
        /// </summary>
        public int CellPadding {
            get {
                if (ViewState["cellPadding"] == null) return _defaultCellPadding;
                return (int) ViewState["cellPadding"];
            }
            set { ViewState["cellPadding"] = value; }
        }

        /// <summary>
        /// Specifies a textual title to display immediately before the DataGrid.
        /// </summary>
        public String DataGridTitle {
            get {
                if (ViewState["dgTitle"] == null) {
                    if (Mode == ModeratedForumMode.ViewForUser)
                        return _defaultForUserDataGridTitle;
                    else
                        return this._defaultForForumDataGridTitle;
                }
                return (String) ViewState["dgTitle"];
            }
            set { ViewState["dgTitle"] = value; }
        }

        /// <summary>
        /// Specifies the CellSpacing to use for the DataGrid.
        /// </summary>
        public int CellSpacing {
            get {
                if (ViewState["cellSpacing"] == null) return _defaultCellSpacing;
                return (int) ViewState["cellSpacing"];
            }
            set { ViewState["cellSpacing"] = value; }
        }

        /// <summary>
        /// Specifies the Mode for the Web control.  This property can have one of two values:
        /// ViewForUser or ViewForForum.  If ViewForUser is selected, a Username must be passed in
        /// and the list of forums that the particular user moderates is displayed, along with the
        /// option to add and remove forums from this list.  If Mode is set to ViewForForum, a
        /// ForumID must be passed in and the list of users that moderate the particular forum are
        /// shown.  The default is ViewForUser.
        /// <seealso cref="Username"/>
        /// <seealso cref="ForumID"/>
        /// </summary>
        /// <remarks>If Mode is set to ViewForUser and the Username property is not set, an
        /// Exception will be thrown.  Likewise, if Mode is set to ViewForForum and the ForumID
        /// property is not set, an Exception will be thrown.</remarks>
        public ModeratedForumMode Mode {
            get {
                if (ViewState["mode"] == null) return _defaultMode;
                return (ModeratedForumMode) ViewState["mode"];
            }
            set { ViewState["mode"] = value; }
        }

        /// <summary>
        /// Indicates if the Web control should check to verify that the user visiting the page
        /// is, indeed, a moderator.
        /// </summary>
        public bool CheckUserPermissions {
            get {
                if (ViewState["checkUserPerm"] == null) return true;
                return (bool) ViewState["checkUserPerm"];
            }
            set { ViewState["checkUserPerm"] = value; }
        }
        /*******************************************************/
    }
}

⌨️ 快捷键说明

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