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

📄 preferences.aspx.cs

📁 该项目管理系统可对项目的过程进行管理和控制
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace BronzeMonkey.GeneralTaskList
{
	/// <summary>
	/// Summary description for Preferences.
	/// </summary>
	public class Preferences : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ListBox lstDisplayFrom;
		protected System.Web.UI.WebControls.Button btnDisplayAdd;
		protected System.Web.UI.WebControls.Button btnDisplayRemove;
		protected System.Web.UI.WebControls.ListBox lstDisplayTo;
		protected System.Web.UI.WebControls.DropDownList cboTaskListToView;
		protected System.Web.UI.WebControls.LinkButton lnkLogOff;
	
		private BronzeMonkey.GeneralTaskList.TaskList tl = new BronzeMonkey.GeneralTaskList.TaskList();
		protected System.Web.UI.WebControls.RadioButtonList TaskListToDisplayList;
		protected System.Web.UI.WebControls.ListBox lstTaskSortOrder;
		protected System.Web.UI.WebControls.Button btnTaskSortOrderMoveUp;
		protected System.Web.UI.WebControls.Button btnTaskSortOrderMoveDown;
		protected System.Web.UI.WebControls.DropDownList cboItemsToShow;
    protected System.Web.UI.WebControls.CheckBox chkShouldNotify;
    protected System.Web.UI.WebControls.TextBox txtNotifyPeriod;
    protected System.Web.UI.WebControls.Button btnSaveNotification;
		private UserInformation CurrentUser = new UserInformation();

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if (Session["CurrentUser"] == null) 
				Response.Redirect("login.aspx");
			else
				CurrentUser = (UserInformation)Session["CurrentUser"];

			if (!Page.IsPostBack)
			{
        chkShouldNotify.Checked = CurrentUser.ShouldNotify;
        txtNotifyPeriod.Text = CurrentUser.NotifyPeriod.ToString();
        txtNotifyPeriod.Enabled = chkShouldNotify.Checked;

				LoadTaskListDropDown();
				LoadStatusTypes();
				LoadStartupViewOptionSection();
				LoadNumberOfItemsToDisplay();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.lnkLogOff.Click += new System.EventHandler(this.lnkLogOff_Click);
			this.chkShouldNotify.CheckedChanged += new System.EventHandler(this.chkShouldNotify_CheckedChanged);
			this.btnSaveNotification.Click += new System.EventHandler(this.btnSaveNotification_Click);
			this.TaskListToDisplayList.SelectedIndexChanged += new System.EventHandler(this.TaskListToDisplayList_SelectedIndexChanged);
			this.cboTaskListToView.SelectedIndexChanged += new System.EventHandler(this.cboTaskListToView_SelectedIndexChanged);
			this.cboItemsToShow.SelectedIndexChanged += new System.EventHandler(this.cboItemsToShow_SelectedIndexChanged);
			this.btnTaskSortOrderMoveUp.Click += new System.EventHandler(this.btnTaskSortOrderMoveUp_Click);
			this.btnTaskSortOrderMoveDown.Click += new System.EventHandler(this.btnTaskSortOrderMoveDown_Click);
			this.btnDisplayAdd.Click += new System.EventHandler(this.btnDisplayAdd_Click);
			this.btnDisplayRemove.Click += new System.EventHandler(this.btnDisplayRemove_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void LoadTaskListDropDown()
		{
			SqlDataReader dr = tl.GetUserTaskLists(CurrentUser, CurrentUser.UserID);

			cboTaskListToView.Items.Clear();
			while (dr.Read())
			{
				cboTaskListToView.Items.Add(new ListItem(dr["TaskListName"].ToString(), dr["TaskListID"].ToString()));
			}
		}

		private void LoadStatusTypes()
		{
			SqlDataReader dr = tl.GetUserSortOrderPreferences(CurrentUser);
			lstDisplayFrom.Items.Clear();
			lstTaskSortOrder.Items.Clear();
			while (dr.Read())
			{
				lstDisplayFrom.Items.Add(new ListItem(dr["StatusDescription"].ToString(), dr["StatusID"].ToString()));
				lstTaskSortOrder.Items.Add(new ListItem(dr["StatusDescription"].ToString(), dr["StatusID"].ToString()));
			}

			dr = tl.GetUserStatusShowPreferences(CurrentUser);
			lstDisplayTo.Items.Clear();
			while (dr.Read())
			{
				lstDisplayTo.Items.Add(new ListItem(dr["StatusDescription"].ToString(), dr["StatusID"].ToString()));
			}
		}

		private void LoadStartupViewOptionSection()
		{
			StartupViewOptionEnum vo = tl.GetStartupViewOption(CurrentUser);
			int StartupTaskListID = tl.GetStartupTaskListID(CurrentUser);
			// Select the correct radio button to correspond with our method
			if (vo == StartupViewOptionEnum.LastTaskList)
				TaskListToDisplayList.Items.FindByValue("LastTaskList").Selected = true;
			else
				TaskListToDisplayList.Items.FindByValue("SpecificTaskList").Selected = true;
			// Now select the proper task list
			cboTaskListToView.SelectedIndex = -1;
			cboTaskListToView.Items.FindByValue(StartupTaskListID.ToString()).Selected = true;
		}
		
		private void LoadNumberOfItemsToDisplay()
		{
			string NumberOfItems = tl.GetNumberOfItemsToDisplayPerPage(CurrentUser);
			cboItemsToShow.SelectedIndex = -1;
			cboItemsToShow.Items.FindByValue(NumberOfItems).Selected = true;
		}

		private void lnkLogOff_Click(object sender, System.EventArgs e)
		{
			Session.Abandon();
			System.Web.Security.FormsAuthentication.SignOut();
			Response.Redirect("login.aspx");
		}

		private void TaskListToDisplayList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (TaskListToDisplayList.Items.FindByValue("SpecificTaskList").Selected == true)
			{
				cboTaskListToView.Enabled = true;
				tl.ChangeStartupViewOption(CurrentUser, StartupViewOptionEnum.SpecificTaskList);
				tl.ChangeStartupTaskListID(CurrentUser, Convert.ToInt32(cboTaskListToView.SelectedItem.Value));
			}
			else
			{
				tl.ChangeStartupViewOption(CurrentUser, StartupViewOptionEnum.LastTaskList);
				cboTaskListToView.Enabled = false;
			}
		}

		private void btnTaskSortOrderMoveUp_Click(object sender, System.EventArgs e)
		{
			ListItem PreviousItem;
			int PreviousIndex = lstTaskSortOrder.SelectedIndex - 1;
			int CurrentIndex = lstTaskSortOrder.SelectedIndex;

			if (lstTaskSortOrder.SelectedIndex == -1) return;
			if (lstTaskSortOrder.SelectedIndex != 0)
			{
				PreviousItem = lstTaskSortOrder.Items[PreviousIndex];
				lstTaskSortOrder.Items.RemoveAt(PreviousIndex);
				lstTaskSortOrder.Items.Insert(PreviousIndex + 1, PreviousItem);
				SaveSortOrderSettings();
			}
		}

		private void btnTaskSortOrderMoveDown_Click(object sender, System.EventArgs e)
		{
			ListItem NextItem;
			int NextIndex = lstTaskSortOrder.SelectedIndex + 1;
			int CurrentIndex = lstTaskSortOrder.SelectedIndex;

			if (lstTaskSortOrder.SelectedIndex == -1) return;
			if (lstTaskSortOrder.Items.Count == 1) return;
			if (lstTaskSortOrder.SelectedIndex != lstTaskSortOrder.Items.Count - 1)
			{
				NextItem = lstTaskSortOrder.Items[NextIndex];
				lstTaskSortOrder.Items.RemoveAt(NextIndex);
				lstTaskSortOrder.Items.Insert(NextIndex - 1, NextItem);
				SaveSortOrderSettings();
			}
		}

		private void btnDisplayAdd_Click(object sender, System.EventArgs e)
		{
			if (lstDisplayFrom.SelectedItem == null) return;
			if (lstDisplayTo.Items.FindByValue(lstDisplayFrom.SelectedItem.Value) != null) return; 
			lstDisplayTo.SelectedIndex = -1;
			lstDisplayTo.Items.Add(lstDisplayFrom.SelectedItem);
			SaveShowSettings();
		}

		private void btnDisplayRemove_Click(object sender, System.EventArgs e)
		{
			if (lstDisplayTo.SelectedItem == null) return;
			lstDisplayTo.Items.RemoveAt(lstDisplayTo.SelectedIndex);
			SaveShowSettings();
		}
		
		/// <summary>
		/// Writes the current sort order settings to the database
		/// </summary>
		private void SaveSortOrderSettings()
		{
			for (int i = 0; i < lstTaskSortOrder.Items.Count; i++)
			{
				tl.UpdateSortOrderPreferences(CurrentUser, Convert.ToInt32(lstTaskSortOrder.Items[i].Value), i);
			}
		}

		/// <summary>
		/// Writes the current show settings to the database
		/// </summary>
		private void SaveShowSettings()
		{
			tl.ClearStatusShowPreferences(CurrentUser);
			for (int i = 0; i < lstDisplayTo.Items.Count; i++)
			{
				tl.AddStatusShowPreference(CurrentUser, Convert.ToInt32(lstDisplayTo.Items[i].Value));
			}
		}

		private void cboTaskListToView_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (TaskListToDisplayList.Items.FindByValue("SpecificTaskList").Selected == true)
				tl.ChangeStartupTaskListID(CurrentUser, Convert.ToInt32(cboTaskListToView.SelectedItem.Value));
		}

		private void cboItemsToShow_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			tl.SetNumberOfItemsToDisplayPerPage(CurrentUser, cboItemsToShow.SelectedItem.Value);
		}

    private void chkShouldNotify_CheckedChanged(object sender, System.EventArgs e)
    {
      txtNotifyPeriod.Enabled = chkShouldNotify.Checked;
    }

    private void txtNotifyPeriod_TextChanged(object sender, System.EventArgs e)
    {
    
    }

    private void txtNotifyPeriod_Unload(object sender, System.EventArgs e)
    {

    }

    private void btnSaveNotification_Click(object sender, System.EventArgs e)
    {
      // Update the notify period if it is enabled
      CurrentUser.NotifyPeriod = Convert.ToInt32(txtNotifyPeriod.Text);
      CurrentUser.ShouldNotify = chkShouldNotify.Checked;
      tl.UpdateUserNotification(CurrentUser, CurrentUser.ShouldNotify, CurrentUser.NotifyPeriod);
      Session["CurrentUser"] = CurrentUser;
    }
	}
}

⌨️ 快捷键说明

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