2006年10月13日
主要部分:
<forums
defaultProvider="SqlForumsProvider" // 要使用的数据提供者类
defaultLanguage="zh-CN" // 网站使用的默认语言
forumFilesPath="/" // 论坛根路径
disableEmail="true" // 是否禁用邮件发送,依附于disableThreading
disableIndexing="false" // 是否禁用索引(要使用搜索功能,必须启用)
// 依附于disableThreading
disableThreading="false" // 是否禁用后台线程运行
threadIntervalStats="15" // 后台帖子索引运行间隔时间(分钟)
threadIntervalEmail="3" // 后台邮件发送运行间隔时间(分钟)
passwordEncodingFormat="unicode" // 密码编码格式
allowAutoUserRegistration="false" //
adminWindowsGroup="Administrators"
assignLocalAdminsAdminRole="false"
smtpServerConnectionLimit="-1"
enableLatestVersionCheck="false" // 允许版本检查
>
<add
name = "SqlForumsProvider" // 使用Sql Server数据提供者类
type = "AspNetForums.Data.SqlDataProvider, AspNetForums.SqlDataProvider"
// Sql Server数据提供者类的程序集
connectionString = "server={0};database={1};uid={2};pwd={3}"
// {0}数据库服务器名或IP;{1}数据库名称;{2}登录数据库用户ID;
// {3}登录数据库密码.
databaseOwner = "dbo" // 数据库所有者,dbo或{2}
/>
Asp.Net Forums 2.0.1数据库表简要说明
[表]
forums_AnonymousUsers
匿名用户
forums_BlockedIpAddresses
禁止的IP地址
forums_Censorship
脏字过滤
forums_CodeScheduleType
待查
forums_CodeServiceType
待查
forums_DisallowedNames
禁止用户注册的用户名
forums_EmailQueue
发送邮件序列
forums_Exceptions
系统异常
forums_ForumGroups
论坛组
forums_ForumPermissions
论坛权限
forums_ForumPingback
待查
forums_Favorites
用户收藏夹
forums_Forums
论坛
forums_ForumsRead
论坛用户读取标记
forums_Images
待查
forums_Messages
论坛消息,待查,并非用户相互发送的消息
forums_ModerationAction
论坛管理操作列表(审核,编辑帖子,移动贴子,删除贴子,锁定,精华等)
forums_ModerationAudit
论坛操作检查,与下表对应
forums_Moderators
论坛版主
forums_PostAttachments
论坛贴子附件
forums_PostEditNotes
贴子编辑记录
forums_PostRating
主题评估
forums_Posts
论坛贴子
forums_PostsArchive
论坛文章(目前版本未使用)
forums_PrivateMessages
论坛内部会员消息
forums_Ranks
用户等级
forums_Reports
论坛报告(目前版本未使用)
forums_Roles
论坛角色
forums_SearchBarrel
论坛搜索关键字
forums_SearchIgnoreWords
论坛搜索忽略关键字(目前版本未使用)
forums_ServiceSchedule
论坛服务计划(目前版本未使用)
forums_Services
论坛服务(目前版本未使用)
forums_SiteSettings
站点设置
forums_Smilies
论坛表情符号
forums_Styles
论坛风格(类CSS设置) (目前版本未使用)
forums_Threads
论坛主题
forums_ThreadsRead
用户已读主题
forums_TrackedForums
论坛跟踪(待查)
forums_TrackedThreads
论坛主题跟踪(订阅列表)
forums_UserAvatar
用户头像
forums_UserProfile
用户配置选项
forums_Users
论坛用户
forums_UsersInRoles
用户角色
forums_UsersOnline
注册用户在线列表
forums_ValueGroups
精华区域管理
forums_Version
论坛版本信息
forums_Vote
用户投票
forums_VoteOptions
投票选项
forums_statistics_Site
论坛统计信息
forums_statistics_User
论坛会员列表统计
nntp_Newsgroups
NNTP设置,待查
nntp_Posts
NNTP设置,待查
=================================================================
// SqlServer数据访问帮助类
=================================================================
// 名字空间: hiDotNet.Data
// 描 述: SqlServer数据访问帮助类.
// 日 期: 2006年3月14日
// 修订日期: 2006年3月17日
// 联 系: venjiang@msn.com
// 说 明: 实现SqlServer的快速访问
=================================================================
// 版权所有,hiDotNet.com 更多内容请访问: www.hiDotNet.com
=================================================================
[示例运行环境]
.Net Framework 2.0
Sql Server 2000
[步骤]
1.执行SetupDataBase.bat,安装示例数据库所需内容.
2.使用Vs2005打开SqlHelperTest.csproj,编译运行.
欢迎测试反馈.
示例截图:

