public override bool Equals(object obj) { DateTimeScope target = obj as DateTimeScope; if (target == null) { return(false); } return(this == target); }
/// <summary> /// 获取一页群聊天记录。 /// </summary> /// <param name="groupID">群ID</param> /// <param name="pageSize">页大小</param> /// <param name="pageIndex">页索引</param> /// <returns>聊天记录页</returns> public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope chatRecordTimeScope, string groupID, int pageSize, int pageIndex) { if (this.transactionScopeFactory == null) { return new ChatRecordPage(0, 0, new List<ChatMessageRecord>()); } DateTimeScope timeScope = null; DateTime now = DateTime.Now; if (chatRecordTimeScope == ChatRecordTimeScope.RecentWeek) //一周 { timeScope = new DateTimeScope(now.AddDays(-7), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.RecentMonth)//一月 { timeScope = new DateTimeScope(now.AddDays(-31), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.Recent3Month)//三月 { timeScope = new DateTimeScope(now.AddDays(-91), now); } else //全部 { } List<Filter> filterList = new List<Filter>(); filterList.Add(new Filter(ChatMessageRecord._AudienceID, groupID)); filterList.Add(new Filter(ChatMessageRecord._IsGroupChat, true)); if (timeScope != null) { filterList.Add(new Filter(ChatMessageRecord._OccureTime, new DateTime[] { timeScope.StartDate, timeScope.EndDate }, ComparisonOperators.BetweenAnd)); } SimpleFilterTree tree = new SimpleFilterTree(filterList); //最后一页 if (pageIndex == int.MaxValue) { int total = 0; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<ChatMessageRecord> accesser = scope.NewOrmAccesser<ChatMessageRecord>(); total = (int)accesser.GetCount(tree); scope.Commit(); } int pageCount = total / pageSize; if (total % pageSize > 0) { pageCount += 1; } pageIndex = pageCount - 1; } int totalCount = 0; ChatMessageRecord[] page = null; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<ChatMessageRecord> accesser = scope.NewOrmAccesser<ChatMessageRecord>(); page = accesser.GetPage(tree, pageSize, pageIndex, ChatMessageRecord._AutoID, true, out totalCount); scope.Commit(); } return new ChatRecordPage(totalCount, pageIndex, new List<ChatMessageRecord>(page)); }