📄 configuration.cs
字号:
/// </summary>
/// <param name="tabId">所属标签Id</param>
/// <param name="moduleOrder">模块排序号</param>
/// <param name="paneName">显示在那个框架中</param>
/// <param name="title">标题</param>
/// <param name="moduleDefId">模板Id</param>
/// <param name="cacheTime">缓存时间</param>
/// <param name="editRoles">修改角色</param>
/// <param name="showMobile">是否显示在移动设备浏览器上</param>
/// <returns>新模块Id</returns>
public int AddModule(int tabId, int moduleOrder, String paneName, String title, int moduleDefId, int cacheTime, String editRoles, bool showMobile)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// 新建模块行
SiteConfiguration.ModuleRow newModule = siteSettings.Module.NewModuleRow();
// 设置模块行的值
newModule.ModuleDefId = moduleDefId;
newModule.ModuleOrder = moduleOrder;
newModule.ModuleTitle = title;
newModule.PaneName = paneName;
newModule.EditRoles = editRoles;
newModule.CacheTimeout = cacheTime;
newModule.ShowMobile = showMobile;
newModule.TabRow = siteSettings.Tab.FindByTabId(tabId);
// 添加新的一行到设置的Module表中
siteSettings.Module.AddModuleRow(newModule);
// Save the changes
SaveSiteSettings();
// 返回新模块If
return newModule.ModuleId;
}
#endregion
//*********************************************************************
//
// UpdateModule Method <a name="UpdateModule"></a>
//
// The UpdateModule method updates the Portal Settings for an existing
// 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>
//
//*********************************************************************
public int UpdateModule(int moduleId, int moduleOrder, String paneName, String title, int cacheTime, String editRoles, bool showMobile)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate Module in the Module table and update the properties
SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(moduleId);
moduleRow.ModuleOrder = moduleOrder;
moduleRow.ModuleTitle = title;
moduleRow.PaneName = paneName;
moduleRow.CacheTimeout = cacheTime;
moduleRow.EditRoles = editRoles;
moduleRow.ShowMobile = showMobile;
// Save the changes
SaveSiteSettings();
// Return the existing Module ID
return moduleId;
}
//*********************************************************************
//
// DeleteModule Method <a name="DeleteModule"></a>
//
// The DeleteModule method deletes a specified Module from the settings
// stored in the Xml file PortalCfg.xml. This method also deletes any
// data from the database associated with this module.
//
// 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>
//
//*********************************************************************
public void DeleteModule(int moduleId)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
//
// Delete information in the Database relating to 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();
parameterModuleID.Value = moduleId;
myCommand.Parameters.Add(parameterModuleID);
// Open the database connection and execute the command
myCommand.ExecuteNonQuery();
myConnection.Close();
// Finish removing Module
siteSettings.Module.RemoveModuleRow(siteSettings.Module.FindByModuleId(moduleId));
// Save the changes
SaveSiteSettings();
}
//*********************************************************************
//
// UpdateModuleSetting Method <a name="UpdateModuleSetting"></a>
//
// The UpdateModuleSetting Method updates a single module setting
// in the configuration file. If the value passed in is String.Empty,
// the Setting element is deleted if it exists. If not, either a
// matching Setting element is updated, or a new Setting element is
// created.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
public void UpdateModuleSetting(int moduleId, String key, String val)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate Module in the Module table
SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(moduleId);
// Find the first (only) settings element
SiteConfiguration.SettingsRow settingsRow;
if(moduleRow.GetSettingsRows().Length > 0 )
{
settingsRow = moduleRow.GetSettingsRows()[0];
}
else
{
// Add new settings element
settingsRow = siteSettings.Settings.NewSettingsRow();
// Set the parent relationship
settingsRow.ModuleRow = moduleRow;
siteSettings.Settings.AddSettingsRow(settingsRow);
}
// Find the child setting elements
SiteConfiguration.SettingRow settingRow;
SiteConfiguration.SettingRow[] settingRows = settingsRow.GetSettingRows();
if(settingRows.Length == 0)
{
// If there are no Setting elements at all, add one with the new name and value,
// but only if the value is not empty
if(val != String.Empty)
{
settingRow = siteSettings.Setting.NewSettingRow();
// Set the parent relationship and data
settingRow.SettingsRow = settingsRow;
settingRow.Name = key;
settingRow.Setting_Text = val;
siteSettings.Setting.AddSettingRow(settingRow);
}
}
else
{
// Update existing setting element if it matches
bool found = false;
Int32 i;
// Find which row matches the input parameter "key" and update the
// value. If the value is String.Empty, however, delete the row.
for(i=0; i < settingRows.Length; i++)
{
if(settingRows[i].Name == key)
{
if(val == String.Empty)
{
// Delete the row
siteSettings.Setting.RemoveSettingRow(settingRows[i]);
}
else
{
// Update the value
settingRows[i].Setting_Text = val;
}
found = true;
}
}
if(found == false)
{
// Setting elements exist, however, there is no matching Setting element.
// Add one with new name and value, but only if the value is not empty
if(val != String.Empty)
{
settingRow = siteSettings.Setting.NewSettingRow();
// Set the parent relationship and data
settingRow.SettingsRow = settingsRow;
settingRow.Name = key;
settingRow.Setting_Text = val;
siteSettings.Setting.AddSettingRow(settingRow);
}
}
}
// Save the changes
SaveSiteSettings();
}
//*********************************************************************
//
// GetModuleSettings Method <a name="GetModuleSettings"></a>
//
// The GetModuleSettings Method returns a hashtable of custom,
// module-specific settings from the configuration file. This method is
// used by some user control modules (Xml, Image, etc) to access misc
// settings.
//
// 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>
/// <returns></returns>
public static Hashtable GetModuleSettings(int moduleId)
{
// Create a new Hashtable
Hashtable _settingsHT = new Hashtable();
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate Module in the Module table
SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(moduleId);
// Find the first (only) settings element
if(moduleRow.GetSettingsRows().Length > 0)
{
SiteConfiguration.SettingsRow settingsRow = moduleRow.GetSettingsRows()[0];
if(settingsRow != null)
{
// Find the child setting elements and add to the hashtable
// 将设置值添加到hashtable中,如:图片地址,大小,XML/XSL的地址等
foreach(SiteConfiguration.SettingRow sRow in settingsRow.GetSettingRows())
{
_settingsHT[sRow.Name] = sRow.Setting_Text;
}
}
}
return _settingsHT;
}
//
// MODULE DEFINITIONS
//
//*********************************************************************
//
// GetModuleDefinitions() Method <a name="GetModuleDefinitions"></a>
//
// The GetModuleDefinitions method returns a list of all module type
// definitions for the portal.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
public DataRow[] GetModuleDefinitions(int portalId)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Find the appropriate Module in the Module table
return siteSettings.ModuleDefinition.Select();
}
//*********************************************************************
//
// AddModuleDefinition() Method <a name="AddModuleDefinition"></a>
//
// The AddModuleDefinition add the definition for a new module type
// to the portal.
//
// Other relevant sources:
// + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
// + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
//
//*********************************************************************
public int AddModuleDefinition(int portalId, String name, String desktopSrc, String mobileSrc)
{
// 从HttpContext中获取全局设置对象
SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];
// Create new ModuleDefinitionRow
SiteConfiguration.ModuleDefinitionRow newModuleDef = siteSettings.ModuleDefinition.NewModuleDefinitionRow();
// Set the parameter values
newModuleDef.FriendlyName = name;
newModuleDef.DesktopSourceFile = desktopSrc;
newModuleDef.MobileSourceFile = mobileSrc;
// Add the new ModuleDefinitionRow to the ModuleDefinition table
siteSettings.ModuleDefinition.AddModuleDefinitionRow(newModuleDef);
// Save the changes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -