Esempio n. 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(MSSQLHelper.ExecuteScalar(cmdText));
         if (r == 0)
         {
             return(true);
         }
         post.Slug += "-2";
     }
 }
Esempio n. 2
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";

            SqlParameter[] prams =
            {
                MSSQLHelper.MakeInParam("@Type",         SqlDbType.Int,       1, (int)TermType.Tag),
                MSSQLHelper.MakeInParam("@Name",         SqlDbType.VarChar, 255, tag.Name),
                MSSQLHelper.MakeInParam("@Slug",         SqlDbType.VarChar, 255, tag.Slug),
                MSSQLHelper.MakeInParam("@Description",  SqlDbType.VarChar, 255, tag.Description),
                MSSQLHelper.MakeInParam("@Displayorder", SqlDbType.Int,       4, tag.Displayorder),
                MSSQLHelper.MakeInParam("@Count",        SqlDbType.Int,       4, tag.Count),
                MSSQLHelper.MakeInParam("@CreateDate",   SqlDbType.Date,      8, tag.CreateDate),
                MSSQLHelper.MakeInParam("@termid",       SqlDbType.Int,       1, tag.TagId),
            };
            return(Convert.ToInt32(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)));
        }
Esempio n. 3
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)";

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

            int newId = Convert.ToInt32(MSSQLHelper.ExecuteScalar("select top 1 [CommentId] from [loachs_comments]  order by [CommentId] desc"));

            return(newId);
        }
Esempio n. 4
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
                            )";

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

            int newId = Convert.ToInt32(MSSQLHelper.ExecuteScalar("select top 1 [termid] from [loachs_terms] order by [termid] desc"));

            return(newId);
        }
Esempio n. 5
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 )";

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

            if (r > 0)
            {
                return(Convert.ToInt32(MSSQLHelper.ExecuteScalar("select top 1 [UserId] from [loachs_users]  order by [UserId] desc")));
            }
            return(0);
        }
Esempio n. 6
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";

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

            return(Convert.ToInt32(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)));
        }
Esempio n. 7
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
                            )";

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

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

            if (r > 0)
            {
                return(Convert.ToInt32(MSSQLHelper.ExecuteScalar("select top 1 [linkid] from [loachs_links]  order by [linkid] desc")));
            }
            return(0);
        }
Esempio n. 8
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 ";

            SqlParameter[] prams =
            {
                MSSQLHelper.MakeInParam("@userName", SqlDbType.VarChar, 50, userName),
            };
            return(Convert.ToInt32(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdText, prams)) > 0);
        }
Esempio n. 9
0
        public SettingInfo GetSetting()
        {
            string cmdText = "select top 1 [setting] from [loachs_sites]";

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

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

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

            return((SettingInfo)obj);
        }
Esempio n. 10
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
                                )";

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

            //if (newId > 0)
            //{
            //    MSSQLHelper.ExecuteNonQuery(string.Format("update [loachs_users] set [postcount]=[postcount]+1 where [userid]={0}", postinfo.UserId));
            //    MSSQLHelper.ExecuteNonQuery("update [loachs_sites] set [postcount]=[postcount]+1");
            //    MSSQLHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]+1 where [termid]={0}", postinfo.CategoryId));
            //}
            return(newId);
        }
Esempio n. 11
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(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdTotalRecord));

            //   throw new Exception(cmdTotalRecord);

            string cmdText = MSSQLHelper.GetPageSql("[loachs_comments]", "[CommentId]", "*", pageSize, pageIndex, order, condition);

            return(DataReaderToCommentList(MSSQLHelper.ExecuteReader(cmdText)));
        }
Esempio n. 12
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(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdText)));
        }
Esempio n. 13
0
 /// <summary>
 /// 检查别名是否重复
 /// </summary>
 /// <param name="term"></param>
 /// <returns></returns>
 private bool CheckSlug(TagInfo term)
 {
     while (true)
     {
         string cmdText = string.Empty;
         if (term.TagId == 0)
         {
             cmdText = string.Format("select count(1) from [loachs_terms] where [Slug]='{0}' and [type]={1}", term.Slug, (int)TermType.Tag);
         }
         else
         {
             cmdText = string.Format("select count(1) from [loachs_terms] where [Slug]='{0}'  and [type]={1} and [termid]<>{2}", term.Slug, (int)TermType.Tag, term.TagId);
         }
         int r = Convert.ToInt32(MSSQLHelper.ExecuteScalar(cmdText));
         if (r == 0)
         {
             return(true);
         }
         term.Slug += "-2";
     }
 }
Esempio n. 14
0
        public List <PostInfo> GetPostList(int pageSize, int pageIndex, out int recordCount, int categoryId, int tagId, int userId, int recommend, int status, int topstatus, int hidestatus, string begindate, string enddate, string keyword)
        {
            string condition = " 1=1 ";

            if (categoryId != -1)
            {
                condition += " and categoryId=" + categoryId;
            }
            if (tagId != -1)
            {
                condition += " and tag like '%{" + tagId + "}%'";
            }
            if (userId != -1)
            {
                condition += " and userid=" + userId;
            }
            if (recommend != -1)
            {
                condition += " and recommend=" + recommend;
            }
            if (status != -1)
            {
                condition += " and status=" + status;
            }

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

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

            if (!string.IsNullOrEmpty(begindate))
            {
                condition += " and createdate>=#" + begindate + "#";
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                condition += " and createdate<#" + enddate + "#";
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                condition += string.Format(" and (summary like '%{0}%' or title like '%{0}%'  )", keyword);
            }

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

            //   throw new Exception(cmdTotalRecord);

            recordCount = StringHelper.ObjectToInt(MSSQLHelper.ExecuteScalar(CommandType.Text, cmdTotalRecord));


            string cmdText = MSSQLHelper.GetPageSql("[Loachs_Posts]", "[PostId]", "*", pageSize, pageIndex, 1, condition);



            return(DataReaderToCommentList(MSSQLHelper.ExecuteReader(cmdText)));
        }