📄 default.aspx.cs
字号:
using System;
using System.Collections;
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.Web.Security;
using Park.Common;
namespace Park
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class MainPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList CommonTask;
protected System.Web.UI.WebControls.DataList SpecialTask;
protected System.Web.UI.WebControls.DataList MinorTask;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.HtmlControls.HtmlTableCell Content;
#region main
/// <summary>
/// using ParkSetting to get UserView
/// and initialize
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Page_Load(object sender, System.EventArgs e)
{
#if !Debug
try
{
#endif
// 处理用户提交动作
ProcessLastContent();
// 建立用户视图任务列表
BuildUI();
// 得到中心视图控件名称
GetRightContent();
// 检查权限
CheckContentRight();
//添加主视图
#if !Debug
}
catch(Exception)
{
ContentControl = @"Module/error.ascx";
}
#endif
LoadControl();
this.DataBind();
}
#endregion
#region completed
/// <summary>
/// 加载中心视图控件
/// </summary>
private void LoadControl()
{
Control control;
//添加主视图
#if !Debug
try
{
#endif
control=Page.LoadControl( ContentControl );
Content.Controls.Add( control );
if( control is IProcessable)
{
Session[SessionKey.LastContent] = ContentControl;
/*Debug
output.Text = ContentControl;//((Task)settings.FirstIndex[1]).Content;
*/
}
else
Session[SessionKey.LastContent] = null;
#if !Debug
}
catch (Exception)
{
ContentControl = @"Module/error.ascx";
Content.Controls.Add( Page.LoadControl( ContentControl ) );
Session[SessionKey.LastContent] = null;
}
#endif
}
/// <summary>
/// 处理用户提交动作
/// </summary>
private void ProcessLastContent()
{
//将Session[SessionKey.LastContent]中记录的控件,
//重新加载并调用Process方法,用来处理用户提交的表单内容,并更改数据库.
lastcontent = (string)Session[SessionKey.LastContent];
Session[SessionKey.LastContent] = null;
if( lastcontent==null || lastcontent.Equals("")) return ;
Control control = Page.LoadControl( lastcontent );
if(control is IProcessable)
{//调用控件中process方法实现事件处理
((IProcessable)control).Process();
}
control.Dispose();
}
/// <summary>
/// 检查权限,调用UserDB的CheckContentRight方法
/// </summary>
private void CheckContentRight()
{
if (! UserDB.CheckContentRight(Role,ContentControl,out nextcontent) )
ContentControl = @"Module/AccessDenied.ascx";
}
/// <summary>
/// 得到中心视图控件名称
/// </summary>
private void GetRightContent()
{
string content = Request["Content"];
if(!(content==null||content.Equals("")))
{
ContentControl = content;
Session[SessionKey.ChangeContent] = content;
return;
}
content = Request[QueryKey.ChangeContent];
if(content == null || content.Equals("") ) content = (string)Session[SessionKey.ChangeContent];
if(content==null||content.Equals("")) return;
else ContentControl = content;
Session[SessionKey.ChangeContent] = content;
}
/// <summary>
/// 建立用户视图任务列表
/// </summary>
private void BuildUI()
{
//Initialize User Page View
// Get roles from UserRoles table, and add to cookie
role=UserDB.GetRole(User.Identity.Name);
//获取用户当前操作列表的选择
string childindex = Request[ QueryKey.ChangeChildIndex ];
if(childindex == null || childindex.Equals("") ) childindex = (string)Session[SessionKey.ChangeChildIndex];
//获取用户操作权限列表
ParkSettings settings = new ParkSettings( role , childindex);
//绑定数据源
CommonTask.DataSource = settings.FirstIndex;
SpecialTask.DataSource = settings.SecondIndex;
MinorTask.DataSource = settings.ThirdIndex;
//通过用户是否有操作设置DataList是否可见
if( settings.View.FirstIndex.Equals("") ) CommonTask.Visible=false;
if( settings.View.SecondIndex.Equals("") ) SpecialTask.Visible=false;
if( settings.View.ThirdIndex.Equals("") && ( childindex==null || childindex.Equals("") ) ) MinorTask.Visible=false;
ContentControl = settings.View.Content;
//记录用户当前操作列表的选择
Session[SessionKey.ChangeChildIndex] = childindex;
}
/// <summary>
/// 用户ID
/// </summary>
public string UserName
{
get
{
if(HttpContext.Current == null) return "";
return HttpContext.Current.User.Identity.Name;
}
}
protected string role;
/// <summary>
/// 用户角色
/// </summary>
public string Role
{
get
{
return role;
}
}
protected string lastcontent;
/// <summary>
/// 上一个视图
/// </summary>
public string LastContent
{
get
{
return lastcontent;
}
}
protected string content;
/// <summary>
/// 当前视图
/// </summary>
public string ContentControl
{
get
{
return content;
}
set
{
if(hasError) return;
content = value;
}
}
private string nextcontent;
/// <summary>
/// 下个视图
/// </summary>
public string NextContent
{
get
{
return nextcontent;
}
}
public bool HasError
{
get
{
return hasError;
}
}
public string ErrorMessage
{
set
{
if ( hasError ) return;
hasError = true;
Message.Text = value;
}
}
private bool hasError = false;
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.CommonTask.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.CommonTask_ItemDataBound);
this.SpecialTask.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.SpecialTask_ItemDataBound);
this.MinorTask.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.MinorTask_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region highlightened
private void CommonTask_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
//修改当用户单击通用任务时,将选中的行显示不同的颜色
switch(e.Item.ItemType)
{
case ListItemType.AlternatingItem :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
case ListItemType.Item :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
default:
break;
}
}
private void SpecialTask_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
//修改当用户单击用户任务时,将选中的行显示不同的颜色
switch(e.Item.ItemType)
{
case ListItemType.AlternatingItem :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl)||((Task)e.Item.DataItem).ChildIndexName.Equals(Session[SessionKey.ChangeChildIndex]))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
case ListItemType.Item :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl)||((Task)e.Item.DataItem).ChildIndexName.Equals(Session[SessionKey.ChangeChildIndex]))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
default:
break;
}
}
private void MinorTask_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{//修改当用户单击用户子任务时,将选中的行显示不同的颜色
switch(e.Item.ItemType)
{
case ListItemType.AlternatingItem :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
case ListItemType.Item :
if ( ((Task)e.Item.DataItem).Content.Equals(ContentControl))
e.Item.BackColor = Color.LightGoldenrodYellow;
break;
default:
break;
}
}
#endregion highlightened
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -