Exemple #1
0
        //public static Dictionary<String, Int32> GetMonthPostsStats()
        //{
        //    // 按照年月日 yyyyMM 为键,统计每月的帖子数,更新到哈希表里面去
        //    // 打算增加PostDate字段,专门存储日期,然后按照它统计
        //    var list = FindAll(null, null, null, 0, 0);
        //    var dic = new Dictionary<String, Int32>();
        //    foreach (var item in list)
        //    {
        //        var key = item.PostDateTime.ToString("yyyyMM");
        //        if (dic.ContainsKey(key))
        //            dic[key] += 1;
        //        else
        //            dic.Add(key, 1);
        //    }
        //    return dic;
        //}
        #endregion

        #region 帖子逻辑
        public Int32 Create()
        {
            var tp = Topic.FindByID(Tid);

            if (tp == null)
            {
                throw new ArgumentNullException("Tid", "找不到ID=" + Tid + "的主题");
            }

            using (var trans = Meta.CreateTrans())
            {
                FillDefault();

                // 需要借助索引表来生成主键
                var pi = new PostId();
                pi.PostDateTime = PostDateTime;
                pi.Insert();

                ID = pi.ID;
                if (ParentID == 0)
                {
                    ParentID = ID;
                }

                var rs = base.OnInsert();

                if (Invisible == 0)
                {
                    UpdateStatistic(1);
                }

                bool flag = Regex.IsMatch(Message, "\\s*(\\[hide\\][\\n\\r]*([\\s\\S]+?)[\\n\\r]*\\[\\/hide\\]|\\[hide=(\\d+?)\\][\\n\\r]*([\\s\\S]+?)[\\n\\r]*\\[\\/hide\\])\\s*", RegexOptions.IgnoreCase);
                if (tp != null)
                {
                    // 如果这个帖子是主贴,有隐藏内容,则隐藏主题
                    if (flag && Layer <= 0)
                    {
                        tp.Hide = 1;
                    }

                    tp.Save();
                }

                // 插入我的帖子
                if (PosterID != -1)
                {
                    var my = new MyPost();
                    my.Uid      = PosterID;
                    my.Tid      = Tid;
                    my.Pid      = ID;
                    my.Dateline = PostDateTime;
                    my.Insert();
                }

                trans.Commit();

                return(rs);
            }
        }
Exemple #2
0
        ///// <summary>首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法</summary>
        //[EditorBrowsable(EditorBrowsableState.Never)]
        //protected override void InitData()
        //{
        //    base.InitData();

        //    // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用
        //    // Meta.Count是快速取得表记录数
        //    if (Meta.Count > 0) return;

        //    // 需要注意的是,如果该方法调用了其它实体类的首次数据库操作,目标实体类的数据初始化将会在同一个线程完成
        //    if (XTrace.Debug) XTrace.WriteLine("开始初始化{0}PostS1数据……", typeof(PostS1).Name);

        //    var entity = new PostS1();
        //    entity.Pid = 0;
        //    entity.Fid = 0;
        //    entity.Tid = 0;
        //    entity.ParentID = 0;
        //    entity.Layer = 0;
        //    entity.Poster = "abc";
        //    entity.PosterID = 0;
        //    entity.Title = "abc";
        //    entity.PostDateTime = DateTime.Now;
        //    entity.Message = "abc";
        //    entity.IP = "abc";
        //    entity.LastEdit = "abc";
        //    entity.Invisible = 0;
        //    entity.Usesig = 0;
        //    entity.Htmlon = 0;
        //    entity.Smileyoff = 0;
        //    entity.Parseurloff = 0;
        //    entity.Bbcodeoff = 0;
        //    entity.Attachment = 0;
        //    entity.Rate = 0;
        //    entity.Ratetimes = 0;
        //    entity.Insert();

        //    if (XTrace.Debug) XTrace.WriteLine("完成初始化{0}PostS1数据!", typeof(PostS1).Name);
        //}


        ///// <summary>已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert</summary>
        ///// <returns></returns>
        //public override Int32 Insert()
        //{
        //    return base.Insert();
        //}

        /// <summary>已重载。在事务保护范围内处理业务,位于Valid之后</summary>
        /// <returns></returns>
        protected override Int32 OnInsert()
        {
            // 需要借助索引表来生成主键
            var pi = new PostId();

            pi.PostDateTime = PostDateTime;
            pi.Insert();

            ID = pi.ID;
            if (ParentID == 0)
            {
                ParentID = ID;
            }

            return(base.OnInsert());
        }
Exemple #3
0
        protected override int OnDelete()
        {
            var pi = PostId.FindByKey(ID);

            if (pi != null)
            {
                pi.Delete();
            }

            var rlog = RateLog.FindAllByPostID(ID);

            if (rlog != null)
            {
                rlog.Delete();
            }

            return(base.OnDelete());
        }