?? default.aspx.cs
字號:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace BronzeMonkey.GeneralTaskList
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class TaskListIndex : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton lnkAdd;
protected System.Web.UI.WebControls.LinkButton lnkRefresh;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.DropDownList cboTaskLists;
//Our web service
private TaskList tl = new TaskList();
protected System.Web.UI.WebControls.LinkButton lnkLogOff;
protected System.Web.UI.WebControls.LinkButton lnkMyPreferences;
protected System.Web.UI.HtmlControls.HtmlGenericControl AdministrativeTasksHeader;
protected System.Web.UI.HtmlControls.HtmlTable AdministrativeTasksTable;
protected System.Web.UI.HtmlControls.HtmlImage imgManageTaskLists;
protected System.Web.UI.HtmlControls.HtmlAnchor lnkManageTaskLists;
protected System.Web.UI.HtmlControls.HtmlImage imgManageUsers;
protected System.Web.UI.HtmlControls.HtmlAnchor lnkManageUsers;
protected System.Web.UI.HtmlControls.HtmlImage imgManageApplication;
protected System.Web.UI.HtmlControls.HtmlImage imgManageNotification;
protected System.Web.UI.HtmlControls.HtmlAnchor lnkManageNotification;
protected System.Web.UI.HtmlControls.HtmlAnchor lnkManageApplication;
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)
{
CacheFontTagsForTaskSummary();
LoadTaskListDropDown(cboTaskLists);
DetermineMenusToShow();
ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
}
#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.lnkAdd.Click += new System.EventHandler(this.lnkAdd_Click);
this.lnkRefresh.Click += new System.EventHandler(this.lnkRefresh_Click);
this.lnkMyPreferences.Click += new System.EventHandler(this.lnkMyPreferences_Click);
this.lnkLogOff.Click += new System.EventHandler(this.lnkLogOff_Click);
this.cboTaskLists.SelectedIndexChanged += new System.EventHandler(this.cboTaskLists_SelectedIndexChanged);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DetermineMenusToShow()
{
lnkManageTaskLists.Visible = CurrentUser.IsManager; imgManageTaskLists.Visible = CurrentUser.IsManager;
lnkManageUsers.Visible = CurrentUser.IsAdministrator; imgManageUsers.Visible = CurrentUser.IsAdministrator;
lnkManageApplication.Visible = CurrentUser.IsAdministrator; imgManageApplication.Visible = CurrentUser.IsAdministrator;
lnkManageNotification.Visible = CurrentUser.IsAdministrator; imgManageNotification.Visible = CurrentUser.IsAdministrator;
AdministrativeTasksTable.Visible = false;
AdministrativeTasksHeader.Visible = false;
if (CurrentUser.IsManager || CurrentUser.IsAdministrator)
{
AdministrativeTasksTable.Visible = true;
AdministrativeTasksHeader.Visible = true;
}
}
private void LoadTaskListDropDown(DropDownList cboTaskLists)
{
SqlDataReader dr = tl.GetUserTaskLists(CurrentUser, CurrentUser.UserID);
cboTaskLists.Items.Clear();
while (dr.Read())
{
cboTaskLists.Items.Add(new ListItem(dr["TaskListName"].ToString(), dr["TaskListID"].ToString()));
}
cboTaskLists.SelectedIndex = -1;
if (Session["TaskListID"] != null)
{
if (cboTaskLists.Items.FindByValue(Session["TaskListID"].ToString()) != null)
cboTaskLists.Items.FindByValue(Session["TaskListID"].ToString()).Selected = true;
}
else
{
//Get the startup task list
int TaskListIDToShow;
TaskListIDToShow = tl.GetStartupTaskListID(CurrentUser);
if (cboTaskLists.Items.FindByValue(TaskListIDToShow.ToString()) != null)
cboTaskLists.Items.FindByValue(TaskListIDToShow.ToString()).Selected = true;
}
if (cboTaskLists.SelectedItem.Value != String.Empty) Session["TaskListID"] = Convert.ToInt32(cboTaskLists.SelectedItem.Value);
}
/// <summary>
/// Retrieve a list of the font tags that we flag our task summary headers with, and cache them
/// in Session[]. We do this so that we can draw the fonts appropriately when building the grid, and
/// we can do it dynamically by changing the text in the TaskListStatus table in the database.
/// The usercontrol TaskSummary.ascx uses the Session value Session["StatusFontFlagsCollection"] to
/// render the fonts on the grid.
/// </summary>
private void CacheFontTagsForTaskSummary()
{
NameValueCollection StatusFontFlags = new NameValueCollection();
SqlDataReader dr = tl.GetStatusList(CurrentUser);
while (dr.Read())
{
StatusFontFlags.Add(dr["Description"].ToString(), dr["FontFlags"].ToString());
}
Session["StatusFontFlagsCollection"] = StatusFontFlags;
}
/// <summary>
/// Retrieves a list of the status codes in the database, and uses them to populate
/// a drop-down list. This gets executed when a user clicks the "View" button.
/// </summary>
/// <param name="StatusList">The DropDownList to populate with Status Codes.</param>
private void LoadStatusList(DropDownList StatusList)
{
SqlDataReader dr = tl.GetStatusList(CurrentUser);
while (dr.Read())
{
StatusList.Items.Add(new ListItem(dr["Description"].ToString(), dr["Value"].ToString()));
}
}
private void LoadCategoryList(DropDownList CategoryList)
{
SqlDataReader dr = tl.GetCategoryList(CurrentUser);
while( dr.Read() )
{
CategoryList.Items.Add(new ListItem(dr["Description"].ToString(), dr["CategoryID"].ToString()));
}
}
/// <summary>
/// Retrieves a task list and displays it on the DataGrid by using the DataGrid's
/// DataBinding functionality.
/// </summary>
/// <param name="TaskListID">The Task List to retrieve</param>
private void ShowTaskList(int TaskListID)
{
if (TaskListID == 0) return;
int PreviousPageIndex = DataGrid1.CurrentPageIndex;
DataGrid1.CurrentPageIndex = 0;
DataSet ds = tl.GetTaskList(CurrentUser, TaskListID);
DataView dv = ds.Tables[0].DefaultView;
if (Session["TaskListSort"] != null) dv.Sort = Session["TaskListSort"].ToString();
string NumberOfItemsToDisplay = tl.GetNumberOfItemsToDisplayPerPage(CurrentUser);
if (NumberOfItemsToDisplay == "All" && dv.Count > 0)
DataGrid1.PageSize = dv.Count;
else if(NumberOfItemsToDisplay != "All" && dv.Count > 0)
DataGrid1.PageSize = Convert.ToInt32(NumberOfItemsToDisplay);
else
DataGrid1.PageSize = 20; // default if there are no items to display.
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
DataGrid1.Columns[1].Visible = false;
if (DataGrid1.PageCount == 1)
DataGrid1.PagerStyle.Visible = false;
else
DataGrid1.PagerStyle.Visible = true;
if (PreviousPageIndex > (DataGrid1.PageCount - 1))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -