Exemplo n.º 1
0
        /// <summary>
        /// 在数据库中删除指定主题
        /// </summary>
        /// <param name="topiclist">主题列表</param>
        /// <param name="subtractCredits">是否减少用户积分(0不减少,1减少)</param>
        /// <returns>删除个数</returns>
        public static int DeleteTopics(string topicList, int subTractCredits, bool reserveAttach)
        {
            if (!Utils.IsNumericList(topicList))
            {
                return(-1);
            }

            DataTable dt = Topics.GetTopicList(topicList);

            if (dt == null)
            {
                return(-1);
            }

            foreach (DataRow dr in dt.Rows)
            {
                if (TypeConverter.ObjectToInt(dr["digest"]) > 0)
                {
                    //UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), -1, CreditsOperationType.Digest, 1, true);
                    CreditsFacade.UnDigest(TypeConverter.ObjectToInt(dr["posterid"]));
                }
            }

            List <PostInfo> list = Posts.GetPostList(topicList);

            if (list != null && list.Count != 0)
            {
                int       lastFid   = 0;
                ForumInfo forumInfo = null;
                foreach (PostInfo postInfo in list)
                {
                    //如果与上一个帖子是同一版块,将不再重新读取版块信息
                    if (lastFid != postInfo.Fid)
                    {
                        lastFid   = postInfo.Fid;
                        forumInfo = Forums.GetForumInfo(lastFid);
                    }
                    CreditsFacade.DeletePost(postInfo, forumInfo, reserveAttach);
                }
            }

            int reval = 0;

            foreach (string posttableid in Posts.GetPostTableIdArray(topicList))
            {
                reval = Discuz.Data.TopicAdmins.DeleteTopicByTidList(topicList, posttableid);
            }
            if (reval > 0 && !reserveAttach)
            {
                Attachments.DeleteAttachmentByTid(topicList);
            }
            return(reval);
        }