public static PostInfo GetLastPostByTid(int tid, string tableName) { PostInfo postinfo = new PostInfo(); DataTable dt = DatabaseProvider.GetInstance().GetLastPostByTid(tid, tableName); if (dt.Rows.Count > 0) { postinfo.Pid = TypeConverter.ObjectToInt(dt.Rows[0]["pid"]); postinfo.Tid = TypeConverter.ObjectToInt(dt.Rows[0]["tid"]); postinfo.Title = dt.Rows[0]["title"].ToString().Trim(); postinfo.Postdatetime = dt.Rows[0]["postdatetime"].ToString().Trim(); postinfo.Poster = dt.Rows[0]["poster"].ToString().Trim(); postinfo.Posterid = TypeConverter.ObjectToInt(dt.Rows[0]["posterid"]); postinfo.Topictitle = Topics.GetTopicInfo(postinfo.Tid, 0, 0).Title; } else { postinfo.Pid = 0; postinfo.Tid = 0; postinfo.Title = "从未"; postinfo.Topictitle = "从未"; postinfo.Postdatetime = "1900-1-1"; postinfo.Poster = ""; postinfo.Posterid = 0; } dt.Dispose(); return(postinfo); }
/// <summary> /// 更新主题中的附件标志 /// </summary> /// <param name="tid">主题id</param> public static void UpdateTopicAttachment(int tid) { int attachmentCount = 0; if (appDBCache) { attachmentCount = IAttachmentService.GetAttachmentCountByTid(tid); } else { attachmentCount = DatabaseProvider.GetInstance().GetAttachmentCountByTid(tid); } if (Topics.appDBCache) { TopicInfo topicInfo = Topics.GetTopicInfo(tid, 0, 0); topicInfo.Attachment = attachmentCount; Topics.ITopicService.UpdateTopic(topicInfo); } DatabaseProvider.GetInstance().UpdateTopicAttachment(tid, attachmentCount > 0 ? 1 : 0); }
/// <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); } } } }