/// <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 "; 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.MakeInParam("@CommentId", SqlDbType.Int, 4, comment.CommentId), }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
/// <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); }
/// <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); }
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); }
public int DeleteTag(int tagId) { string cmdText = "delete from [loachs_terms] where [termid] = @termid"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@termid", SqlDbType.Int, 4, tagId) }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public int DeleteLink(int linkId) { string cmdText = "delete from [loachs_links] where [linkid] = @linkid"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@linkid", SqlDbType.Int, 4, linkId) }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
/// <summary> /// 删除 /// </summary> /// <param name="userid"></param> /// <returns></returns> public int DeleteUser(int userid) { string cmdText = "delete from [loachs_users] where [userid] = @userid"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@userid", SqlDbType.Int, 4, userid) }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public int UpdatePostViewCount(int postId, int addCount) { string cmdText = "update [loachs_posts] set [viewcount] = [viewcount] + @addcount where [postid]=@postid"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@addcount", SqlDbType.Int, 4, addCount), MSSQLHelper.MakeInParam("@postid", SqlDbType.Int, 4, postId), }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }
public bool UpdateSetting(SettingInfo setting) { string cmdText = @"update [loachs_sites] set [setting]=@setting"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@setting", SqlDbType.VarChar, 0, Serialize(setting)), }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams) == 1); }
/// <summary> /// 根据日志ID删除评论 /// </summary> /// <param name="postId">日志ID</param> /// <returns></returns> public int DeleteCommentByPost(int postId) { string cmdText = "delete from [loachs_comments] where [postId] = @postId"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@postId", SqlDbType.Int, 4, postId) }; int result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); return(result); }
/// <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"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@commentId", SqlDbType.Int, 4, commentId) }; int result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); return(result); }
public StatisticsInfo GetStatistics() { string cmdText = "select top 1 * from [loachs_sites]"; 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(MSSQLHelper.ExecuteReader(cmdText)); if (list.Count == 0) { MSSQLHelper.ExecuteNonQuery(insertText); } list = DataReaderToList(MSSQLHelper.ExecuteReader(cmdText)); return(list.Count > 0 ? list[0] : null); }
public bool UpdateStatistics(StatisticsInfo statistics) { string cmdText = @"update [loachs_sites] set PostCount=@PostCount, CommentCount=@CommentCount, VisitCount=@VisitCount, TagCount=@TagCount"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@PostCount", SqlDbType.Int, 4, statistics.PostCount), MSSQLHelper.MakeInParam("@CommentCount", SqlDbType.Int, 4, statistics.CommentCount), MSSQLHelper.MakeInParam("@VisitCount", SqlDbType.Int, 4, statistics.VisitCount), MSSQLHelper.MakeInParam("@TagCount", SqlDbType.Int, 4, statistics.TagCount), }; return(MSSQLHelper.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 )"; 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); }
/// <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) //{ // MSSQLHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]-1 where [termid]={0}", oldPost.CategoryId)); // MSSQLHelper.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"; 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.MakeInParam("@PostId", SqlDbType.Int, 4, postinfo.PostId), }; return(MSSQLHelper.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"; SqlParameter[] prams = { MSSQLHelper.MakeInParam("@PostId", SqlDbType.Int, 4, postid) }; int result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams); //if (oldPost != null) //{ // MSSQLHelper.ExecuteNonQuery(string.Format("update [loachs_users] set [postcount]=[postcount]-1 where [userid]={0}", oldPost.UserId)); // MSSQLHelper.ExecuteNonQuery("update [loachs_sites] set [postcount]=[postcount]-1"); // MSSQLHelper.ExecuteNonQuery(string.Format("update [loachs_terms] set [count]=[count]-1 where [termid]={0}", oldPost.CategoryId)); //} return(result); }
/// <summary> /// 更新 /// </summary> /// <param name="_userinfo"></param> /// <returns></returns> public int UpdateUser(UserInfo _userinfo) { string cmdText = @"update [loachs_users] set [Type]=@Type, [UserName]=@UserName, [Name]=@Name, [Password]=@Password, [Email]=@Email, [SiteUrl]=@SiteUrl, [AvatarUrl]=@AvatarUrl, [Description]=@Description, [Displayorder]=@Displayorder, [Status]=@Status, [PostCount]=@PostCount, [CommentCount]=@CommentCount, [CreateDate]=@CreateDate where UserId=@UserId"; 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), MSSQLHelper.MakeInParam("@UserId", SqlDbType.Int, 4, _userinfo.UserId), }; return(MSSQLHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams)); }