📄 tablayout.aspx.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 MyStarterKit.Portal.Web
{
/// <summary>
/// TabLayout 的摘要说明。
/// </summary>
public class TabLayout : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox tabName;
protected System.Web.UI.WebControls.CheckBoxList authRoles;
protected System.Web.UI.WebControls.CheckBox showMobile;
protected System.Web.UI.WebControls.TextBox mobileTabName;
protected System.Web.UI.WebControls.DropDownList moduleType;
protected System.Web.UI.WebControls.TextBox moduleTitle;
protected System.Web.UI.WebControls.LinkButton AddModuleBtn;
protected System.Web.UI.WebControls.ListBox leftPane;
protected System.Web.UI.WebControls.ImageButton LeftUpBtn;
protected System.Web.UI.WebControls.ImageButton LeftRightBtn;
protected System.Web.UI.WebControls.ImageButton LeftDownBtn;
protected System.Web.UI.WebControls.ImageButton LeftEditBtn;
protected System.Web.UI.WebControls.ImageButton LeftDeleteBtn;
protected System.Web.UI.WebControls.ListBox contentPane;
protected System.Web.UI.WebControls.ImageButton ContentUpBtn;
protected System.Web.UI.WebControls.ImageButton ContentLeftBtn;
protected System.Web.UI.WebControls.ImageButton ContentRightBtn;
protected System.Web.UI.WebControls.ImageButton ContentDownBtn;
protected System.Web.UI.WebControls.ImageButton ContentEditBtn;
protected System.Web.UI.WebControls.ImageButton ContentDeleteBtn;
protected System.Web.UI.WebControls.ListBox rightPane;
protected System.Web.UI.WebControls.ImageButton RightUpBtn;
protected System.Web.UI.WebControls.ImageButton RightLeftBtn;
protected System.Web.UI.WebControls.ImageButton RightDownBtn;
protected System.Web.UI.WebControls.ImageButton RightEditBtn;
protected System.Web.UI.WebControls.ImageButton RightDeleteBtn;
protected System.Web.UI.WebControls.LinkButton applyBtn;
int tabId = 0;
protected ArrayList leftList;
protected ArrayList contentList;
protected ArrayList rightList;
private void Page_Load(object sender, System.EventArgs e)
{
// Verify that the current user has access to access this page
// 用户角色为Admins的才能访问该管理模块,否则重定向到EditAccessDenied.aspx
if (PortalSecurity.IsInRoles("Admins") == false)
{
Response.Redirect("~/Admin/EditAccessDenied.aspx");
}
// 获取编辑的tabid
if (Request.Params["tabid"] != null)
{
tabId = Int32.Parse(Request.Params["tabid"]);
}
if (!Page.IsPostBack)
{
BindData();
}
}
/// <summary>
/// 为页面中的控件赋初值
/// </summary>
private void BindData()
{
// 从HttpContext中获取全局设置对象
// 从HttpContext中获取全局设置对象
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
// 因为当前请求是Response.Redirect("~/Admin/TabLayout.aspx?tabid=" + t.TabId);,它触发Global.asax中的Application_BeginRequest事件,就设定了要编辑的tabid为当前活动标签
// 所以取出当前活动标签就是要编辑的标签
TabSettings tab = portalSettings.ActiveTab;
// 为标签名称,移动浏览器上显示的标签名称,是否在移动设备浏览器上显示等控件赋初值
tabName.Text = tab.TabName;
mobileTabName.Text = tab.MobileTabName;
showMobile.Checked = tab.ShowMobile;
// 读角色信息,显示授权角色复选框列表
RolesDB rolesObj = new RolesDB();
SqlDataReader roles = rolesObj.GetPortalRoles(portalSettings.PortalId);
// 清除已经存在的角色复选框列表项
authRoles.Items.Clear();
// 给出默认的All Users项
ListItem allItem = new ListItem();
allItem.Text = "All Users";
// 如果该标签可以被All Users访问,则勾选它
if (tab.AuthorizedRoles.LastIndexOf("All Users") > -1)
{
allItem.Selected = true;
}
//将All Users项添加到复选列表中
authRoles.Items.Add(allItem);
// 循环添加从数据库中读取的角色信息到复选列表中
while(roles.Read())
{
ListItem item = new ListItem();
item.Text = (String) roles["RoleName"];
item.Value = roles["RoleID"].ToString();
if ((tab.AuthorizedRoles.LastIndexOf(item.Text)) > -1)
{
item.Selected = true;
}
authRoles.Items.Add(item);
}
// 添加组织模块区
// 获取当前站点下的全部用户模版和管理模板,绑定到模块类型下列框中
Configuration config = new Configuration();
moduleType.DataSource = config.GetModuleDefinitions(portalSettings.PortalId);
moduleType.DataBind();
// 右边框架列表中的用户模块内容
rightList = GetModules("RightPane");
rightPane.DataBind();
// 中间框架列表中的用户模块内容
contentList = GetModules("ContentPane");
contentPane.DataBind();
// 右边框架列表中的用户模块内容
leftList = GetModules("LeftPane");
leftPane.DataBind();
}
/// <summary>
/// 获取指定框架中的模块内容
/// </summary>
/// <param name="pane"></param>
/// <returns></returns>
private ArrayList GetModules (String pane)
{
// 从HttpContext中获取全局设置对象
// 从HttpContext中获取全局设置对象
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
// 模块ArrayList
ArrayList paneModules = new ArrayList();
// 循环添加指定框架中用户模块内容
foreach (ModuleSettings module in portalSettings.ActiveTab.Modules)
{
if ((module.PaneName).ToLower() == pane.ToLower())
{
ModuleItem m = new ModuleItem();
m.ModuleTitle = module.ModuleTitle;
m.ModuleId = module.ModuleId;
m.ModuleDefId = module.ModuleDefId;
m.ModuleOrder = module.ModuleOrder;
paneModules.Add(m);
}
}
return paneModules;
}
/// <summary>
/// 重新排列模块序号
/// </summary>
/// <param name="list"></param>
private void OrderModules (ArrayList list)
{
int i = 1;
list.Sort();
// 按1,3,5……的顺序,原理和标签排序的一样
foreach (ModuleItem m in list)
{
m.ModuleOrder = i;
i += 2;
}
}
/// <summary>
/// 保存标签设置
/// </summary>
private void SaveTabData()
{
// 获取可访问该标签的角色信息
String authorizedRoles = "";
foreach(ListItem item in authRoles.Items)
{
if (item.Selected == true)
{
authorizedRoles = authorizedRoles + item.Text + ";";
}
}
// 从HttpContext中获取全局设置对象
PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
// 更新设置
Configuration config = new Configuration();
config.UpdateTab(portalSettings.PortalId, tabId, tabName.Text, portalSettings.ActiveTab.TabOrder, authorizedRoles, mobileTabName.Text, showMobile.Checked);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tabName.TextChanged += new System.EventHandler(this.TabSettings_Change);
this.authRoles.SelectedIndexChanged += new System.EventHandler(this.TabSettings_Change);
this.showMobile.CheckedChanged += new System.EventHandler(this.TabSettings_Change);
this.mobileTabName.TextChanged += new System.EventHandler(this.TabSettings_Change);
this.AddModuleBtn.Click += new System.EventHandler(this.AddModuleToPane_Click);
this.LeftUpBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.LeftRightBtn.Click += new System.Web.UI.ImageClickEventHandler(this.RightLeft_Click);
this.LeftDownBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.LeftEditBtn.Click += new System.Web.UI.ImageClickEventHandler(this.EditBtn_Click);
this.LeftDeleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.DeleteBtn_Click);
this.ContentUpBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.ContentLeftBtn.Click += new System.Web.UI.ImageClickEventHandler(this.RightLeft_Click);
this.ContentRightBtn.Click += new System.Web.UI.ImageClickEventHandler(this.RightLeft_Click);
this.ContentDownBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.ContentEditBtn.Click += new System.Web.UI.ImageClickEventHandler(this.EditBtn_Click);
this.ContentDeleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.DeleteBtn_Click);
this.RightUpBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.RightLeftBtn.Click += new System.Web.UI.ImageClickEventHandler(this.RightLeft_Click);
this.RightDownBtn.Click += new System.Web.UI.ImageClickEventHandler(this.UpDown_Click);
this.RightEditBtn.Click += new System.Web.UI.ImageClickEventHandler(this.EditBtn_Click);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -