📄 moduledefs.ascx.cs
字号:
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyStarterKit.Portal.Web
{
/// <summary>
/// ModuleDefs 的摘要说明。
/// </summary>
public class ModuleDefs : PortalModuleControl
{
protected System.Web.UI.WebControls.DataList defsList;
protected System.Web.UI.WebControls.LinkButton AddDefBtn;
private void Page_Load(object sender, System.EventArgs e)
{
// 用户角色为Admins的才能访问该管理模块,否则重定向到EditAccessDenied.aspx
if (PortalSecurity.IsInRoles("Admins") == false)
{
Response.Redirect("~/Admin/EditAccessDenied.aspx");
}
if (!Page.IsPostBack)
{
BindData();
}
}
/// <summary>
/// 添加新模板
/// </summary>
/// <param name="Sender"></param>
/// <param name="e"></param>
private void AddDef_Click(Object Sender, EventArgs e)
{
// 重定向到模板编辑页,defId=-1表示新建
Response.Redirect("~/Admin/ModuleDefinitions.aspx?defId=-1");
}
/// <summary>
/// 修改模板信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DefsList_ItemCommand(object sender, DataListCommandEventArgs e)
{
int moduleDefId = (int) defsList.DataKeys[e.Item.ItemIndex];
// 重定向到模板编辑页
Response.Redirect("~/Admin/ModuleDefinitions.aspx?defId=" + moduleDefId);
}
/// <summary>
/// 初始化控件数据
/// </summary>
private void BindData()
{
// 从HttpContext中获取全局设置对象
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
// 从配置文件中获取模板信息
Configuration config = new Configuration();
defsList.DataSource = config.GetModuleDefinitions(portalSettings.PortalId);
defsList.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.defsList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DefsList_ItemCommand);
this.AddDefBtn.Click += new System.EventHandler(this.AddDef_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -