/// <summary> /// 创建帖子 /// </summary> /// <param name="postInfo">帖子信息</param> /// <param name="postTableId">分表ID</param> /// <returns>帖子ID</returns> public static int CreatePost(PostInfo postInfo, string postTableId) { int postId = DatabaseProvider.GetInstance().CreatePost(postInfo, postTableId); //更新TTCache缓存中的用户信息 if (postInfo.Invisible == 0 && Users.appDBCache && Users.IUserService != null) { UserInfo userInfo = Users.IUserService.GetUserInfo(postInfo.Posterid); if (userInfo != null) { userInfo.Lastpost = postInfo.Postdatetime; userInfo.Lastpostid = postId; userInfo.Lastposttitle = postInfo.Title; userInfo.Posts = userInfo.Posts + 1; userInfo.Lastactivity = DateTime.Now.ToString(); userInfo.Newpm = 1; Users.IUserService.UpdateUser(userInfo); } } //更新Cache缓存中的用户信息 if (postInfo.Invisible == 0 && Topics.appDBCache && Topics.ITopicService != null) { Topics.ITopicService.ResetTopicByTid(postInfo.Tid); } //创建Cache缓存中的帖子信息(权限于当前正在使用的分表) if (appDBCache && IPostService != null && PostTables.GetPostTableId(postInfo.Tid) == postTableId) { postInfo.Pid = postId; IPostService.CreatePost(postInfo, postTableId); } return(postId); }
/// <summary> /// 获取指定条件的帖子DataSet /// </summary> /// <param name="_postpramsinfo">参数列表</param> /// <returns>指定条件的帖子DataSet</returns> public static List <ShowtopicPagePostInfo> GetPostList(PostpramsInfo postpramsInfo) { IDataReader reader; string postTableId = PostTables.GetPostTableId(postpramsInfo.Tid); if (!postpramsInfo.Condition.Equals("")) { reader = DatabaseProvider.GetInstance().GetPostListByCondition(postpramsInfo, postTableId); } else { //更新Cache缓存中的帖子信息(目前只对当前分表进行查询,这主要出于将所有分表数据转换对于某些中型论坛的服务器硬盘内存要求过高的暂时方案) if (postTableId == PostTables.GetPostTableId() && appDBCache && IPostService != null) { List <ShowtopicPagePostInfo> list = IPostService.GetPostList(postpramsInfo, postTableId); if (list != null && list.Count > 0) { return(list); } } reader = DatabaseProvider.GetInstance().GetPostList(postpramsInfo, postTableId); } return(LoadPostList(postpramsInfo, reader)); }
public static int UpdatePostAttachmentType(int tid, int pid, int attType) { string postTableId = PostTables.GetPostTableId(tid); //更新Cache缓存中的帖子信息 if (appDBCache && IPostService != null) { IPostService.UpdatePostAttachmentType(postTableId, pid, attType); } return(DatabaseProvider.GetInstance().UpdatePostAttachmentType(pid, postTableId, attType)); }
/// <summary> /// 通过主题ID得到主帖内容,此方法可继续扩展 /// </summary> /// <param name="tid"></param> /// <returns>ShowtopicPagePostInfo</returns> public static PostInfo GetTopicPostInfo(int tid) { PostInfo postInfo = new PostInfo(); IDataReader reader = DatabaseProvider.GetInstance().GetSinglePost(tid, PostTables.GetPostTableId(tid)); if (reader.Read()) { postInfo = LoadSinglePostInfo(reader); } reader.Close(); return(postInfo); }
/// <summary> /// 更新帖子的评分值 /// </summary> /// <param name="tid">主题ID</param> /// <param name="postidlist">帖子ID列表</param> /// <returns>更新的帖子数量</returns> public static int UpdatePostRateTimes(int tid, string postidlist) { string postTableId = PostTables.GetPostTableId(tid); int result = DatabaseProvider.GetInstance().UpdatePostRateTimes(postidlist, postTableId); //更新Cache缓存中的帖子信息 if (appDBCache && IPostService != null) { IPostService.UpdatePostRateTimes(postTableId, postidlist); } return(result); }
/// <summary> /// 删除指定附件id的附件同时更新主题和帖子中的附件个数 /// </summary> /// <param name="aid">附件id</param> /// <param name="pid">附件所属帖子id</param> /// <param name="tid">附件所属主题id</param> private static void DeleteAttachment(string aidlist, int pid, int tid) { if (appDBCache) { IAttachmentService.DeleteAttachment(aidlist); } DatabaseProvider.GetInstance().DelMyAttachmentByAid(aidlist); if (tid > 0) { if (DatabaseProvider.GetInstance().GetAttachmentCountByPid(pid) <= 0) { string postTableId = PostTables.GetPostTableId(tid); DatabaseProvider.GetInstance().UpdatePostAttachment(pid, postTableId, 0); if (Posts.appDBCache) { PostInfo postInfo = Posts.GetPostInfo(postTableId, pid); postInfo.Attachment = 0; Posts.IPostService.UpdatePost(postInfo, postTableId); } } if (DatabaseProvider.GetInstance().GetAttachmentCountByTid(tid) <= 0) { DatabaseProvider.GetInstance().UpdateTopicAttachment(tid, 0); if (Topics.appDBCache) { TopicInfo topicInfo = Topics.GetTopicInfo(tid, 0, 0); topicInfo.Attachment = 0; Topics.ITopicService.UpdateTopic(topicInfo); } } } }
/// <summary> /// 返回辩论帖子列表 /// </summary> /// <param name="postpramsInfo">参数对象</param> /// <param name="debateOpinion">辩论正反观点</param> /// <param name="postOrderType">排序类型</param> /// <returns></returns> public static List <ShowtopicPagePostInfo> GetDebatePostList(PostpramsInfo postpramsInfo, int debateOpinion, PostOrderType postOrderType) { IDataReader reader = DatabaseProvider.GetInstance().GetDebatePostList(postpramsInfo, debateOpinion, postpramsInfo.Pagesize, postpramsInfo.Pageindex, PostTables.GetPostTableId(postpramsInfo.Tid), postOrderType); return(Posts.LoadPostList(postpramsInfo, reader)); }
/// <summary> /// 获取ShowtopicPagePostInfo对象与ShowtopicPageAttachmentInfo对象列表 /// </summary> /// <param name="postPramsInfo">参数对象</param> /// <param name="attachmentList">输出附件列表</param> /// <returns></returns> public static ShowtopicPagePostInfo GetPostInfoWithAttachments(PostpramsInfo postPramsInfo, out List <ShowtopicPageAttachmentInfo> attachmentList) { attachmentList = new List <ShowtopicPageAttachmentInfo>(); //得到帖子对应主题的所有附件,因为ACCESS不支持存储过程,故此方法在ACCESS版中做了特殊处理 IDataReader attachmentReader; IDataReader reader = DatabaseProvider.GetInstance().GetSinglePost(out attachmentReader, postPramsInfo, PostTables.GetPostTableId(postPramsInfo.Tid)); //Access版运行此处逻辑 bool isAccess = false; if (attachmentReader == null) { attachmentReader = reader; } else { isAccess = true; } while (attachmentReader.Read()) { attachmentList.Add(Attachments.LoadSingleAttachmentInfo(attachmentReader)); } //bool next = false; //Access版运行此处逻辑 if (!isAccess) { reader.NextResult(); } ShowtopicPagePostInfo postInfo = null; if (reader.Read()) { postInfo = LoadSingleShowtopicPagePostInfo(reader); } reader.Close(); if (!attachmentReader.IsClosed) { attachmentReader.Close(); } return(postInfo); }
/// <summary> /// 判断指定用户是否是指定主题的回复者 /// </summary> /// <param name="tid">主题id</param> /// <param name="uid">用户id</param> /// <returns>是否是指定主题的回复者</returns> public static bool IsReplier(int tid, int uid) { return(DatabaseProvider.GetInstance().IsReplier(tid, uid, PostTables.GetPostTableId(tid))); }
/// <summary> /// 获得指定主题的第一个帖子的id /// </summary> /// <param name="tid">主题id</param> /// <returns>帖子id</returns> public static int GetFirstPostId(int tid) { return(DatabaseProvider.GetInstance().GetFirstPostId(tid, PostTables.GetPostTableId(tid))); }
/// <summary> /// 获取指定tid的帖子DataTable /// </summary> /// <param name="tid">帖子的tid</param> /// <returns>指定tid的帖子DataTable</returns> public static DataTable GetPostTree(int tid) { return(DatabaseProvider.GetInstance().GetPostTree(tid, PostTables.GetPostTableId(tid))); }
/// <summary> /// 获得最后回复的帖子列表 /// </summary> /// <param name="postpramsInfo">参数对象</param> /// <returns>帖子列表</returns> public static DataTable GetLastPostDataTable(PostpramsInfo postpramsInfo) { return(DatabaseProvider.GetInstance().GetLastPostList(postpramsInfo, PostTables.GetPostTableId(postpramsInfo.Tid))); }
/// <summary> /// 构建RSS输出内容 /// </summary> /// <param name="ttl">TTL数值</param> /// <param name="fidList">版块id列表</param> /// <param name="forumname">版块名称</param> /// <returns></returns> public static string BuildRssOutput(int ttl, string fidList, string forumname) { StringBuilder sbRss = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"); IDataReader reader = DatabaseProvider.GetInstance().GetNewTopics(fidList, PostTables.GetPostTableId()); sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n"); sbRss.Append("<rss version=\"2.0\">\r\n"); sbRss.Append(" <channel>\r\n"); sbRss.AppendFormat(" <title>{0}{1}</title>\r\n", Utils.HtmlEncode(config.Forumtitle), !Utils.StrIsNullOrEmpty(forumname) ? " - " + Utils.HtmlEncode(forumname) : ""); sbRss.AppendFormat(" <link>{0}", forumurl); if (Utils.IsNumeric(fidList)) { if (config.Aspxrewrite == 1) { sbRss.AppendFormat("showforum-{0}{1}", fidList, config.Extname); } else { sbRss.AppendFormat("showforum.aspx?forumid={0}", fidList); } } sbRss.Append("</link>\r\n"); sbRss.Append(" <description>Latest 20 threads</description>\r\n"); sbRss.AppendFormat(" <copyright>Copyright (c) {0}</copyright>\r\n", Utils.HtmlEncode(config.Forumtitle)); sbRss.Append(" <generator>Discuz!NT</generator>\r\n"); sbRss.AppendFormat(" <pubDate>{0}</pubDate>\r\n", DateTime.Now.ToString("r")); sbRss.AppendFormat(" <ttl>{0}</ttl>\r\n", ttl.ToString()); if (reader != null) { while (reader.Read()) { sbRss.Append(" <item>\r\n"); sbRss.AppendFormat(" <title>{0}</title>\r\n", Utils.HtmlEncode(reader["title"].ToString().Trim())); sbRss.Append(" <description><![CDATA["); if (reader["message"].ToString().IndexOf("[hide]") > -1) { sbRss.Append("***内容隐藏***"); } else { sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(Utils.ClearUBB(reader["message"].ToString()), 200, "......"))); } sbRss.Append("]]></description>\r\n"); sbRss.AppendFormat(" <link>{0}", Utils.HtmlEncode(forumurl)); if (config.Aspxrewrite == 1) { sbRss.AppendFormat("showtopic-{0}{1}", reader["tid"].ToString(), config.Extname); } else { sbRss.AppendFormat("showtopic.aspx?topicid={0}", reader["tid"].ToString()); } sbRss.Append("</link>\r\n"); if (!Utils.IsNumeric(fidList)) { sbRss.AppendFormat(" <category>{0}</category>\r\n", Utils.HtmlEncode(reader["name"].ToString().Trim())); } sbRss.AppendFormat(" <author>{0}</author>\r\n", Utils.HtmlEncode(reader["poster"].ToString().Trim())); sbRss.AppendFormat(" <pubDate>{0}</pubDate>\r\n", Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim())); sbRss.Append(" </item>\r\n"); } reader.Close(); } return(sbRss.Append(" </channel>\r\n</rss>").ToString()); }