projectnotifications.ascx.cs

来自「BugNET is an issue tracking and project 」· CS 代码 · 共 143 行

CS
143
字号
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BugNET.BusinessLogicLayer;
using BugNET.UserInterfaceLayer;
using System.Collections.Generic;

namespace BugNET.Administration.Projects.UserControls
{
    public partial class ProjectNotifications : System.Web.UI.UserControl, IEditProjectControl
    {
        private int _ProjectId = -1;

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region IEditProjectControl Members

        /// <summary>
        /// Gets or sets the project id.
        /// </summary>
        /// <value>The project id.</value>
        public int ProjectId
        {
            get { return _ProjectId; }
            set { _ProjectId = value; }
        }


        /// <summary>
        /// Updates this instance.
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
          
            return true;
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            lstAllUsers.Items.Clear();
            lstSelectedUsers.Items.Clear();

            lstAllUsers.DataSource = ITUser.GetUsersByProjectId(ProjectId);
            lstAllUsers.DataTextField = "DisplayName";
            lstAllUsers.DataValueField = "Username";
            lstAllUsers.DataBind();

            // Copy selected users into Selected Users List Box
            List<ProjectNotification> projectNotifications = ProjectNotification.GetProjectNotificationsByProjectId(ProjectId);
            foreach (ProjectNotification currentNotification in projectNotifications)
            {
                ListItem matchItem = lstAllUsers.Items.FindByValue(currentNotification.NotificationUsername);
                if (matchItem != null)
                {
                    lstSelectedUsers.Items.Add(matchItem);
                    lstAllUsers.Items.Remove(matchItem);
                }
            }

         
        }

        #endregion


        /// <summary>
        /// Adds the user.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddUser(Object s, EventArgs e)
        {
            //The users must be added to a list first becuase the collection can not
            //be modified while we iterate through it.
            var usersToAdd = new List<ListItem>();

            foreach (ListItem item in lstAllUsers.Items)
                if (item.Selected)
                    usersToAdd.Add(item);


            foreach (var item in usersToAdd)
            {
                ProjectNotification pn = new ProjectNotification(ProjectId,item.Value);
                if (pn.Save())
                {
                    lstSelectedUsers.Items.Add(item);
                    lstAllUsers.Items.Remove(item);
                }
            }

            lstSelectedUsers.SelectedIndex = -1;
        }

        /// <summary>
        /// Removes the user.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void RemoveUser(Object s, EventArgs e)
        {
            //The users must be added to a list first becuase the collection can not
            //be modified while we iterate through it.
            var usersToRemove = new List<ListItem>();

            foreach (ListItem item in lstSelectedUsers.Items)
                if (item.Selected)
                    usersToRemove.Add(item);


            foreach (var item in usersToRemove)
            {             
                if (ProjectNotification.DeleteProjectNotification(ProjectId,item.Value))
                {
                    lstAllUsers.Items.Add(item);
                    lstSelectedUsers.Items.Remove(item);
                }
            }

            lstAllUsers.SelectedIndex = -1;
        }
    }
    
}

⌨️ 快捷键说明

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