⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sectionutility.cs

📁 ASP.NET精品全站程序SQL版.rar
💻 CS
📖 第 1 页 / 共 3 页
字号:



		//*********************************************************************
		//
		// AddSectionServiceSubscriptions Method
		//
		// Adds new services to the Community_SectionServiceSubscriptions table.
		//
		//*********************************************************************
		public static void AddSectionServiceSubscriptions(int sectionID, string[] serviceNames) 
		{
			// Setup db objects
			SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

			SqlCommand cmdDelete = new SqlCommand( "Community_ServicesDeleteServiceSubscriptions", con);
			cmdDelete.CommandType = CommandType.StoredProcedure;
			cmdDelete.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
			cmdDelete.Parameters.Add("@sectionID", sectionID);

			SqlCommand cmdAdd = new SqlCommand( "Community_ServicesAddServiceSubscription", con);
			cmdAdd.CommandType = CommandType.StoredProcedure;
			cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
			cmdAdd.Parameters.Add("@sectionID", sectionID);
			cmdAdd.Parameters.Add("@serviceName", SqlDbType.NVarChar);
           
			// Open connection
			con.Open();
            
			// Delete all roles from section of specified type
			cmdDelete.ExecuteNonQuery();
            
			// Add new roles
			foreach (string name in serviceNames) 
			{
				cmdAdd.Parameters["@serviceName"].Value = name;
				cmdAdd.ExecuteNonQuery();
			}
            
			// close connection
			con.Close();
		}



		//*********************************************************************
		//
		// GetSectionServiceSubscriptions Method
		//
		// Retrieves list of subscribed services to remote communities.
		//
		//*********************************************************************
		public static string[] GetSectionServiceSubscriptions(int sectionID) 
		{
			ArrayList colSubscriptions = new ArrayList();
            
			// Setup db objects
			SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

			SqlCommand cmd = new SqlCommand( "Community_SectionsGetSectionServiceSubscriptions", con);
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.Parameters.Add("@sectionID", sectionID);
            
			con.Open();
			SqlDataReader dr = cmd.ExecuteReader();
            
			while (dr.Read())
				colSubscriptions.Add(dr["ss_name"]);
			con.Close();
            
			return (string[])colSubscriptions.ToArray(typeof(string));
		}




		//*********************************************************************
		//
		// GetAllEnabledSections Method
		//
		// Gets all enabled sections from the cache, or if that fails,
		// from the database. 
		//
		//*********************************************************************
        

		public static SectionCollection GetAllEnabledSections() 
		{
			HttpContext Context = HttpContext.Current;

			SectionCollection sectionCollection = (SectionCollection)Context.Cache[ CommunityGlobals.CacheKey("Sections") ];
			if (sectionCollection == null) 
			{
				sectionCollection = GetAllEnabledSectionsFromDB();
				Context.Cache[ CommunityGlobals.CacheKey("Sections") ] = sectionCollection;
			}
			return sectionCollection;
		}



		//*********************************************************************
		//
		// GetAllSectionsFromDB Method
		//
		// Returns all sections from the database.
		//
		//*********************************************************************
        
		public static DataSet GetAllSectionsFromDB() 
		{
			SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetAllSections", CommunityGlobals.ConnectionString );
			dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
			dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
			DataSet dstSections = new DataSet();
			dadSections.Fill( dstSections );
			DataTable dtblSections = dstSections.Tables[0];
            
			// Add section_path column to Section DataSet
			dtblSections.Columns.Add( "section_path" );
            
			// Calculate path for each section
			foreach (DataRow drowSection in dtblSections.Rows)
				drowSection["section_path"] = CalculateSectionPath( drowSection, dstSections );
            
			return dstSections;
		}





		//*********************************************************************
		//
		// GetAllEnabledSectionsFromDB Method
		//
		// Gets all enabled sections from the database.
		//
		//*********************************************************************
        
		public static SectionCollection GetAllEnabledSectionsFromDB() 
		{
			SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetAllEnabledSections", CommunityGlobals.ConnectionString );
			dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
			dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

			SqlDataAdapter dadSectionSecurity = new SqlDataAdapter( "Community_SectionsGetAllSectionRoles", CommunityGlobals.ConnectionString );
			dadSectionSecurity.SelectCommand.CommandType = CommandType.StoredProcedure;
			dadSectionSecurity.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

			SqlDataAdapter dadSectionWebBoxes = new SqlDataAdapter( "Community_SectionsGetAllSectionWebBoxes", CommunityGlobals.ConnectionString );
			dadSectionWebBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
			dadSectionWebBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

			SqlDataAdapter dadSectionWebServiceBoxes = new SqlDataAdapter( "Community_SectionsGetAllSectionWebServiceBoxes", CommunityGlobals.ConnectionString );
			dadSectionWebServiceBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
			dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

			DataSet dstSections = new DataSet();
			dadSections.Fill( dstSections, "Sections" );
			dadSectionSecurity.Fill( dstSections, "SectionSecurity" );
			dadSectionWebBoxes.Fill( dstSections, "SectionWebBoxes" );
			dadSectionWebServiceBoxes.Fill( dstSections, "SectionWebServiceBoxes" );
            
			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);
					
					
					
					// SMR - Enh - Begin: Add fail over skin support
					drowSection["section_failOverPageSkin"] = GetInheritedSectionFailOverPageSkin( drowSection, dstSections );
					// SMR - Enh - End: Add fail over skin support
                    
					// 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);
					
					objSectionInfo.WebBoxDisplayMode = GetInheritedSectionWebBoxDisplayMode(objSectionInfo,sectionCollection);//SMR - Enh Add inherit web box display mode
				}

				if (objSectionInfo.IsWebServiceBoxesInherited)
				{
					objSectionInfo.WebServiceBoxes = GetInheritedWebServiceBoxes(objSectionInfo, sectionCollection);
					objSectionInfo.WebServiceBoxDisplayMode = GetInheritedSectionWebServiceBoxDisplayMode(objSectionInfo,sectionCollection);//SMR - Enh Add inherit web box display mode

				}
			}
			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 );
		}

		// SMR - Enh - Begin: Add fail over skin support
		public static string GetInheritedSectionFailOverPageSkin(DataRow drowSection, DataSet dstSections) 
		{
			return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_failOverPageSkin", dstSections );
		}
		// SMR - Enh - End: Add fail over skin support

		//*********************************************************************
		//
		// GetInheritedSectionStyle Method
		//
		// Calculates the inherited style for a section.
		//
		//*********************************************************************

		public static string GetInheritedSectionPageStyle(DataRow drowSection, DataSet dstSections) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -