📄 configuration.cs
字号:
using System;
using System.Configuration;
using System.Web;
using System.Data;
using System.Web.Caching;
using System.Data.SqlClient;
using System.Collections;
namespace MyStarterKit.Portal.Web
{
//*********************************************************************
//
// Configuration Class
//
// Class that encapsulates all data logic necessary to add/query/delete
// tab configuration settings, module configuration settings and module
// definition configuration settings from the PortalCfg.xml file.
//
//*********************************************************************
/// <summary>
/// 配置事务组件,控制配置文件数据集中各表的增/查/删等操作
/// </summary>
public class Configuration
{
#region 更新站点设置信息
//
// PORTAL
//
//*********************************************************************
//
// UpdatePortalInfo() Method <a name="UpdatePortalInfo"></a>
//
// The UpdatePortalInfo method updates the name and access settings for the portal.
// These settings are stored in the Xml file PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 更新站点设置信息
/// </summary>
/// <param name="portalId">站点Id</param>
/// <param name="portalName">站点名称</param>
/// <param name="alwaysShow">是否总是显示编辑按钮</param>
public void UpdatePortalInfo (int portalId, String portalName, bool alwaysShow)
{
// Obtain SiteSettings from Current Context
//从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Get first record of the "Global" element
// 找到当前站点的设置信息行
SiteConfiguration.GlobalRow globalRow = siteSettings.Global.FindByPortalId(portalId);
// Update the values
// 更新
globalRow.PortalId = portalId;
globalRow.PortalName = portalName;
globalRow.AlwaysShowEditButton = alwaysShow;
// Save the changes
// 保存设置
SaveSiteSettings();
}
#endregion
//
// TABS
//
#region 添加新的标签信息
//*********************************************************************
//
// AddTab Method <a name="AddTab"></a>
//
// The AddTab method adds a new tab to the portal. These settings are
// stored in the Xml file PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 添加新的标签信息
/// </summary>
/// <param name="portalId">门户站点Id</param>
/// <param name="tabName">新标签名称</param>
/// <param name="tabOrder">新标签位置</param>
/// <returns>新标签的Id</returns>
public int AddTab (int portalId, String tabName, int tabOrder)
{
// Obtain SiteSettings from Current Context
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Create a new TabRow from the Tab table
// 创建标签行
SiteConfiguration.TabRow newRow = siteSettings.Tab.NewTabRow();
// Set the properties on the new row
// 设置新的标签行
newRow.TabName = tabName;
newRow.TabOrder = tabOrder;
newRow.MobileTabName = String.Empty;
newRow.ShowMobile = true;
newRow.AccessRoles = "All Users;";
// Add the new TabRow to the Tab table
// 添加到Tab表中
siteSettings.Tab.AddTabRow(newRow);
// Save the changes
SaveSiteSettings();
// Return the new TabID
return newRow.TabId;
}
#endregion
#region 更新标签信息
//*********************************************************************
//
// UpdateTab Method <a name="UpdateTab"></a>
//
// The UpdateTab method updates the settings for the specified tab.
// These settings are stored in the Xml file PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 更新标签信息
/// </summary>
/// <param name="portalId"></param>
/// <param name="tabId"></param>
/// <param name="tabName"></param>
/// <param name="tabOrder"></param>
/// <param name="authorizedRoles"></param>
/// <param name="mobileTabName"></param>
/// <param name="showMobile"></param>
public void UpdateTab (int portalId, int tabId, String tabName, int tabOrder, String authorizedRoles, String mobileTabName, bool showMobile)
{
// Obtain SiteSettings from Current Context
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate tab in the Tab table and set the properties
SiteConfiguration.TabRow tabRow = siteSettings.Tab.FindByTabId(tabId);
tabRow.TabName = tabName;
tabRow.TabOrder = tabOrder;
tabRow.AccessRoles = authorizedRoles;
tabRow.MobileTabName = mobileTabName;
tabRow.ShowMobile = showMobile;
// Save the changes
SaveSiteSettings();
}
#endregion
#region 更新标签排序号
//*********************************************************************
//
// UpdateTabOrder Method <a name="UpdateTabOrder"></a>
//
// The UpdateTabOrder method changes the position of the tab with respect
// to other tabs in the portal. These settings are stored in the Xml
// file PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 更新标签排序号
/// </summary>
/// <param name="tabId"></param>
/// <param name="tabOrder"></param>
public void UpdateTabOrder (int tabId, int tabOrder)
{
// Obtain SiteSettings from Current Context
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate tab in the Tab table and set the property
SiteConfiguration.TabRow tabRow = siteSettings.Tab.FindByTabId(tabId);
tabRow.TabOrder = tabOrder;
// Save the changes
SaveSiteSettings();
}
#endregion
#region 删除标签信息
//*********************************************************************
//
// DeleteTab Method <a name="DeleteTab"></a>
//
// The DeleteTab method deletes the selected tab and its modules from
// the settings which are stored in the Xml file PortalCfg.xml. This
// method also deletes any data from the database associated with all
// modules within this tab.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
// + <a href="DeleteModule.htm" style="color:green">DeleteModule stored procedure</a>
//
//*********************************************************************
/// <summary>
/// 删除标签信息
/// </summary>
/// <param name="tabId"></param>
public void DeleteTab(int tabId)
{
//
// Delete the Tab in the XML file
// 删除XML文件中标签相关信息
// Obtain SiteSettings from Current Context
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate tab in the Tab table
SiteConfiguration.TabDataTable tabTable = siteSettings.Tab;
SiteConfiguration.TabRow tabRow = siteSettings.Tab.FindByTabId(tabId);
//
// Delete information in the Database relating to each Module being deleted
// 删除数据库中该标签相关的信息
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("Portal_DeleteModule", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterModuleID = new SqlParameter("@ModuleID", SqlDbType.Int, 4);
myConnection.Open();
foreach(SiteConfiguration.ModuleRow moduleRow in tabRow.GetModuleRows())
{
myCommand.Parameters.Clear();
parameterModuleID.Value = moduleRow.ModuleId;
myCommand.Parameters.Add(parameterModuleID);
// Open the database connection and execute the command
myCommand.ExecuteNonQuery();
}
// Close the connection
myConnection.Close();
// Finish removing the Tab row from the Xml file
// 从Xml文件中移出
tabTable.RemoveTabRow(tabRow);
// Save the changes
SaveSiteSettings();
}
#endregion
//
// MODULES
//
#region 修改模块排序号
//*********************************************************************
//
// UpdateModuleOrder Method <a name="UpdateModuleOrder"></a>
//
// The UpdateModuleOrder method updates the order in which the modules
// in a tab are displayed. These settings are stored in the Xml file
// PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 修改模块排序号
/// </summary>
/// <param name="ModuleId"></param>
/// <param name="ModuleOrder"></param>
/// <param name="pane"></param>
public void UpdateModuleOrder (int ModuleId, int ModuleOrder, String pane)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// 找到模块行的设置
SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(ModuleId);
// 赋新值
moduleRow.ModuleOrder = ModuleOrder;
moduleRow.PaneName = pane;
// Save the changes
SaveSiteSettings();
}
#endregion
#region 添加新的模块
//*********************************************************************
//
// AddModule Method <a name="AddModule"></a>
//
// The AddModule method adds Portal Settings for a new Module within
// a Tab. These settings are stored in the Xml file PortalCfg.xml.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
/// <summary>
/// 添加新的模块
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -