/// <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)"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@PostId", OleDbType.Integer, 4, comment.PostId), OleDbHelper.MakeInParam("@ParentId", OleDbType.Integer, 4, comment.ParentId), OleDbHelper.MakeInParam("@UserId", OleDbType.Integer, 4, comment.UserId), OleDbHelper.MakeInParam("@Name", OleDbType.VarWChar, 255, comment.Name), OleDbHelper.MakeInParam("@Email", OleDbType.VarWChar, 255, comment.Email), OleDbHelper.MakeInParam("@SiteUrl", OleDbType.VarWChar, 255, comment.SiteUrl), OleDbHelper.MakeInParam("@Content", OleDbType.VarWChar, 255, comment.Content), OleDbHelper.MakeInParam("@EmailNotify", OleDbType.Integer, 4, comment.EmailNotify), OleDbHelper.MakeInParam("@IpAddress", OleDbType.VarWChar, 255, comment.IpAddress), OleDbHelper.MakeInParam("@CreateDate", OleDbType.Date, 8, comment.CreateDate), OleDbHelper.MakeInParam("@Approved", OleDbType.Integer, 4, comment.Approved), }; OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); int newId = Convert.ToInt32(OleDbHelper.ExecuteScalar("select top 1 [CommentId] from [loachs_comments] order by [CommentId] desc")); return(newId); }
/// <summary> /// 添加分类 /// </summary> /// <param name="category"></param> /// <returns></returns> public int InsertCategory(CategoryInfo category) { CheckSlug(category); string cmdText = @"insert into [loachs_terms] ( [Type],[Name],[Slug],[Description],[Displayorder],[Count],[CreateDate] ) values ( @Type,@Name,@Slug,@Description,@Displayorder,@Count,@CreateDate )"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@Type", OleDbType.Integer, 1, (int)TermType.Category), OleDbHelper.MakeInParam("@Name", OleDbType.VarWChar, 255, category.Name), OleDbHelper.MakeInParam("@Slug", OleDbType.VarWChar, 255, category.Slug), OleDbHelper.MakeInParam("@Description", OleDbType.VarWChar, 255, category.Description), OleDbHelper.MakeInParam("@Displayorder", OleDbType.Integer, 4, category.Displayorder), OleDbHelper.MakeInParam("@Count", OleDbType.Integer, 4, category.Count), OleDbHelper.MakeInParam("@CreateDate", OleDbType.Date, 8, category.CreateDate) }; OleDbHelper.ExecuteScalar(CommandType.Text, cmdText, prams); int newId = Convert.ToInt32(OleDbHelper.ExecuteScalar("select top 1 [termid] from [loachs_terms] order by [termid] desc")); return(newId); }
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 )"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@type", OleDbType.Integer, 4, link.Type), OleDbHelper.MakeInParam("@name", OleDbType.VarWChar, 100, link.Name), OleDbHelper.MakeInParam("@href", OleDbType.VarWChar, 255, link.Href), OleDbHelper.MakeInParam("@position", OleDbType.Integer, 4, link.Position), OleDbHelper.MakeInParam("@target", OleDbType.VarWChar, 50, link.Target), OleDbHelper.MakeInParam("@description", OleDbType.VarWChar, 255, link.Description), OleDbHelper.MakeInParam("@displayorder", OleDbType.Integer, 4, link.Displayorder), OleDbHelper.MakeInParam("@status", OleDbType.Integer, 4, link.Status), OleDbHelper.MakeInParam("@createdate", OleDbType.Date, 8, link.CreateDate), }; int r = OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); if (r > 0) { return(Convert.ToInt32(OleDbHelper.ExecuteScalar("select top 1 [linkid] from [loachs_links] order by [linkid] desc"))); } return(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"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@type", OleDbType.Integer, 4, link.Type), OleDbHelper.MakeInParam("@name", OleDbType.VarWChar, 100, link.Name), OleDbHelper.MakeInParam("@href", OleDbType.VarWChar, 255, link.Href), OleDbHelper.MakeInParam("@position", OleDbType.Integer, 4, link.Position), OleDbHelper.MakeInParam("@target", OleDbType.VarWChar, 50, link.Target), OleDbHelper.MakeInParam("@description", OleDbType.VarWChar, 255, link.Description), OleDbHelper.MakeInParam("@displayorder", OleDbType.Integer, 4, link.Displayorder), OleDbHelper.MakeInParam("@status", OleDbType.Integer, 4, link.Status), OleDbHelper.MakeInParam("@createdate", OleDbType.Date, 8, link.CreateDate), OleDbHelper.MakeInParam("@linkid", OleDbType.Integer, 4, link.LinkId), }; return(Convert.ToInt32(OleDbHelper.ExecuteScalar(CommandType.Text, cmdText, prams))); }
/// <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 "; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@PostId", OleDbType.Integer, 4, comment.PostId), OleDbHelper.MakeInParam("@ParentId", OleDbType.Integer, 4, comment.ParentId), OleDbHelper.MakeInParam("@UserId", OleDbType.Integer, 4, comment.UserId), OleDbHelper.MakeInParam("@Name", OleDbType.VarWChar, 255, comment.Name), OleDbHelper.MakeInParam("@Email", OleDbType.VarWChar, 255, comment.Email), OleDbHelper.MakeInParam("@SiteUrl", OleDbType.VarWChar, 255, comment.SiteUrl), OleDbHelper.MakeInParam("@Content", OleDbType.VarWChar, 255, comment.Content), OleDbHelper.MakeInParam("@EmailNotify", OleDbType.Integer, 4, comment.EmailNotify), OleDbHelper.MakeInParam("@IpAddress", OleDbType.VarWChar, 255, comment.IpAddress), OleDbHelper.MakeInParam("@CreateDate", OleDbType.Date, 8, comment.CreateDate), OleDbHelper.MakeInParam("@Approved", OleDbType.Integer, 4, comment.Approved), OleDbHelper.MakeInParam("@CommentId", OleDbType.Integer, 4, comment.CommentId), }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public int DeleteLink(int linkId) { string cmdText = "delete from [loachs_links] where [linkid] = @linkid"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@linkid", OleDbType.Integer, 4, linkId) }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public int DeleteCategory(int categoryId) { string cmdText = "delete from [loachs_terms] where [termid] = @termid"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@termid", OleDbType.Integer, 4, categoryId) }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public int UpdatePostViewCount(int postId, int addCount) { string cmdText = "update [loachs_posts] set [viewcount] = [viewcount] + @addcount where [postid]=@postid"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@addcount", OleDbType.Integer, 4, addCount), OleDbHelper.MakeInParam("@postid", OleDbType.Integer, 4, postId), }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public bool UpdateSetting(SettingInfo setting) { string cmdText = @"update [loachs_sites] set [setting]=@setting"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@setting", OleDbType.VarWChar, 0, Serialize(setting)), }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams) == 1); }
/// <summary> /// 获取实体 /// </summary> /// <param name="commentId"></param> /// <returns></returns> public CommentInfo GetComment(int commentId) { string cmdText = "select * from [loachs_comments] where [commentId] = @commentId"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@commentId", OleDbType.Integer, 4, commentId) }; List <CommentInfo> list = DataReaderToCommentList(OleDbHelper.ExecuteReader(cmdText, prams)); return(list.Count > 0 ? list[0] : null); }
/// <summary> /// 根据日志ID删除评论 /// </summary> /// <param name="postId">日志ID</param> /// <returns></returns> public int DeleteCommentByPost(int postId) { string cmdText = "delete from [loachs_comments] where [postId] = @postId"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@postId", OleDbType.Integer, 4, postId) }; int result = OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); return(result); }
public CategoryInfo GetCategory(int categoryId) { string cmdText = "select * from [loachs_terms] where [termid] = @termid"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@termid", OleDbType.Integer, 4, categoryId) }; List <CategoryInfo> list = DataReaderToList(OleDbHelper.ExecuteReader(CommandType.Text, cmdText, prams)); return(list.Count > 0 ? list[0] : null); }
/// <summary> /// 获取实体 /// </summary> /// <param name="slug"></param> /// <returns></returns> public PostInfo GetPost(string slug) { string cmdText = "select top 1 * from [loachs_posts] where [slug] = @slug"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@slug", OleDbType.VarWChar, 200, slug) }; List <PostInfo> list = DataReaderToCommentList(OleDbHelper.ExecuteReader(cmdText, prams)); return(list.Count > 0 ? list[0] : null); }
/// <summary> /// 获取实体 /// </summary> /// <param name="PostId">主键</param> /// <returns></returns> public PostInfo GetPost(int postid) { string cmdText = "select top 1 * from [loachs_posts] where [PostId] = @PostId"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@PostId", OleDbType.Integer, 4, postid) }; List <PostInfo> list = DataReaderToCommentList(OleDbHelper.ExecuteReader(cmdText, prams)); return(list.Count > 0 ? list[0] : null); }
/// <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"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@commentId", OleDbType.Integer, 4, commentId) }; int result = OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); return(result); }
public bool UpdateStatistics(StatisticsInfo statistics) { string cmdText = @"update [loachs_sites] set PostCount=@PostCount, CommentCount=@CommentCount, VisitCount=@VisitCount, TagCount=@TagCount"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@PostCount", OleDbType.Integer, 4, statistics.PostCount), OleDbHelper.MakeInParam("@CommentCount", OleDbType.Integer, 4, statistics.CommentCount), OleDbHelper.MakeInParam("@VisitCount", OleDbType.Integer, 4, statistics.VisitCount), OleDbHelper.MakeInParam("@TagCount", OleDbType.Integer, 4, statistics.TagCount), }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams) == 1); }
/// <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 )"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@CategoryId", OleDbType.Integer, 4, postinfo.CategoryId), OleDbHelper.MakeInParam("@Title", OleDbType.VarWChar, 255, postinfo.Title), OleDbHelper.MakeInParam("@Summary", OleDbType.VarWChar, 0, postinfo.Summary), OleDbHelper.MakeInParam("@Content", OleDbType.VarWChar, 0, postinfo.Content), OleDbHelper.MakeInParam("@Slug", OleDbType.VarWChar, 255, postinfo.Slug), OleDbHelper.MakeInParam("@UserId", OleDbType.Integer, 4, postinfo.UserId), OleDbHelper.MakeInParam("@CommentStatus", OleDbType.Integer, 1, postinfo.CommentStatus), OleDbHelper.MakeInParam("@CommentCount", OleDbType.Integer, 4, postinfo.CommentCount), OleDbHelper.MakeInParam("@ViewCount", OleDbType.Integer, 4, postinfo.ViewCount), OleDbHelper.MakeInParam("@Tag", OleDbType.VarWChar, 255, postinfo.Tag), OleDbHelper.MakeInParam("@UrlFormat", OleDbType.Integer, 1, postinfo.UrlFormat), OleDbHelper.MakeInParam("@Template", OleDbType.VarChar, 50, postinfo.Template), OleDbHelper.MakeInParam("@Recommend", OleDbType.Integer, 1, postinfo.Recommend), OleDbHelper.MakeInParam("@Status", OleDbType.Integer, 1, postinfo.Status), OleDbHelper.MakeInParam("@TopStatus", OleDbType.Integer, 1, postinfo.TopStatus), OleDbHelper.MakeInParam("@HideStatus", OleDbType.Integer, 1, postinfo.HideStatus), OleDbHelper.MakeInParam("@CreateDate", OleDbType.Date, 8, postinfo.CreateDate), OleDbHelper.MakeInParam("@UpdateDate", OleDbType.Date, 8, postinfo.UpdateDate) }; OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); int newId = StringHelper.ObjectToInt(OleDbHelper.ExecuteScalar("select top 1 [PostId] from [Loachs_Posts] order by [PostId] desc")); //if (newId > 0) //{ // OleDbHelper.ExecuteNonQuery(string.Format("update [loachs_users] set [postcount]=[postcount]+1 where [userid]={0}", postinfo.UserId)); // OleDbHelper.ExecuteNonQuery("update [loachs_sites] set [postcount]=[postcount]+1"); // OleDbHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]+1 where [termid]={0}", postinfo.CategoryId)); //} return(newId); }
/// <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) //{ // OleDbHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]-1 where [termid]={0}", oldPost.CategoryId)); // OleDbHelper.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"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@CategoryId", OleDbType.Integer, 4, postinfo.CategoryId), OleDbHelper.MakeInParam("@Title", OleDbType.VarWChar, 255, postinfo.Title), OleDbHelper.MakeInParam("@Summary", OleDbType.VarWChar, 0, postinfo.Summary), OleDbHelper.MakeInParam("@Content", OleDbType.VarWChar, 0, postinfo.Content), OleDbHelper.MakeInParam("@Slug", OleDbType.VarWChar, 255, postinfo.Slug), OleDbHelper.MakeInParam("@UserId", OleDbType.Integer, 4, postinfo.UserId), OleDbHelper.MakeInParam("@CommentStatus", OleDbType.Integer, 1, postinfo.CommentStatus), OleDbHelper.MakeInParam("@CommentCount", OleDbType.Integer, 4, postinfo.CommentCount), OleDbHelper.MakeInParam("@ViewCount", OleDbType.Integer, 4, postinfo.ViewCount), OleDbHelper.MakeInParam("@Tag", OleDbType.VarWChar, 255, postinfo.Tag), OleDbHelper.MakeInParam("@UrlFormat", OleDbType.Integer, 1, postinfo.UrlFormat), OleDbHelper.MakeInParam("@Template", OleDbType.VarChar, 50, postinfo.Template), OleDbHelper.MakeInParam("@Recommend", OleDbType.Integer, 1, postinfo.Recommend), OleDbHelper.MakeInParam("@Status", OleDbType.Integer, 1, postinfo.Status), OleDbHelper.MakeInParam("@TopStatus", OleDbType.Integer, 1, postinfo.TopStatus), OleDbHelper.MakeInParam("@HideStatus", OleDbType.Integer, 1, postinfo.HideStatus), OleDbHelper.MakeInParam("@CreateDate", OleDbType.Date, 8, postinfo.CreateDate), OleDbHelper.MakeInParam("@UpdateDate", OleDbType.Date, 8, postinfo.UpdateDate), OleDbHelper.MakeInParam("@PostId", OleDbType.Integer, 4, postinfo.PostId), }; return(OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
/// <summary> /// 删除 /// </summary> /// <param name="PostId">主键</param> /// <returns>删除的行数</returns> public int DeletePost(int postid) { PostInfo oldPost = GetPost(postid); //删除前 string cmdText = "delete from [loachs_posts] where [PostId] = @PostId"; OleDbParameter[] prams = { OleDbHelper.MakeInParam("@PostId", OleDbType.Integer, 4, postid) }; int result = OleDbHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); //if (oldPost != null) //{ // OleDbHelper.ExecuteNonQuery(string.Format("update [loachs_users] set [postcount]=[postcount]-1 where [userid]={0}", oldPost.UserId)); // OleDbHelper.ExecuteNonQuery("update [loachs_sites] set [postcount]=[postcount]-1"); // OleDbHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]-1 where [termid]={0}", oldPost.CategoryId)); //} return(result); }