public static DataView GetTop10Users(DateTime StartDate, DateTime EndDate) { int DefaultBias = UserReport.GetTimeZoneBias(Security.CurrentUser.TimeZoneId); DataTable dt = new DataTable("Top10writers"); dt.Columns.Add("Place"); dt.Columns.Add("Group"); dt.Columns.Add("Name"); dt.Columns.Add("TotalMessages"); using (IDataReader reader = DBUserReport.GetTop10Users(StartDate, EndDate, DefaultBias)) { int place = 1; while (reader.Read()) { int iUserId = reader.GetInt32(0); string sName = ""; int iIMGroupId = 0; using (IDataReader _obj = UserReport.GetUserInfoByOriginalId(iUserId)) { if (_obj.Read()) { sName = _obj["FirstName"].ToString() + " " + _obj["LastName"].ToString(); iIMGroupId = (int)_obj["IMGroupId"]; } else { continue; } } DataRow dr = dt.NewRow(); dr["Place"] = place.ToString(); dr["TotalMessages"] = reader.GetInt32(1).ToString(); dr["Name"] = sName; if (iIMGroupId > 0) { using (IDataReader _obj = UserReport.GetIMGroup(iIMGroupId)) { if (_obj.Read()) { dr["Group"] = _obj["IMGroupName"].ToString(); } } } dt.Rows.Add(dr); place++; } } return(dt.DefaultView); }
/// <summary> /// Returns ArrayList of UserActivityInfo objects. /// </summary> public static ArrayList GetUsersActivity(DateTime fromDate, DateTime toDate, ActivityReportType type, int topCount) { ArrayList list = new ArrayList(); UserActivityInfo user; using (IDataReader reader = GetUsersByCompany()) { while (reader.Read()) { string sDisplayName = reader["DisplayName"].ToString(); int iIMGroupId = (int)reader["IMGroupId"]; int user_id = (int)reader["UserId"]; user = new UserActivityInfo(sDisplayName, iIMGroupId); list.Add(user); using (IDataReader _obj = UserReport.GetUserInfoByOriginalId(user_id)) { if (_obj.Read()) { user_id = (int)_obj["UserId"]; } else { continue; } } int DefaultBias = UserReport.GetTimeZoneBias(Security.CurrentUser.TimeZoneId); switch (type) { case ActivityReportType.Messages: using (IDataReader _obj = DBUserReport.GetUserStats(user_id, fromDate, toDate, DefaultBias)) { if (_obj.Read()) { user.Count = (int)_obj["MsgSent"]; } } break; case ActivityReportType.FilesExchanged: using (IDataReader _obj = DBUserReport.GetUserStats(user_id, fromDate, toDate, DefaultBias)) { if (_obj.Read()) { user.Count = (int)_obj["FilesSent"]; } } break; case ActivityReportType.IMLogins: using (IDataReader _obj = DBUserReport.GetUserStats(user_id, fromDate, toDate, DefaultBias)) { if (_obj.Read()) { user.Count = (int)_obj["LoginsClient"]; } } break; case ActivityReportType.PortalLogins: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["PortalLogins"]; } } break; case ActivityReportType.CalendarEntries: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewEventsCount"]; } } break; case ActivityReportType.ActiveProjects: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewProjectsCount"]; } } break; case ActivityReportType.FilesPublished: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewAssetsCount"]; } } break; case ActivityReportType.FileVersionsPublished: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewAssetVersionsCount"]; } } break; case ActivityReportType.NewIssues: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewIncidentsCount"]; } } break; case ActivityReportType.NewTasks: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewTasksCount"]; } } break; case ActivityReportType.NewToDos: using (IDataReader _obj = GetQuickSnapshotReport(fromDate, toDate, user_id)) { if (_obj.Read()) { user.Count = (int)_obj["NewToDosCount"]; } } break; default: break; } } } // Leave only topCount items if (topCount > 0) { list.Sort(); if (list.Count > topCount) { list.RemoveRange(topCount, list.Count - topCount); } } // Remove items with zero counter for (int i = 0; i < list.Count;) { if (((ActivityInfo)list[i]).Count == 0) { list.RemoveAt(i); } else { i++; } } return(list); }