📄 moduledefinitions.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;
namespace MyStarterKit.Portal.Web.admin
{
/// <summary>
/// ModuleDefinitions 的摘要说明。
/// </summary>
public class ModuleDefinitions : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox FriendlyName;
protected System.Web.UI.WebControls.RequiredFieldValidator Req1;
protected System.Web.UI.WebControls.TextBox DesktopSrc;
protected System.Web.UI.WebControls.RequiredFieldValidator Req2;
protected System.Web.UI.WebControls.TextBox MobileSrc;
protected System.Web.UI.WebControls.LinkButton updateButton;
protected System.Web.UI.WebControls.LinkButton cancelButton;
protected System.Web.UI.WebControls.LinkButton deleteButton;
int defId = -1;
private void Page_Load(object sender, System.EventArgs e)
{
// 用户角色为Admins的才能访问该管理模块,否则重定向到EditAccessDenied.aspx
if (PortalSecurity.IsInRoles("Admins") == false)
{
Response.Redirect("~/Admin/EditAccessDenied.aspx");
}
// 模板Id
if (Request.Params["defid"] != null)
{
defId = Int32.Parse(Request.Params["defid"]);
}
if (!Page.IsPostBack)
{
if (defId == -1)
{
// 新建模板,给出初始值
FriendlyName.Text = "New Definition";
DesktopSrc.Text = "DesktopModules/SomeModule.ascx";
MobileSrc.Text = "MobileModules/SomeModule.ascx";
}
else
{
// 获取要编辑的模板信息
Configuration config = new Configuration();
SiteConfiguration.ModuleDefinitionRow modDefRow = config.GetSingleModuleDefinition(defId);
FriendlyName.Text = modDefRow.FriendlyName;
DesktopSrc.Text = modDefRow.DesktopSourceFile;
MobileSrc.Text = modDefRow.MobileSourceFile;
}
}
}
/// <summary>
/// 更新模板信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdateBtn_Click(Object sender, EventArgs e)
{
if (Page.IsValid == true)
{
Configuration config = new Configuration();
if (defId == -1)
{
//新建
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
config.AddModuleDefinition(portalSettings.PortalId, FriendlyName.Text, DesktopSrc.Text, MobileSrc.Text);
}
else
{
//修改
config.UpdateModuleDefinition(defId, FriendlyName.Text, DesktopSrc.Text, MobileSrc.Text);
}
RadminUrl();
}
}
/// <summary>
/// 删除模板信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteBtn_Click(Object sender, EventArgs e)
{
Configuration config = new Configuration();
config.DeleteModuleDefinition(defId);
RadminUrl();
}
/// <summary>
/// 取消
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CancelBtn_Click(Object sender, EventArgs e)
{
RadminUrl();
}
/// <summary>
/// 重定向回管理页
/// </summary>
private void RadminUrl()
{
// 获取管理标签的索引adminIndex,管理标签默认为最后一个
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
int adminIndex = portalSettings.DesktopTabs.Count-1;
// 返回管理页
Response.Redirect("~/DesktopDefault.aspx?tabindex=" + adminIndex.ToString() + "&tabid=" + ((TabStripDetails)portalSettings.DesktopTabs[adminIndex]).TabId);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.updateButton.Click += new System.EventHandler(this.UpdateBtn_Click);
this.cancelButton.Click += new System.EventHandler(this.CancelBtn_Click);
this.deleteButton.Click += new System.EventHandler(this.DeleteBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -