📄 contentpageutility.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Collections;
using System.Web;
using System.Text.RegularExpressions;
//*********************************************************************
//
// ContentPageUtility Class
//
// Contains static methods for working with content pages.
//
//*********************************************************************
public class ContentPageUtility {
//*********************************************************************
//
// GetTotalRecords Method
//
// Returns the total number of visible content pages in a
// particular section.
//
//*********************************************************************
public static int GetTotalRecords(int sectionID) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGetTotal = new SqlCommand("Community_ContentPagesGetTotalRecords", conPortal);
cmdGetTotal.CommandType = CommandType.StoredProcedure;
cmdGetTotal.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
cmdGetTotal.Parameters.Add("@sectionID", sectionID);
conPortal.Open();
cmdGetTotal.ExecuteNonQuery();
int totalRecords = (int)cmdGetTotal.Parameters["@RETURN_VALUE"].Value;
conPortal.Close();
return totalRecords;
}
//*********************************************************************
//
// GetTotalRecordsWithInvisible Method
//
// Returns the total number of visible and invisible content pages in a
// particular section.
//
//*********************************************************************
public static int GetTotalRecordsWithInvisible(int sectionID) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGetTotal = new SqlCommand("Community_ContentPagesGetTotalRecordsWithInvisible", conPortal);
cmdGetTotal.CommandType = CommandType.StoredProcedure;
cmdGetTotal.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
cmdGetTotal.Parameters.Add("@sectionID", sectionID);
conPortal.Open();
cmdGetTotal.ExecuteNonQuery();
int totalRecords = (int)cmdGetTotal.Parameters["@RETURN_VALUE"].Value;
conPortal.Close();
return totalRecords;
}
//*********************************************************************
//
// GetPageInfoFromPageContentID Method
//
// Returns a PageInfo object from a file name. Checks whether
// file name is a number, if it is, then a content page is assumed.
//
//*********************************************************************
public static PageInfo GetPageInfoFromPageContentID(string requestFile, SectionInfo sectionInfo) {
// Attempt to convert request path to integer
string strContentID = Path.GetFileNameWithoutExtension( requestFile );
if (!CommunityGlobals.IsNumeric( strContentID ))
return null;
int intContentID = Int32.Parse( strContentID );
// Otherwise, we have a content page
ContentPageInfo _contentPageInfo = GetContentPageInfoFromDB( intContentID, sectionInfo.ID );
// Check whether it exists
if (_contentPageInfo == null)
return null;
return new PageInfo
(
_contentPageInfo.ContentPageID, // Page ID
String.Empty, // Page Name
_contentPageInfo.ParentID, // Page Parent ID
_contentPageInfo.PageType, // Page Type
_contentPageInfo.Title, // Page Title
_contentPageInfo.Description, // Page Description
_contentPageInfo.MetaDescription, // Page Meta Description
_contentPageInfo.MetaKeys, // Page Meta Keys
_contentPageInfo.PageContent // Page Content
);
}
//*********************************************************************
//
// GetContentPageInfoFromDB Method
//
// Returns a content page from the database given a
// particular ID.
//
//*********************************************************************
public static ContentPageInfo GetContentPageInfoFromDB(int contentID, int sectionID) {
ContentPageInfo _contentPageInfo = null;
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand( "Community_ContentPagesGetContentPage", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
cmdGet.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add( "@sectionID", sectionID );
cmdGet.Parameters.Add( "@contentPageID", contentID );
conPortal.Open();
SqlDataReader dr = cmdGet.ExecuteReader();
if (dr.Read())
_contentPageInfo = PopulateContentPageInfoFromSqlDataReader(dr);
conPortal.Close();
return _contentPageInfo;
}
//*********************************************************************
//
// PopulateContentPageInfoFromSqlDataReader Method
//
// Generates a ContentPageInfo object given a SqlDataReader.
//
//*********************************************************************
public static ContentPageInfo PopulateContentPageInfoFromSqlDataReader(SqlDataReader dr) {
ContentPageInfo _contentPageInfo = new ContentPageInfo();
_contentPageInfo.ContentPageID = (int)dr["contentPage_id"];
_contentPageInfo.ParentID = (int)dr["contentPage_parentID"];
_contentPageInfo.SectionID = (int)dr["contentPage_sectionID"];
_contentPageInfo.PageType = (int)dr["contentPage_pageType"];
_contentPageInfo.Title = (string)dr["contentPage_title"];
_contentPageInfo.Description = (string)dr["contentPage_description"];
_contentPageInfo.MetaDescription = (string)dr["contentPage_metaDesc"];
_contentPageInfo.MetaKeys = (string)dr["contentPage_metaKeys"];
_contentPageInfo.PageContent = (string)dr["PageType_pageContent"];
_contentPageInfo.ModerationStatus = (ModerationStatus)dr["contentPage_moderationStatus"];
return _contentPageInfo;
}
//*********************************************************************
//
// DeleteContentPage Method
//
// Deletes a content page from the database.
//
//*********************************************************************
public static void DeleteContentPage(int contentPageID, int sectionID) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmd = new SqlCommand( "Community_ContentPagesDeleteContentPage", conPortal);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( "@communityID", CommunityGlobals.CommunityID);
cmd.Parameters.Add( "@sectionID", sectionID );
cmd.Parameters.Add( "@contentPageID", contentPageID );
conPortal.Open();
cmd.ExecuteNonQuery();
conPortal.Close();
}
//*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -