Beispiel #1
0
 /// <summary>
 /// 检查别名是否重复
 /// </summary>
 /// <param name="term"></param>
 /// <returns></returns>
 private bool CheckSlug(PostInfo post)
 {
     if (string.IsNullOrEmpty(post.Slug))
     {
         return(true);
     }
     while (true)
     {
         string cmdText = string.Empty;
         if (post.PostId == 0)
         {
             cmdText = string.Format("select count(1) from Loachs_Posts where slug='{0}'  ", post.Slug);
         }
         else
         {
             cmdText = string.Format("select count(1) from Loachs_Posts where slug='{0}'   and postid<>{1}", post.Slug, post.PostId);
         }
         int r = Convert.ToInt32(MYSQLHelper.ExecuteScalar(cmdText));
         if (r == 0)
         {
             return(true);
         }
         post.Slug += "-2";
     }
 }
Beispiel #2
0
        public int InsertLink(LinkInfo link)
        {
            string cmdText = @"insert into Loachs_Links
                            (
                            type,name,href,position,target,description,displayorder,status,createdate
                            )
                            values
                            (
                            @type,@name,@href,@position,@target,@description,@displayorder,@status,@createdate
                            )";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@type",         MySqlDbType.Int32,     4, link.Type),
                MYSQLHelper.MakeInParam("@name",         MySqlDbType.VarChar, 100, link.Name),
                MYSQLHelper.MakeInParam("@href",         MySqlDbType.VarChar, 255, link.Href),
                MYSQLHelper.MakeInParam("@position",     MySqlDbType.Int32,     4, link.Position),
                MYSQLHelper.MakeInParam("@target",       MySqlDbType.VarChar,  50, link.Target),
                MYSQLHelper.MakeInParam("@description",  MySqlDbType.VarChar, 255, link.Description),
                MYSQLHelper.MakeInParam("@displayorder", MySqlDbType.Int32,     4, link.Displayorder),
                MYSQLHelper.MakeInParam("@status",       MySqlDbType.Int32,     4, link.Status),
                MYSQLHelper.MakeInParam("@createdate",   MySqlDbType.Date,      8, link.CreateDate),
            };

            int r = MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            if (r > 0)
            {
                return(Convert.ToInt32(MYSQLHelper.ExecuteScalar("select linkid from Loachs_Links  order by linkid desc limit 0,1")));
            }
            return(0);
        }
Beispiel #3
0
        public int UpdateTag(TagInfo tag)
        {
            CheckSlug(tag);

            string cmdText = @"update Loachs_Terms set
                                Type=@Type,
                                Name=@Name,
                                Slug=@Slug,
                                Description=@Description,
                                Displayorder=@Displayorder,
                                Count=@Count,
                                CreateDate=@CreateDate
                                where termid=@termid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@Type",         MySqlDbType.Int32,     1, (int)TermType.Tag),
                MYSQLHelper.MakeInParam("@Name",         MySqlDbType.VarChar, 255, tag.Name),
                MYSQLHelper.MakeInParam("@Slug",         MySqlDbType.VarChar, 255, tag.Slug),
                MYSQLHelper.MakeInParam("@Description",  MySqlDbType.VarChar, 255, tag.Description),
                MYSQLHelper.MakeInParam("@Displayorder", MySqlDbType.Int32,     4, tag.Displayorder),
                MYSQLHelper.MakeInParam("@Count",        MySqlDbType.Int32,     4, tag.Count),
                MYSQLHelper.MakeInParam("@CreateDate",   MySqlDbType.Date,      8, tag.CreateDate),
                MYSQLHelper.MakeInParam("@termid",       MySqlDbType.Int32,     1, tag.TagId),
            };
            return(Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)));
        }
Beispiel #4
0
        public int UpdateLink(LinkInfo link)
        {
            string cmdText = @"update Loachs_Links set
                                type=@type,
                                name=@name,
                                href=@href,
                                position=@position,
                                target=@target,
                                description=@description,
                                displayorder=@displayorder,
                                status=@status,
                                createdate=@createdate
                                where linkid=@linkid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@type",         MySqlDbType.Int32,     4, link.Type),
                MYSQLHelper.MakeInParam("@name",         MySqlDbType.VarChar, 100, link.Name),
                MYSQLHelper.MakeInParam("@href",         MySqlDbType.VarChar, 255, link.Href),
                MYSQLHelper.MakeInParam("@position",     MySqlDbType.Int32,     4, link.Position),
                MYSQLHelper.MakeInParam("@target",       MySqlDbType.VarChar,  50, link.Target),
                MYSQLHelper.MakeInParam("@description",  MySqlDbType.VarChar, 255, link.Description),
                MYSQLHelper.MakeInParam("@displayorder", MySqlDbType.Int32,     4, link.Displayorder),
                MYSQLHelper.MakeInParam("@status",       MySqlDbType.Int32,     4, link.Status),
                MYSQLHelper.MakeInParam("@createdate",   MySqlDbType.Date,      8, link.CreateDate),
                MYSQLHelper.MakeInParam("@linkid",       MySqlDbType.Int32,     4, link.LinkId),
            };

            return(Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)));
        }
Beispiel #5
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public int UpdateComment(CommentInfo comment)
        {
            string cmdText = @"update Loachs_Comments set 
                            PostId=@PostId,                            
                            ParentId=@ParentId,
                            UserId=@UserId,
                            Name=@Name,
                            Email=@Email,
                            SiteUrl=@SiteUrl,
                            Content=@Content,
                            EmailNotify=@EmailNotify,
                            IpAddress=@IpAddress,
                            CreateDate=@CreateDate,
                            Approved=@Approved
                            where CommentId=@CommentId ";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@PostId",      MySqlDbType.Int32,     4, comment.PostId),
                MYSQLHelper.MakeInParam("@ParentId",    MySqlDbType.Int32,     4, comment.ParentId),
                MYSQLHelper.MakeInParam("@UserId",      MySqlDbType.Int32,     4, comment.UserId),
                MYSQLHelper.MakeInParam("@Name",        MySqlDbType.VarChar, 255, comment.Name),
                MYSQLHelper.MakeInParam("@Email",       MySqlDbType.VarChar, 255, comment.Email),
                MYSQLHelper.MakeInParam("@SiteUrl",     MySqlDbType.VarChar, 255, comment.SiteUrl),
                MYSQLHelper.MakeInParam("@Content",     MySqlDbType.VarChar, 255, comment.Content),
                MYSQLHelper.MakeInParam("@EmailNotify", MySqlDbType.Int32,     4, comment.EmailNotify),
                MYSQLHelper.MakeInParam("@IpAddress",   MySqlDbType.VarChar, 255, comment.IpAddress),
                MYSQLHelper.MakeInParam("@CreateDate",  MySqlDbType.Date,      8, comment.CreateDate),
                MYSQLHelper.MakeInParam("@Approved",    MySqlDbType.Int32,     4, comment.Approved),
                MYSQLHelper.MakeInParam("@CommentId",   MySqlDbType.Int32,     4, comment.CommentId),
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #6
0
        public List <PostInfo> GetPostListByRelated(int postId, int rowCount)
        {
            string tags = string.Empty;

            PostInfo post = GetPost(postId);

            if (post != null && post.Tag.Length > 0)
            {
                tags = post.Tag;


                tags = tags.Replace("}", "},");
                string[] idList = tags.Split(',');

                string where = " (";
                foreach (string tagID in idList)
                {
                    if (!string.IsNullOrEmpty(tagID))
                    {
                        where += string.Format("  tags like '%{0}%' or ", tagID);
                    }
                }
                where += " 1=2 ) and status=1 and postid<>" + postId;

                //string cmdText = string.Format("select top {0} * from Loachs_Posts where {1} order by postid desc", rowCount, where);
                string cmdText = string.Format("select  * from Loachs_Posts where {1} order by postid desc limit 0,{0}", rowCount, where);


                return(DataReaderToCommentList(MYSQLHelper.ExecuteReader(cmdText)));
            }
            return(new List <PostInfo>());
        }
Beispiel #7
0
        public int InsertTag(TagInfo tag)
        {
            CheckSlug(tag);

            string cmdText = @"insert into Loachs_Terms
                            (
                            Type,Name,Slug,Description,Displayorder,Count,CreateDate
                            )
                            values
                            (
                            @Type,@Name,@Slug,@Description,@Displayorder,@Count,@CreateDate
                            )";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@Type",         MySqlDbType.Int32,     1, (int)TermType.Tag),
                MYSQLHelper.MakeInParam("@Name",         MySqlDbType.VarChar, 255, tag.Name),
                MYSQLHelper.MakeInParam("@Slug",         MySqlDbType.VarChar, 255, tag.Slug),
                MYSQLHelper.MakeInParam("@Description",  MySqlDbType.VarChar, 255, tag.Description),
                MYSQLHelper.MakeInParam("@Displayorder", MySqlDbType.Int32,     4, tag.Displayorder),
                MYSQLHelper.MakeInParam("@Count",        MySqlDbType.Int32,     4, tag.Count),
                MYSQLHelper.MakeInParam("@CreateDate",   MySqlDbType.Date,      8, tag.CreateDate)
            };
            MYSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams);

            //int newId = Convert.ToInt32(MYSQLHelper.ExecuteScalar("select top 1 termid from Loachs_Terms order by termid desc"));
            int newId = Convert.ToInt32(MYSQLHelper.ExecuteScalar("select termid from Loachs_Terms order by termid desc limit 0,1"));


            return(newId);
        }
Beispiel #8
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public int InsertComment(CommentInfo comment)
        {
            string cmdText = @"insert into Loachs_Comments(
                            PostId, ParentId,UserId,Name,Email,SiteUrl,Content,EmailNotify,IpAddress,CreateDate,Approved)
                             values (
                            @PostId, @ParentId,@UserId,@Name,@Email,@SiteUrl,@Content,@EmailNotify,@IpAddress,@CreateDate,@Approved)";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@PostId",      MySqlDbType.Int32,     4, comment.PostId),
                MYSQLHelper.MakeInParam("@ParentId",    MySqlDbType.Int32,     4, comment.ParentId),
                MYSQLHelper.MakeInParam("@UserId",      MySqlDbType.Int32,     4, comment.UserId),
                MYSQLHelper.MakeInParam("@Name",        MySqlDbType.VarChar, 255, comment.Name),
                MYSQLHelper.MakeInParam("@Email",       MySqlDbType.VarChar, 255, comment.Email),
                MYSQLHelper.MakeInParam("@SiteUrl",     MySqlDbType.VarChar, 255, comment.SiteUrl),
                MYSQLHelper.MakeInParam("@Content",     MySqlDbType.VarChar, 255, comment.Content),
                MYSQLHelper.MakeInParam("@EmailNotify", MySqlDbType.Int32,     4, comment.EmailNotify),
                MYSQLHelper.MakeInParam("@IpAddress",   MySqlDbType.VarChar, 255, comment.IpAddress),
                MYSQLHelper.MakeInParam("@CreateDate",  MySqlDbType.Date,      8, comment.CreateDate),
                MYSQLHelper.MakeInParam("@Approved",    MySqlDbType.Int32,     4, comment.Approved),
            };
            MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            int newId = Convert.ToInt32(MYSQLHelper.ExecuteScalar("select  CommentId from Loachs_Comments  order by CommentId desc limit 0,1"));

            return(newId);
        }
Beispiel #9
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="_userinfo"></param>
        /// <returns></returns>
        public int InsertUser(UserInfo _userinfo)
        {
            string cmdText = @" insert into Loachs_Users(
                                Type,UserName,Name,Password,Email,SiteUrl,AvatarUrl,Description,displayorder,Status,PostCount,CommentCount,CreateDate)
                                values (
                                @Type,@UserName,@Name,@Password,@Email,@SiteUrl,@AvatarUrl,@Description,@Displayorder,@Status, @PostCount,@CommentCount,@CreateDate )";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@Type",         MySqlDbType.Int32,     4, _userinfo.Type),
                MYSQLHelper.MakeInParam("@UserName",     MySqlDbType.VarChar,  50, _userinfo.UserName),
                MYSQLHelper.MakeInParam("@Name",         MySqlDbType.VarChar,  50, _userinfo.Name),
                MYSQLHelper.MakeInParam("@Password",     MySqlDbType.VarChar,  50, _userinfo.Password),
                MYSQLHelper.MakeInParam("@Email",        MySqlDbType.VarChar,  50, _userinfo.Email),
                MYSQLHelper.MakeInParam("@SiteUrl",      MySqlDbType.VarChar, 255, _userinfo.SiteUrl),
                MYSQLHelper.MakeInParam("@AvatarUrl",    MySqlDbType.VarChar, 255, _userinfo.AvatarUrl),
                MYSQLHelper.MakeInParam("@description",  MySqlDbType.VarChar, 255, _userinfo.Description),
                MYSQLHelper.MakeInParam("@Displayorder", MySqlDbType.Int32,     4, _userinfo.Displayorder),
                MYSQLHelper.MakeInParam("@Status",       MySqlDbType.Int32,     4, _userinfo.Status),
                MYSQLHelper.MakeInParam("@PostCount",    MySqlDbType.Int32,     4, _userinfo.PostCount),
                MYSQLHelper.MakeInParam("@CommentCount", MySqlDbType.Int32,     4, _userinfo.CommentCount),
                MYSQLHelper.MakeInParam("@CreateDate",   MySqlDbType.Date,      8, _userinfo.CreateDate),
            };
            int r = MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            if (r > 0)
            {
                //return Convert.ToInt32(MYSQLHelper.ExecuteScalar("select top 1 UserId from Loachs_Users  order by UserId desc"));
                return(Convert.ToInt32(MYSQLHelper.ExecuteScalar("select UserId from Loachs_Users  order by UserId desc limit 0,1")));
            }
            return(0);
        }
Beispiel #10
0
        public List <TagInfo> GetTagList()
        {
            string condition = " type=" + (int)TermType.Tag;

            string cmdText = "select * from Loachs_Terms where " + condition + "  order by displayorder asc ,termid asc";

            return(DataReaderToList(MYSQLHelper.ExecuteReader(cmdText)));
        }
Beispiel #11
0
        public int DeleteLink(int linkId)
        {
            string cmdText = "delete from Loachs_Links where linkid = @linkid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@linkid", MySqlDbType.Int32, 4, linkId)
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #12
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int DeleteUser(int userid)
        {
            string cmdText = "delete from Loachs_Users where userid = @userid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@userid", MySqlDbType.Int32, 4, userid)
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #13
0
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool ExistsUserName(string userName)
        {
            string cmdText = "select count(1) from Loachs_Users where userName = @userName ";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@userName", MySqlDbType.VarChar, 50, userName),
            };
            return(Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)) > 0);
        }
Beispiel #14
0
        public int DeleteTag(int tagId)
        {
            string cmdText = "delete from Loachs_Terms where termid = @termid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@termid", MySqlDbType.Int32, 4, tagId)
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #15
0
        public int UpdatePostViewCount(int postId, int addCount)
        {
            string cmdText = "update Loachs_Posts set viewcount = viewcount + @addcount where postid=@postid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@addcount", MySqlDbType.Int32, 4, addCount),
                MYSQLHelper.MakeInParam("@postid",   MySqlDbType.Int32, 4, postId),
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #16
0
        public bool UpdateSetting(SettingInfo setting)
        {
            string cmdText = @"update Loachs_Sites set setting=@setting";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@setting", MySqlDbType.VarChar, 0, Serialize(setting)),
            };

            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams) == 1);
        }
Beispiel #17
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public CommentInfo GetComment(int commentId)
        {
            string cmdText = "select * from Loachs_Comments where commentId = @commentId";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@commentId", MySqlDbType.Int32, 4, commentId)
            };
            List <CommentInfo> list = DataReaderToCommentList(MYSQLHelper.ExecuteReader(cmdText, prams));

            return(list.Count > 0 ? list[0] : null);
        }
Beispiel #18
0
        /// <summary>
        /// 根据日志ID删除评论
        /// </summary>
        /// <param name="postId">日志ID</param>
        /// <returns></returns>
        public int DeleteCommentByPost(int postId)
        {
            string cmdText = "delete from Loachs_Comments where postId = @postId";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@postId", MySqlDbType.Int32, 4, postId)
            };
            int result = MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            return(result);
        }
Beispiel #19
0
        public TagInfo GetTag(int tagId)
        {
            string cmdText = "select * from Loachs_Terms where termid = @termid";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@termid", MySqlDbType.Int32, 4, tagId)
            };

            List <TagInfo> list = DataReaderToList(MYSQLHelper.ExecuteReader(CommandType.Text, cmdText, prams));

            return(list.Count > 0 ? list[0] : null);
        }
Beispiel #20
0
        //public List<TagInfo> GetTagList(int pageSize, int pageIndex, out int recordCount)
        //{
        //    string condition = " [type]=" + (int)TermType.Tag;


        //    string cmdTotalRecord = "select count(1) from [Loachs_Terms] where " + condition;

        //    recordCount = Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdTotalRecord));


        //    string cmdText = MYSQLHelper.GetPageSql("[Loachs_Terms]", "[termid]", "*", pageSize, pageIndex, 1, condition);
        //    return DataReaderToList(MYSQLHelper.ExecuteReader(cmdText));
        //}

        public List <TagInfo> GetTagList(string ids)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return(new List <TagInfo>());
            }

            string cmdText = "select * from Loachs_Terms where  termid in (" + ids + ")";

            //  throw new Exception(cmdText);

            return(DataReaderToList(MYSQLHelper.ExecuteReader(cmdText)));
        }
Beispiel #21
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public int DeleteComment(int commentId)
        {
            CommentInfo comment = GetComment(commentId);        //删除前

            string cmdText = "delete from Loachs_Comments where commentId = @commentId";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@commentId", MySqlDbType.Int32, 4, commentId)
            };

            int result = MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            return(result);
        }
Beispiel #22
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="PostId">主键</param>
        /// <returns></returns>
        public PostInfo GetPost(int postid)
        {
            //string cmdText = "select top 1 * from [Loachs_Posts] where [PostId] = @PostId";
            string cmdText = "select * from Loachs_Posts where PostId = @PostId limit 0,1";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@PostId", MySqlDbType.Int32, 4, postid)
            };


            List <PostInfo> list = DataReaderToCommentList(MYSQLHelper.ExecuteReader(cmdText, prams));

            return(list.Count > 0 ? list[0] : null);
        }
Beispiel #23
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="slug"></param>
        /// <returns></returns>
        public PostInfo GetPost(string slug)
        {
            //string cmdText = "select top 1 * from [Loachs_Posts] where [slug] = @slug";
            string cmdText = "select * from Loachs_Posts where slug = @slug limit 0,1";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@slug", MySqlDbType.VarChar, 200, slug)
            };


            List <PostInfo> list = DataReaderToCommentList(MYSQLHelper.ExecuteReader(cmdText, prams));

            return(list.Count > 0 ? list[0] : null);
        }
Beispiel #24
0
        public SettingInfo GetSetting()
        {
            //string cmdText = "select top 1 [setting] from [Loachs_Sites]";
            string cmdText = "select setting from Loachs_Sites limit 0,1";


            string str = Convert.ToString(MYSQLHelper.ExecuteScalar(cmdText));

            object obj = DeSerialize(typeof(SettingInfo), str);

            if (obj == null)
            {
                return(new SettingInfo());
            }

            return((SettingInfo)obj);
        }
Beispiel #25
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="postinfo">实体</param>
        /// <returns>成功返回新记录的ID,失败返回 0</returns>
        public int InsertPost(PostInfo postinfo)
        {
            CheckSlug(postinfo);
            string cmdText = @"insert into Loachs_Posts
                                (
                               CategoryId,Title,Summary,Content,Slug,UserId,CommentStatus,CommentCount,ViewCount,Tag,UrlFormat,Template,Recommend,Status,TopStatus,HideStatus,CreateDate,UpdateDate
                                )
                                values
                                (
                                @CategoryId,@Title,@Summary,@Content,@Slug,@UserId,@CommentStatus,@CommentCount,@ViewCount,@Tag,@UrlFormat,@Template,@Recommend,@Status,@TopStatus,@HideStatus,@CreateDate,@UpdateDate
                                )";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@CategoryId",    MySqlDbType.Int32,     4, postinfo.CategoryId),
                MYSQLHelper.MakeInParam("@Title",         MySqlDbType.VarChar, 255, postinfo.Title),
                MYSQLHelper.MakeInParam("@Summary",       MySqlDbType.VarChar,   0, postinfo.Summary),
                MYSQLHelper.MakeInParam("@Content",       MySqlDbType.VarChar,   0, postinfo.Content),
                MYSQLHelper.MakeInParam("@Slug",          MySqlDbType.VarChar, 255, postinfo.Slug),
                MYSQLHelper.MakeInParam("@UserId",        MySqlDbType.Int32,     4, postinfo.UserId),
                MYSQLHelper.MakeInParam("@CommentStatus", MySqlDbType.Int32,     1, postinfo.CommentStatus),
                MYSQLHelper.MakeInParam("@CommentCount",  MySqlDbType.Int32,     4, postinfo.CommentCount),
                MYSQLHelper.MakeInParam("@ViewCount",     MySqlDbType.Int32,     4, postinfo.ViewCount),
                MYSQLHelper.MakeInParam("@Tag",           MySqlDbType.VarChar, 255, postinfo.Tag),
                MYSQLHelper.MakeInParam("@UrlFormat",     MySqlDbType.Int32,     1, postinfo.UrlFormat),
                MYSQLHelper.MakeInParam("@Template",      MySqlDbType.VarChar,  50, postinfo.Template),
                MYSQLHelper.MakeInParam("@Recommend",     MySqlDbType.Int32,     1, postinfo.Recommend),
                MYSQLHelper.MakeInParam("@Status",        MySqlDbType.Int32,     1, postinfo.Status),
                MYSQLHelper.MakeInParam("@TopStatus",     MySqlDbType.Int32,     1, postinfo.TopStatus),
                MYSQLHelper.MakeInParam("@HideStatus",    MySqlDbType.Int32,     1, postinfo.HideStatus),
                MYSQLHelper.MakeInParam("@CreateDate",    MySqlDbType.Date,      8, postinfo.CreateDate),
                MYSQLHelper.MakeInParam("@UpdateDate",    MySqlDbType.Date,      8, postinfo.UpdateDate)
            };
            MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);
            //int newId = StringHelper.ObjectToInt(MYSQLHelper.ExecuteScalar("select top 1 PostId from Loachs_Posts order by PostId desc"));
            int newId = StringHelper.ObjectToInt(MYSQLHelper.ExecuteScalar("select PostId from Loachs_Posts order by PostId desc limit 0,1"));

            //if (newId > 0)
            //{
            //    MYSQLHelper.ExecuteNonQuery(string.Format("update [Loachs_Users] set [postcount]=[postcount]+1 where [userid]={0}", postinfo.UserId));
            //    MYSQLHelper.ExecuteNonQuery("update [Loachs_Sites] set [postcount]=[postcount]+1");
            //    MYSQLHelper.ExecuteNonQuery(string.Format("update [Loachs_Terms] set [count]=[count]+1 where [termid]={0}", postinfo.CategoryId));
            //}
            return(newId);
        }
Beispiel #26
0
        public StatisticsInfo GetStatistics()
        {
            //string cmdText = "select top 1 * from [Loachs_Sites]";
            string cmdText = "select  * from Loachs_Sites limit 0,1";


            string insertText = "insert into Loachs_Sites (PostCount,CommentCount,VisitCount,TagCount,setting) values ( '0','0','0','0','<?xml version=\"1.0\" encoding=\"utf-8\"?><SettingInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></SettingInfo>')";

            List <StatisticsInfo> list = DataReaderToList(MYSQLHelper.ExecuteReader(cmdText));

            if (list.Count == 0)
            {
                MYSQLHelper.ExecuteNonQuery(insertText);
            }
            list = DataReaderToList(MYSQLHelper.ExecuteReader(cmdText));

            return(list.Count > 0 ? list[0] : null);
        }
Beispiel #27
0
        public bool UpdateStatistics(StatisticsInfo statistics)
        {
            string cmdText = @"update Loachs_Sites set 
                                PostCount=@PostCount,
                                CommentCount=@CommentCount,
                                VisitCount=@VisitCount,
                                TagCount=@TagCount";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@PostCount",    MySqlDbType.Int32, 4, statistics.PostCount),
                MYSQLHelper.MakeInParam("@CommentCount", MySqlDbType.Int32, 4, statistics.CommentCount),
                MYSQLHelper.MakeInParam("@VisitCount",   MySqlDbType.Int32, 4, statistics.VisitCount),
                MYSQLHelper.MakeInParam("@TagCount",     MySqlDbType.Int32, 4, statistics.TagCount),
            };

            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams) == 1);
        }
Beispiel #28
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="postinfo">实体</param>
        /// <returns>修改的行数</returns>
        public int UpdatePost(PostInfo postinfo)
        {
            CheckSlug(postinfo);

            //PostInfo oldPost = GetPost(postinfo.PostId);        //修改前

            //if (oldPost.CategoryId != postinfo.CategoryId)
            //{

            //    MYSQLHelper.ExecuteNonQuery(string.Format("update [Loachs_Terms] set [count]=[count]-1 where [termid]={0}", oldPost.CategoryId));

            //    MYSQLHelper.ExecuteNonQuery(string.Format("update [Loachs_Terms] set [count]=[count]+1 where [termid]={0}", postinfo.CategoryId));

            //}


            string cmdText = "update Loachs_Posts set  CategoryId=@CategoryId,Title=@Title,Summary=@Summary,Content=@Content,Slug=@Slug,UserId=@UserId,CommentStatus=@CommentStatus,CommentCount=@CommentCount,ViewCount=@ViewCount,Tag=@Tag,UrlFormat=@UrlFormat,Template=@Template,Recommend=@Recommend,Status=@Status,TopStatus=@TopStatus,HideStatus=@HideStatus,CreateDate=@CreateDate,UpdateDate=@UpdateDate where PostId=@PostId";

            MySqlParameter[] prams =
            {
                MYSQLHelper.MakeInParam("@CategoryId",    MySqlDbType.Int32,     4, postinfo.CategoryId),
                MYSQLHelper.MakeInParam("@Title",         MySqlDbType.VarChar, 255, postinfo.Title),
                MYSQLHelper.MakeInParam("@Summary",       MySqlDbType.VarChar,   0, postinfo.Summary),
                MYSQLHelper.MakeInParam("@Content",       MySqlDbType.VarChar,   0, postinfo.Content),
                MYSQLHelper.MakeInParam("@Slug",          MySqlDbType.VarChar, 255, postinfo.Slug),
                MYSQLHelper.MakeInParam("@UserId",        MySqlDbType.Int32,     4, postinfo.UserId),
                MYSQLHelper.MakeInParam("@CommentStatus", MySqlDbType.Int32,     1, postinfo.CommentStatus),
                MYSQLHelper.MakeInParam("@CommentCount",  MySqlDbType.Int32,     4, postinfo.CommentCount),
                MYSQLHelper.MakeInParam("@ViewCount",     MySqlDbType.Int32,     4, postinfo.ViewCount),
                MYSQLHelper.MakeInParam("@Tag",           MySqlDbType.VarChar, 255, postinfo.Tag),
                MYSQLHelper.MakeInParam("@UrlFormat",     MySqlDbType.Int32,     1, postinfo.UrlFormat),
                MYSQLHelper.MakeInParam("@Template",      MySqlDbType.VarChar,  50, postinfo.Template),
                MYSQLHelper.MakeInParam("@Recommend",     MySqlDbType.Int32,     1, postinfo.Recommend),
                MYSQLHelper.MakeInParam("@Status",        MySqlDbType.Int32,     1, postinfo.Status),
                MYSQLHelper.MakeInParam("@TopStatus",     MySqlDbType.Int32,     1, postinfo.TopStatus),
                MYSQLHelper.MakeInParam("@HideStatus",    MySqlDbType.Int32,     1, postinfo.HideStatus),
                MYSQLHelper.MakeInParam("@CreateDate",    MySqlDbType.Date,      8, postinfo.CreateDate),
                MYSQLHelper.MakeInParam("@UpdateDate",    MySqlDbType.Date,      8, postinfo.UpdateDate),
                MYSQLHelper.MakeInParam("@PostId",        MySqlDbType.Int32,     4, postinfo.PostId),
            };
            return(MYSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams));
        }
Beispiel #29
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="totalRecord"></param>
        /// <returns></returns>
        public List <CommentInfo> GetCommentList(int pageSize, int pageIndex, out int totalRecord, int order, int userId, int postId, int parentId, int approved, int emailNotify, string keyword)
        {
            string condition = " 1=1 ";// "[ParentId]=0 and [PostId]=" + postId;

            if (userId != -1)
            {
                condition += " and userid=" + userId;
            }
            if (postId != -1)
            {
                condition += " and postId=" + postId;
            }
            if (parentId != -1)
            {
                condition += " and parentId=" + parentId;
            }

            if (approved != -1)
            {
                condition += " and approved=" + approved;
            }

            if (emailNotify != -1)
            {
                condition += " and emailNotify=" + emailNotify;
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                condition += string.Format(" and (content like '%{0}%' or author like '%{0}%' or ipaddress like '%{0}%' or email like '%{0}%'  or siteurl like '%{0}%' )", keyword);
            }

            string cmdTotalRecord = "select count(1) from Loachs_Comments where " + condition;

            totalRecord = Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdTotalRecord));

            //   throw new Exception(cmdTotalRecord);

            string cmdText = MYSQLHelper.GetPageSql("Loachs_Comments", "CommentId", "*", pageSize, pageIndex, order, condition);

            return(DataReaderToCommentList(MYSQLHelper.ExecuteReader(cmdText)));
        }
Beispiel #30
0
        /// <summary>
        /// 统计评论
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="postId"></param>
        /// <param name="incChild"></param>
        /// <returns></returns>
        public int GetCommentCount(int userId, int postId, bool incChild)
        {
            string condition = " 1=1 ";

            if (userId != -1)
            {
                condition += " and userId = " + userId;
            }
            if (postId != -1)
            {
                condition += " and postId = " + postId;
            }
            if (incChild == false)
            {
                condition += " and parentid=0";
            }
            string cmdText = "select count(1) from Loachs_Comments where " + condition;

            return(Convert.ToInt32(MYSQLHelper.ExecuteScalar(CommandType.Text, cmdText)));
        }