📄 sectionutility.cs
字号:
return CalculateSections( dstSections );
}
//*********************************************************************
//
// CalculateSections Method
//
// Calculate section information such as section paths and
// inherited properties by iterating through each
// row in a DataSet containing section rows.
//
//*********************************************************************
public static SectionCollection CalculateSections(DataSet dstSections) {
SectionCollection sectionCollection = new SectionCollection();
DataTable dtblSections = dstSections.Tables["Sections"];
DataTable dtblSectionSecurity = dstSections.Tables["SectionSecurity"];
DataTable dtblSectionWebBoxes = dstSections.Tables["SectionWebBoxes"];
DataTable dtblSectionWebServiceBoxes = dstSections.Tables["SectionWebServiceBoxes"];
DataRow[] drowRoles;
DataRow[] drowWebBoxes;
DataRow[] drowWebServiceBoxes;
// Add section_path column to Section DataSet
dtblSections.Columns.Add( "section_path" );
// Calculated inherited properties for each section
foreach (DataRow drowSection in dtblSections.Rows)
{
// skip parentless sections
if (!IsParentless(drowSection, dtblSections) ) {
drowSection["section_path"] = CalculateSectionPath( drowSection, dstSections );
drowSection["section_pageMetaKeys"] = GetInheritedSectionMetaKeys( drowSection, dstSections );
drowSection["section_pageMetaDesc"] = GetInheritedSectionMetaDesc( drowSection, dstSections );
drowSection["section_logo"] = GetInheritedSectionPageLogo( drowSection, dstSections );
drowSection["section_footer"] = GetInheritedSectionFooter( drowSection, dstSections );
drowSection["section_pageSkin"] = GetInheritedSectionPageSkin( drowSection, dstSections );
drowSection["section_pageStyle"] = GetInheritedSectionPageStyle( drowSection, dstSections );
drowSection["section_transformations"] = CalculateTransformations(drowSection, dstSections);
// Retrieve roles
drowRoles = dtblSectionSecurity.Select( String.Format("ss_sectionid={0}", drowSection["section_id"]) );
// Retrieve Web Boxes
drowWebBoxes = dtblSectionWebBoxes.Select( String.Format("sw_sectionid={0}", drowSection["section_id"]) );
// Retrieve Web Service Boxes
drowWebServiceBoxes = dtblSectionWebServiceBoxes.Select( String.Format("sw_sectionid={0}", drowSection["section_id"]) );
// Add to section collection
sectionCollection.Add( (string)drowSection["section_path"], new SectionInfo(drowSection, drowRoles, drowWebBoxes, drowWebServiceBoxes) );
}
}
// We have to go through a second time to determine inheritance for Web Boxes and Web Service Boxes
foreach (SectionInfo objSectionInfo in sectionCollection.GetOrderedSections()) {
if (objSectionInfo.IsWebBoxesInherited)
objSectionInfo.WebBoxes = GetInheritedWebBoxes(objSectionInfo, sectionCollection);
if (objSectionInfo.IsWebServiceBoxesInherited)
objSectionInfo.WebServiceBoxes = GetInheritedWebServiceBoxes(objSectionInfo, sectionCollection);
}
return sectionCollection;
}
//*********************************************************************
//
// IsParentLess
//
// Returns true when section does have a parent. This can happen
// when the parent section is disabled, so we must climb the section
// tree up to the top.
//
//*********************************************************************
static bool IsParentless(DataRow drowSection, DataTable dtblSections) {
DataRow[] drowMatches = { drowSection };
string strMatchString;
while ( (int)drowMatches[0]["section_parentID"]!=-1) {
strMatchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dtblSections.Select( strMatchString );
if (drowMatches.Length == 0)
return true;
}
return false;
}
//*********************************************************************
//
// CalculateSectionPath Method
//
// Calculates the path (URL) for a section by climbing up the
// parent tree.
//
//*********************************************************************
public static string CalculateSectionPath(DataRow drowSection, DataSet dstSections) {
string strPath = "/default.aspx";
DataRow[] drowMatches = { drowSection };
string strMatchString;
while ( (int)drowMatches[0]["section_parentID"]!=-1) {
strPath = "/" + System.Web.HttpUtility.UrlEncode( (string)drowMatches[0]["section_name"] ) + strPath;
strMatchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dstSections.Tables[0].Select( strMatchString );
}
return CommunityGlobals.AppPath + strPath;
}
//*********************************************************************
//
// GetInheritedSectionMetaDesc Method
//
// Calculates the inherited meta desc for a section.
//
//*********************************************************************
public static string GetInheritedSectionMetaDesc(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_pageMetaDesc", dstSections );
}
//*********************************************************************
//
// GetInheritedSectionMetaKeys Method
//
// Calculates the inherited meta keys for a section.
//
//*********************************************************************
public static string GetInheritedSectionMetaKeys(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_pageMetaKeys", dstSections );
}
//*********************************************************************
//
// GetInheritedSectionPageLogo Method
//
// Calculates the inherited logo for a section.
//
//*********************************************************************
public static string GetInheritedSectionPageLogo(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_Logo", dstSections );
}
//*********************************************************************
//
// GetInheritedSectionFooter Method
//
// Calculates the inherited footer for a section.
//
//*********************************************************************
public static string GetInheritedSectionFooter(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_Footer", dstSections );
}
//*********************************************************************
//
// GetInheritedSectionPageSkin Method
//
// Calculates the inherited skin for a section.
//
//*********************************************************************
public static string GetInheritedSectionPageSkin(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_pageSkin", dstSections );
}
//*********************************************************************
//
// GetInheritedSectionStyle Method
//
// Calculates the inherited style for a section.
//
//*********************************************************************
public static string GetInheritedSectionPageStyle(DataRow drowSection, DataSet dstSections) {
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_pageStyle", dstSections );
}
//*********************************************************************
//
// GetInheritedWebBoxes Method
//
// Calculates the inherited Web boxes for a section.
//
//*********************************************************************
private static string[] GetInheritedWebBoxes(SectionInfo objSectionInfo, SectionCollection objSectionCollection) {
while (objSectionInfo.ParentSectionID != -1) {
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (objSectionInfo.WebBoxes != null)
return objSectionInfo.WebBoxes;
}
return null;
}
//*********************************************************************
//
// GetInheritedWebServiceBoxes Method
//
// Calculates the inherited Web boxes for a section.
//
//*********************************************************************
private static string[] GetInheritedWebServiceBoxes(SectionInfo objSectionInfo, SectionCollection objSectionCollection) {
while (objSectionInfo.ParentSectionID != -1) {
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (objSectionInfo.WebServiceBoxes != null)
return objSectionInfo.WebServiceBoxes;
}
return null;
}
//*********************************************************************
//
// GetInheritedSectionString Method
//
// Support method for calculating inherited section properties.
//
//*********************************************************************
private static string GetInheritedSectionString(int intSectionID, string strColName, DataSet dstSections) {
DataRow[] drowMatches;
string strMatchString;
strMatchString = "section_id=" + intSectionID.ToString();
drowMatches = dstSections.Tables[0].Select( strMatchString );
while ( ((string)drowMatches[0][strColName]).Trim()==String.Empty && (int)drowMatches[0]["section_parentID"]!=-1) {
strMatchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dstSections.Tables[0].Select( strMatchString );
}
return (string)drowMatches[0][strColName];
}
//*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -