/// <summary> /// /// </summary> /// <param name="targetID"></param> /// <param name="type"></param> /// <param name="getCount">取最新的前N条 和 最旧的一条</param> /// <param name="isGetAll"></param> /// <returns></returns> public override CommentCollection GetComments(int targetID, CommentType type, int getCount, bool isGetAll) { using (SqlQuery query = new SqlQuery()) { if (isGetAll) { query.CommandText = "SELECT * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID AND IsApproved = 1 ORDER BY CommentID ASC;"; } else { query.CommandText = @" SELECT TOP(@TopCount) * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID AND IsApproved = 1 ORDER BY CommentID DESC; SELECT TOP 1 * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID ORDER BY CommentID ASC; "; query.CreateTopParameter("@TopCount", getCount); } query.CreateParameter <int>("@TargetID", targetID, SqlDbType.Int); query.CreateParameter <int>("@Type", (int)type, SqlDbType.TinyInt); CommentCollection comments = new CommentCollection(); using (XSqlDataReader reader = query.ExecuteReader()) { if (isGetAll) { while (reader.Read()) { comments.Add(new Comment(reader)); } } else { while (reader.Read()) { comments.Insert(0, new Comment(reader)); } if (reader.NextResult()) { while (reader.Read()) { comments.Insert(0, new Comment(reader)); } } } return(comments); } } }
public void AddAnnotation(IAnnotation annotation) { if (annotation.Comments.Count != 0) { if (removedAnnotation == null || removedAnnotation != null && removedAnnotation.AnnotationId != annotation.AnnotationId) { CommentCollection.Add(annotation.Comments[0]); AnnotationCount = CommentCollection.Count.ToString(); } else if (removedAnnotation.AnnotationId == annotation.AnnotationId) { CommentCollection.Insert(removedIndex, annotation.Comments[0]); AnnotationCount = CommentCollection.Count.ToString(); } } }
/// <summary> /// /// </summary> /// <param name="targetID"></param> /// <param name="type"></param> /// <param name="getCount">取最新的前N条 和 最旧的一条</param> /// <param name="isGetAll"></param> /// <returns></returns> public override CommentCollection GetComments(int targetID, CommentType type, int getCount, bool isGetAll) { using (SqlQuery query = new SqlQuery()) { if (isGetAll) { query.CommandText = "SELECT * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID AND IsApproved = 1 ORDER BY CommentID ASC;"; } else { query.CommandText = @" SELECT TOP(@TopCount) * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID AND IsApproved = 1 ORDER BY CommentID DESC; SELECT TOP 1 * FROM [bx_Comments] WHERE Type = @Type AND TargetID = @TargetID ORDER BY CommentID ASC; "; query.CreateTopParameter("@TopCount", getCount); } query.CreateParameter<int>("@TargetID", targetID, SqlDbType.Int); query.CreateParameter<int>("@Type", (int)type, SqlDbType.TinyInt); CommentCollection comments = new CommentCollection(); using (XSqlDataReader reader = query.ExecuteReader()) { if (isGetAll) { while (reader.Read()) { comments.Add(new Comment(reader)); } } else { while (reader.Read()) { comments.Insert(0, new Comment(reader)); } if (reader.NextResult()) { while (reader.Read()) { comments.Insert(0, new Comment(reader)); } } } return comments; } } }