帮助

点击下载
其实asp.net forums2就是像搭积木,现以收藏夹功能实例看一下asp.net forums的结构及组件设计,希望给朋友以参考。
示例:帖子收藏功能(by venjiang 20040912) √
一.增加资源文件项目
修改Web\Languages\zh-CN\Resources.xml,增加
<!-- 收藏夹 -->
<resource name = "MyFavorite_Title">收藏夹</resource>
<resource name = "MyFavorite_Description">我收藏的主题</resource>
<!-- 收藏夹-结束 -->
二.增加站点url
修改E:\WWW\cnforums0804\Web\SiteUrls.config,增加
<url name="user_MyFavorite" path="/User/MyFavorite.aspx" />
三.增加属性
修改Components\Components\SiteUrls.cs,增加
// 收藏夹 by venjiang 0911
public string MyFavorite
{
get { return paths["MyFavorite"]; }
}
四.修改相应的界面文件
修改Web\Themes\default\Skins\View-MyForums.ascx,
修改Web\Themes\default\Skins\View-PrivateMessages.ascx
修改Web\Themes\default\Skins\Skin-EditProfile.ascx
在UserPrivateMessages后增加
<td width="15"> </td>
<td id="1" class="ControlPanelTabInactive" align="center" nowrap>
<a href="<%=Globals.GetSiteUrls().MyFavorites%>"><%=ResourceManager.GetString("MyFavorites_Title")%></a>
</td>
修改: <td colspan=11 class="ControlPanelTabLine"><img width="1" height=1 alt=""></td>跨跃列数
五.增加相应文件
表现层1,收藏夹主视图
在web/user/目录增加MyFavorites.aspx,最终用户页面
在Controls\Views目录增加MyFavoritesView.cs,页面视图服务器控件(主要表现为页面处理逻辑)
界面视图:在Web\Themes\default\Skins中增加View-MyFavorites.ascx 收藏夹视图(主要表现为页面UI)
组件
在Components目录增加Favorites.cs(相当于业务逻辑层,加s表业务处理),此例中未在子目录Components/Components中增加Favorite.cs(相当于业务实体层,未加s表实体),因并不需要,完整的Asp.net forums模式应该还有这一层。
表现层2,用户点击收藏按钮后呈现的UI
(这个比较简单)
在web目录增加MyFavoritesAdd.aspx文件
处理加入收藏时服务器控件, 在Controls目录增加MyFavoritesAdd.cs(页面处理逻辑)
在Web\Themes\default\Skins中增加Skin-MyFavoritesAdd.ascx将主题加入收藏时的视图(UI)
六.数据库
增加表forums_Favorites
UserID int 4 0
ThreadID int 4 0
FavoriteDate datetime 8 0
创建存储过程forums_Favorites_CreateDelete
CREATE procedure forums_Favorites_CreateDelete
(
@UserID int,
@ThreadID int,
@Action int
)
AS
BEGIN
IF @Action = 0
BEGIN
-- Does the user already have the ability to see this thread?
IF EXISTS (SELECT UserID FROM forums_Favorites WHERE UserID = @UserID and ThreadID = @ThreadID)
return
INSERT INTO
forums_Favorites
VALUES
(
@UserID,
@ThreadID,
getdate()
)
RETURN
END
IF @Action = 2
BEGIN
DELETE
forums_Favorites
WHERE
UserID = @UserID AND
ThreadID = @ThreadID
RETURN
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
七.数据处理
1.Components\Provider\ForumsDataProvider.cs增加
#region 收藏夹
public abstract void CreateFavorites(ArrayList users, int threadID);
public abstract void DeleteFavorites(int userID, ArrayList deleteList);
#endregion
2. Data Providers\SqlDataProvider\SqlDataProvider.cs增加实现方法
#region #### 收藏夹 #### by venjiang 0912
/// <summary>
/// 追加主题到收藏夹
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="threadID">主题ID</param>
public override void CreateFavorites(int userID,int threadID)
{
using( SqlConnection myConnection = GetSqlConnection() )
{
SqlCommand myCommand = new SqlCommand(databaseOwner + ".forums_Favorites_CreateDelete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@Action", SqlDbType.Bit).Value = DataProviderAction.Create;
myCommand.Parameters.Add("@UserID", SqlDbType.Int);
myCommand.Parameters.Add("@ThreadID", SqlDbType.Int);
myConnection.Open();
myCommand.Parameters["@UserID"].Value = userID;
myCommand.Parameters["@ThreadID"].Value = threadID;
myCommand.ExecuteNonQuery();
}
}
/// <summary>
/// 从收藏夹中删除主题
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="deleteList">删除列表</param>
public override void DeleteFavorites(int userID, ArrayList deleteList)
{
// Create Instance of Connection and Command Object
using( SqlConnection myConnection = GetSqlConnection() )
{
SqlCommand myCommand = new SqlCommand(databaseOwner + ".forums_Favorites_CreateDelete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@Action", SqlDbType.Int).Value = DataProviderAction.Delete;
myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = userID;
myCommand.Parameters.Add("@ThreadID", SqlDbType.Int);
// Open the connection
myConnection.Open();
// Add multiple times
//
foreach (int threadID in deleteList)
{
myCommand.Parameters["@ThreadID"].Value = threadID;
myCommand.ExecuteNonQuery();
}
}
}
#endregion
3.在Data Providers\SqlDataProvider\SqlDataProvider.cs修改GetThreads方法,以支持收藏功能
#region #### Threads ####
// 增加贴子收藏 by venjiang 0911
public override ThreadSet GetThreads(
int forumID,
int pageIndex,
int pageSize,
int userID,
DateTime threadsNewerThan,
SortThreadsBy sortBy,
SortOrder sortOrder,
ThreadStatus threadStatus,
ThreadUsersFilter userFilter,
bool activeTopics,
bool unreadOnly,
bool unansweredOnly,
bool returnRecordCount,
// 增加新参数,是否仅显示收藏的主题
bool favoriteOnly
)
{
// Create Instance of Connection and Command Object
//
using( SqlConnection connection = GetSqlConnection() ) {
SqlCommand command = new SqlCommand(databaseOwner + ".forums_Threads_GetThreadSet", connection);
command.CommandType = CommandType.StoredProcedure;
ThreadSet threadSet = new ThreadSet();
StringBuilder sqlCountSelect = new StringBuilder("SELECT count(T.ThreadID) ");
StringBuilder sqlPopulateSelect = new StringBuilder("SELECT T.ThreadID, HasRead = ");
StringBuilder fromClause = new StringBuilder(" FROM " + this.databaseOwner + ".forums_Threads T ");
StringBuilder whereClause = new StringBuilder(" WHERE ");
StringBuilder orderClause = new StringBuilder(" ORDER BY ");
// 增加收藏判断 by venjiang 0911
if (favoriteOnly == true)
{
fromClause.Append("," + this.databaseOwner + ".forums_Favorites Fav ");
}
// Ensure DateTime is min value for SQL
//
threadsNewerThan = SqlDataProvider.GetSafeSqlDateTime(threadsNewerThan);
// Construct the clauses
#region Constrain Forums
// Contrain the selectivness to a set of specified forums. The ForumID is our
// clustered index so we want this to be first
if (forumID > 0) {
whereClause.Append("T.ForumID = ");
whereClause.Append(forumID);
} else if (forumID < 0) {
whereClause.Append("(T.ForumID = ");
// Get a list of all the forums the user has access to
//
ArrayList forumList = Forums.GetForums(userID, false, true);
for (int i = 0; i < forumList.Count; i++) {
if ( ((Forum) forumList[i]).ForumID > 0 ) {
if ( (i + 1) < forumList.Count) {
whereClause.Append( ((Forum) forumList[i]).ForumID + " OR T.ForumID = ");
} else {
whereClause.Append( ((Forum) forumList[i]).ForumID );
whereClause.Append(")");
}
}
}
} else {
whereClause.Append("T.ForumID = 0 AND P.UserID = ");
whereClause.Append(userID);
whereClause.Append(" AND P.ThreadID = T.ThreadID ");
fromClause.Append(", " + this.databaseOwner + ".forums_PrivateMessages P ");
}
#endregion
#region Constrain Date
whereClause.Append(" AND StickyDate >= '");
whereClause.Append( threadsNewerThan.ToString( System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.SortableDateTimePattern ));
whereClause.Append(" '");
#endregion
#region Constain Approval
whereClause.Append(" AND IsApproved = 1");
#endregion
#region Constrain Read/Unread
if (userID > 0) {
sqlPopulateSelect.Append("(SELECT " + this.databaseOwner + ".HasReadPost(");
sqlPopulateSelect.Append(userID);
sqlPopulateSelect.Append(", T.ThreadID, T.ForumID)) ");
if (unreadOnly) {
whereClause.Append(" AND " + this.databaseOwner + ".HasReadPost(");
whereClause.Append(userID);
whereClause.Append(", T.ThreadID, T.ForumID) = 0");
}
} else {
sqlPopulateSelect.Append("0");
}
#endregion
#region Unanswered topics
if (unansweredOnly) {
whereClause.Append(" AND TotalReplies = 0 AND IsLocked = 0");
}
#endregion
#region Active topics
// 热门贴子
if (activeTopics) {
whereClause.Append(" AND TotalReplies > 2 AND IsLocked = 0 AND TotalViews > 50");
}
#endregion
#region 收藏
// 尽显示收藏的主题
if (favoriteOnly)
{
whereClause.Append(" AND T.ThreadID = Fav.ThreadID AND Fav.UserID = ");
whereClause.Append(userID);
}
#endregion
#region Users filter
if (userFilter != ThreadUsersFilter.All)
{
if ((userFilter == ThreadUsersFilter.HideTopicsParticipatedIn) || (userFilter == ThreadUsersFilter.HideTopicsNotParticipatedIn)) {
whereClause.Append(" AND ");
whereClause.Append(userID);
if (userFilter == ThreadUsersFilter.HideTopicsNotParticipatedIn)
whereClause.Append(" NOT");
whereClause.Append(" IN (SELECT UserID FROM " + this.databaseOwner + ".forums_Posts P WHERE P.ThreadID = T.ThreadID)");
} else {
if (userFilter == ThreadUsersFilter.HideTopicsByNonAnonymousUsers)
whereClause.Append(" AND 0 NOT");
else
whereClause.Append(" AND 0");
whereClause.Append("IN (SELECT UserID FROM " + this.databaseOwner + ".forums_Posts P WHERE ThreadID = T.ThreadID AND P.UserID = 0)");
}
}
#endregion
#region Thread Status
if (threadStatus != ThreadStatus.NotSet) {
switch (threadStatus) {
case ThreadStatus.Open:
whereClause.Append(" AND ThreadStatus = 0");
break;
case ThreadStatus.Closed:
whereClause.Append(" AND ThreadStatus = 0");
break;
case ThreadStatus.Resolved:
whereClause.Append(" AND ThreadStatus = 0");
break;
default:
break;
}
}
#endregion
#region Order By
switch (sortBy) {
case SortThreadsBy.LastPost:
if (sortOrder == SortOrder.Ascending) {
if (activeTopics || unansweredOnly)
orderClause.Append("ThreadDate");
else
orderClause.Append("IsSticky, StickyDate");
} else {
if (activeTopics || unansweredOnly)
orderClause.Append("ThreadDate DESC");
else
orderClause.Append("IsSticky DESC, StickyDate DESC");
}
break;
case SortThreadsBy.TotalRatings:
if (sortOrder == SortOrder.Ascending)
orderClause.Append("TotalRatings");
else
orderClause.Append("TotalRatings DESC");
break;
case SortThreadsBy.TotalReplies:
if (sortOrder == SortOrder.Ascending)
orderClause.Append("TotalReplies");
else
orderClause.Append("TotalReplies DESC");
break;
case SortThreadsBy.ThreadAuthor:
if (sortOrder == SortOrder.Ascending)
orderClause.Append("PostAuthor DESC");
else
orderClause.Append("PostAuthor");
break;
case SortThreadsBy.TotalViews:
if (sortOrder == SortOrder.Ascending)
orderClause.Append("TotalViews");
else
orderClause.Append("TotalViews DESC");
break;
}
#endregion
// Build the SQL statements
sqlCountSelect.Append(fromClause.ToString());
sqlCountSelect.Append(whereClause.ToString());
sqlPopulateSelect.Append(fromClause.ToString());
sqlPopulateSelect.Append(whereClause.ToString());
sqlPopulateSelect.Append(orderClause.ToString());
// Add Parameters to SPROC
//
command.Parameters.Add("@ForumID", SqlDbType.Int).Value = forumID;
command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = pageIndex;
command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pageSize;
command.Parameters.Add("@sqlCount", SqlDbType.NVarChar, 4000).Value = sqlCountSelect.ToString();
command.Parameters.Add("@sqlPopulate", SqlDbType.NVarChar, 4000).Value = sqlPopulateSelect.ToString();
command.Parameters.Add("@UserID", SqlDbType.Int).Value = userID;
command.Parameters.Add("@ReturnRecordCount", SqlDbType.Bit).Value = returnRecordCount;
// Execute the command
connection.Open();
SqlDataReader dr = command.ExecuteReader();
// Populate the ThreadSet
//
while (dr.Read()) {
// Add threads
//
if (forumID == 0)
threadSet.Threads.Add( ForumsDataProvider.PopulatePrivateMessageFromIDataReader (dr) );
else
threadSet.Threads.Add( ForumsDataProvider.PopulateThreadFromIDataReader(dr) );
}
// Do we need to return record count?
//
if (returnRecordCount) {
dr.NextResult();
dr.Read();
// Read the total records
//
threadSet.TotalRecords = (int) dr[0];
}
// Get the recipients if this is a request for
// the private message list
if ((forumID == 0) && (dr.NextResult()) ) {
Hashtable recipientsLookupTable = new Hashtable();
while(dr.Read()) {
int threadID = (int) dr["ThreadID"];
if (recipientsLookupTable[threadID] == null) {
recipientsLookupTable[threadID] = new ArrayList();
}
((ArrayList) recipientsLookupTable[threadID]).Add(ForumsDataProvider.PopulateUserFromIDataReader(dr) );
}
// Map recipients to the threads
//
foreach (PrivateMessage thread in threadSet.Threads) {
thread.Recipients = (ArrayList) recipientsLookupTable[thread.ThreadID];
}
}
dr.Close();
connection.Close();
return threadSet;
}
}
#endregion
八.增加新方法
在Components\Threads.cs增加新的重载方法,以不必修改原来的方法调用.
// 为了不影响以前的程序,单独加一个重载方法,以获得收藏夹主题
public static ThreadSet GetThreads(int forumID, int pageIndex, int pageSize, int userID, DateTime threadsNewerThan, SortThreadsBy sortBy, SortOrder sortOrder, ThreadStatus threadStatus, ThreadUsersFilter userFilter, bool activeTopics, bool unreadOnly, bool unansweredOnly, bool returnRecordCount,bool favoriteOnly) // 多了一个参数favoriteOnly
{
ForumContext forumContext = ForumContext.Current;
string anonymousKey = "Thread-" + forumID + pageSize.ToString() + pageIndex.ToString() + threadsNewerThan.DayOfYear.ToString() + sortBy + sortOrder + activeTopics.ToString() + unansweredOnly.ToString() + favoriteOnly.ToString();
ThreadSet threadSet;
// If the user is anonymous take some load off the db
//
if (userID == 0)
{
if (forumContext.Context.Cache[anonymousKey] != null)
return (ThreadSet) forumContext.Context.Cache[anonymousKey];
}
// Create Instance of the IDataProvider
//
ForumsDataProvider dp = ForumsDataProvider.Instance();
// Get the threads
//
threadSet = dp.GetThreads(forumID, pageIndex, pageSize, userID, threadsNewerThan, sortBy, sortOrder, threadStatus, userFilter, activeTopics, unreadOnly, unansweredOnly, returnRecordCount,favoriteOnly);
if (userID == 0)
forumContext.Context.Cache.Insert(anonymousKey, threadSet, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.Low, null);
return threadSet;
}
九.业务逻辑层
Components目录中增加Favorites.cs,实现主题的增加删除方法
public static void AddFavoritesPost (int userID,int threadID) {
ForumsDataProvider dp = ForumsDataProvider.Instance();
dp.CreateFavorites(userID, threadID);
}
/// <summary>
/// 删除收藏
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="deleteList">删除列表</param>
public static void DeleteFavorites (int userID, ArrayList deleteList) {
//
ForumsDataProvider dp = ForumsDataProvider.Instance();
dp.DeleteFavorites(userID, deleteList);
}
十.表现层调用
1.收藏夹主视图加载收藏主题列表
threadSet = Threads.GetThreads(forumID, pager.PageIndex, pager.PageSize, Users.GetUser().UserID, dateFilterValue, threadSortddl.SelectedValue, sortOrderddl.SelectedValue, ThreadStatus.NotSet, ThreadUsersFilter.All, false, hideReadPosts.SelectedValue, false, true,true);
注意最后一个参数是true,即返回收藏夹的数据集。
2.增加主题到收藏夹
Favorites.AddFavoritesPost(user.UserID,post.ThreadID);
HttpContext.Current.Response.Redirect(Globals.ApplicationPath+"/MyFavoritesAdd.aspx",true);
3.删除收藏的主题
Favorites.DeleteFavorites(…)
using System;
using System.Reflection;
namespace AbstractClass
{
//===============================================================
// 模拟Asp.Net Forums 2.0 数据提供者类实现,
// 以实现多数据库支持特性.
// 2004.8.2 by venjiang.
// ==============================================================
#region 主程序调用
class Class1
{
[STAThread]
static void Main(string[] args)
{
// 所有方法调用,都在BaseAbstact类进行,不涉及子类调用.
// 这样只要派生类(SubClass)能够重写基类相应方法就可以了.
// 调用基类静态方法
BaseAbstract.BaseOut();
// 调用派生类SubClassA
BaseAbstract ba=BaseAbstract.Instance("AbstractClass.SubClassA", "Power by venjiang.");
ba.BaseOut1();
ba=BaseAbstract.Instance("AbstractClass.SubClassA", "venjiang", 28);
ba.BaseOut2();
// 调用派生类SubClassB
ba=BaseAbstract.Instance("AbstractClass.SubClassB", "Power by venjiang.");
ba.BaseOut1();
ba=BaseAbstract.Instance("AbstractClass.SubClassB", "venjiang", 28);
ba.BaseOut2();
Console.Read();
}
}
#endregion
#region 相当于ForumsDataProvider类
public abstract class BaseAbstract
{
public static BaseAbstract Instance(string subClassType, string name)
{
Type myType=null;
// 获取派生类的类型,在Forums2中subClassType这个类型由Web.config文件中<providers>下的type指定.
myType = Type.GetType( subClassType );
// 构建构造函数参数类型数组
Type[] types = new Type[1];
types[0] = typeof(string);
// 获取指定参数的派生类的构造函数
ConstructorInfo ci = myType.GetConstructor(types);
// 指定派生类参数值
object[] paramArray = new object[1];
paramArray[0] = name;
return (BaseAbstract)ci.Invoke(paramArray);
}
public static BaseAbstract Instance(string subClassType, string name, int height)
{
Type myType=null;
// 获取派生类的类型
myType = Type.GetType( subClassType );
// 构建构造函数参数类型数组
Type[] types = new Type[2];
types[0] = typeof(string);
types[1] = typeof(int);
// 获取指定参数的派生类的构造函数
ConstructorInfo ci = myType.GetConstructor(types);
// 指定派生类参数值
object[] paramArray = new object[2];
paramArray[0] = name;
paramArray[1] = height;
return (BaseAbstract)ci.Invoke(paramArray);
}
public static void BaseOut()
{
// Type myType=null;
// myType = Type.GetType("AbstractClass.SubClassA");
Console.WriteLine("[基类]这是抽象类的静态方法");
// Console.WriteLine("测试{0}",myType.ToString());
}
public abstract void BaseOut1();
public abstract void BaseOut2();
}
#endregion
#region 相当于SqlDataProvider类
public class SubClassA:BaseAbstract
{
private string _name="";
private int _height=0;
public SubClassA(string name)
{
_name=name;
}
public SubClassA(string name,int height)
{
_name=name;
_height=height;
}
public override void BaseOut1()
{
Console.WriteLine("[派生类A]重写基类BaseOut1方法,"+ _name);
}
public override void BaseOut2()
{
Console.WriteLine("[派生类A]重写基类BaseOut2方法,"+ _name + "," + _height.ToString());
}
}
#endregion
#region 相当于其它数据库支持类
public class SubClassB:BaseAbstract
{
private string _name="";
private int _height=0;
public SubClassB(string name)
{
_name=name;
}
public SubClassB(string name,int height)
{
_name=name;
_height=height;
}
public override void BaseOut1()
{
Console.WriteLine("[派生类B]重写基类BaseOut1方法,"+ _name);
}
public override void BaseOut2()
{
Console.WriteLine("[派生类B]重写基类BaseOut2方法,"+ _name + "," + _height.ToString());
}
}
#endregion
}
Pager类,用于分页, Controls\Utility\Pager.cs
首先增加成员变量:
/// venjiang:增加跳转页输入文本框
/// </summary>
TextBox gotoPage;
/// <summary>
/// venjiang:增加跳转按钮
/// </summary>
LinkButton gotoButton;
其次增加控件:
/// <summary>
/// 跳转按钮
/// </summary>
void AddGotoButton()
{
this.gotoButton=new LinkButton();
this.gotoButton.ID="GoTo";
this.gotoButton.Text="Go";
this.gotoButton.Click += new System.EventHandler(PageIndex_Click);
Controls.Add(gotoButton);
}
/// <summary>
/// 增加跳转页输入框
/// </summary>
void AddGotoPage()
{
this.gotoPage=new TextBox();
this.gotoPage.Width=30;
this.gotoPage.ID="GoToPage";
//this.gotoPage.Text="3";
this.gotoPage.TextChanged += new System.EventHandler(PageText_Change);
//this.gotoPage.EnableViewState=true;
Controls.Add(gotoPage);
}
增加跳转页文本框文本改变事件:
void PageText_Change(Object sender,EventArgs e)
{
int i = 1;
try
{
i = Convert.ToInt32(this.gotoPage.Text.Trim().ToString());
if(i < 1)
{
i = 1;
this.gotoPage.Text="1";
}
if(i > CalculateTotalPages())
{
i = CalculateTotalPages();
this.gotoPage.Text=i.ToString();
}
}
catch
{
this.gotoPage.Text="";
return;
}
this.gotoButton.CommandArgument = (i-1).ToString();
}
增加呈现方法:
void RenderGotoPage(HtmlTextWriter writer)
{
Literal l,m;
l = new Literal();
l.Text = " ";
l.RenderControl(writer);
this.gotoPage.RenderControl(writer);
this.gotoButton.RenderControl(writer);
m = new Literal();
m.Text = " ";
m.RenderControl(writer);
}
最后将所创建的方法分别添加到相应用方法中:
在CreateChildControls()方法尾部,增加this.AddGotoPage();this.AddGotoButton();
Render(…)方法尾部,增加this.RenderGotoPage(writer);