Esempio n. 1
0
        /// <summary>
        /// 复制主题
        /// </summary>
        /// <param name="topiclist">主题id列表</param>
        /// <param name="fid">目标版块id</param>
        /// <returns>更新记录数</returns>
        public static int CopyTopics(string topiclist, int fid)
        {
            if (!Utils.IsNumericList(topiclist))
            {
                return(-1);
            }

            int       tid;
            int       reval     = 0;
            TopicInfo topicinfo = null;

            foreach (string topicid in topiclist.Split(','))
            {
                topicinfo = Topics.GetTopicInfo(TypeConverter.StrToInt(topicid));
                if (topicinfo != null)
                {
                    topicinfo.Fid          = fid;
                    topicinfo.Readperm     = 0;
                    topicinfo.Price        = 0;
                    topicinfo.Postdatetime = Utils.GetDateTime();
                    topicinfo.Lastpost     = Utils.GetDateTime();
                    topicinfo.Lastposter   = Utils.GetDateTime();
                    topicinfo.Views        = 0;
                    topicinfo.Replies      = 0;
                    topicinfo.Displayorder = 0;
                    topicinfo.Highlight    = "";
                    topicinfo.Digest       = 0;
                    topicinfo.Rate         = 0;
                    topicinfo.Hide         = 0;
                    topicinfo.Special      = 0;
                    topicinfo.Attachment   = 0;
                    topicinfo.Moderated    = 0;
                    topicinfo.Closed       = 0;
                    tid = Topics.CreateTopic(topicinfo);

                    if (tid > 0)
                    {
                        PostInfo postinfo = Posts.GetPostInfo(tid, Posts.GetFirstPostId(TypeConverter.StrToInt(topicid)));
                        postinfo.Fid          = topicinfo.Fid;
                        postinfo.Tid          = tid;
                        postinfo.Parentid     = 0;
                        postinfo.Layer        = 0;
                        postinfo.Postdatetime = Utils.GetDateTime();
                        postinfo.Invisible    = 0;
                        postinfo.Attachment   = 0;
                        postinfo.Rate         = 0;
                        postinfo.Ratetimes    = 0;
                        postinfo.Message      = UBB.ClearAttachUBB(postinfo.Message);
                        postinfo.Topictitle   = topicinfo.Title;

                        if (Posts.CreatePost(postinfo) > 0)
                        {
                            reval++;
                        }
                    }
                }
            }
            return(reval);
        }
Esempio n. 2
0
        /// <summary>
        /// 分割主题
        /// </summary>
        /// <param name="postidlist">帖子id列表</param>
        /// <param name="subject">主题</param>
        /// <param name="topicId">主题id列表</param>
        /// <returns>更新记录数</returns>
        public static int SplitTopics(string postidlist, string subject, string topicId)
        {
            //验证要分割的帖子是否为有效PID号
            string[] postIdArray = postidlist.Split(',');
            if (Utils.StrIsNullOrEmpty(postidlist) || !Utils.IsNumericArray(postIdArray))
            {
                return(-1);
            }

            int tid        = 0;
            int lastPostId = TypeConverter.StrToInt(postIdArray[postIdArray.Length - 1]);

            //将要被分割主题的tid
            TopicInfo originalTopicInfo = Topics.GetTopicInfo(TypeConverter.StrToInt(topicId)); //原主题信息
            TopicInfo newTopicInfo      = new TopicInfo();                                      //新主题信息
            PostInfo  lastPostInfo      = Posts.GetPostInfo(originalTopicInfo.Tid, lastPostId);
            PostInfo  firstPostInfo     = Posts.GetPostInfo(originalTopicInfo.Tid, TypeConverter.StrToInt(postIdArray[0]));

            newTopicInfo.Poster       = firstPostInfo.Poster;
            newTopicInfo.Posterid     = firstPostInfo.Posterid;
            newTopicInfo.Postdatetime = Utils.GetDateTime();
            newTopicInfo.Displayorder = 0;
            newTopicInfo.Highlight    = "";
            newTopicInfo.Digest       = 0;
            newTopicInfo.Rate         = 0;
            newTopicInfo.Hide         = 0;
            newTopicInfo.Special      = 0;
            newTopicInfo.Attachment   = 0;
            newTopicInfo.Moderated    = 0;
            newTopicInfo.Closed       = 0;
            newTopicInfo.Views        = 0;
            newTopicInfo.Fid          = originalTopicInfo.Fid;
            newTopicInfo.Forumname    = originalTopicInfo.Forumname;
            newTopicInfo.Iconid       = originalTopicInfo.Iconid;
            newTopicInfo.Typeid       = originalTopicInfo.Typeid;
            newTopicInfo.Replies      = postIdArray.Length - 1;
            newTopicInfo.Title        = Utils.HtmlEncode(subject);
            newTopicInfo.Lastposterid = lastPostInfo.Posterid;
            newTopicInfo.Lastpost     = lastPostInfo.Postdatetime;
            newTopicInfo.Lastposter   = lastPostInfo.Poster;

            tid = Topics.CreateTopic(newTopicInfo);
            DatabaseProvider.GetInstance().UpdatePostTid(postidlist, tid, Data.PostTables.GetPostTableId(tid));
            DatabaseProvider.GetInstance().SetPrimaryPost(subject, tid, postIdArray, Discuz.Data.PostTables.GetPostTableId(tid));

            newTopicInfo.Tid        = tid;
            newTopicInfo.Lastpostid = lastPostId;
            if (originalTopicInfo.Lastpostid == lastPostId)//当需要将原主题的最后一个发帖分割走时(即分割列表中有和原主题Lastpostid相同的值)
            {
                newTopicInfo.Lastposterid = originalTopicInfo.Posterid;
                newTopicInfo.Lastpost     = originalTopicInfo.Lastpost;
                newTopicInfo.Lastposter   = originalTopicInfo.Poster;
                DataTable dt = DatabaseProvider.GetInstance().GetLastPostNotInPidList(postidlist, originalTopicInfo.Tid, int.Parse(Posts.GetPostTableId()));
                originalTopicInfo.Lastpostid   = TypeConverter.ObjectToInt(dt.Rows[0]["pid"]);
                originalTopicInfo.Lastposterid = TypeConverter.ObjectToInt(dt.Rows[0]["Posterid"].ToString());
                originalTopicInfo.Lastpost     = dt.Rows[0]["Postdatetime"].ToString();
                originalTopicInfo.Lastposter   = dt.Rows[0]["Poster"].ToString();
            }
            originalTopicInfo.Replies = originalTopicInfo.Replies - postIdArray.Length;

            Topics.UpdateTopic(originalTopicInfo);//更新原主题的信息
            Topics.UpdateTopicReplyCount(originalTopicInfo.Tid);

            Topics.UpdateTopic(newTopicInfo);//由于数据库中对lastpostid有list约束,所以不能有重复值,则必须在原主题的lastpostid修改之后再次修改才能将数据最终修正完毕
            Topics.UpdateTopicReplyCount(tid);

            return(tid);
        }