Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns ArrayList of ActivityInfo objects.
        /// </summary>
        public static ArrayList GetGroupsActivity(DateTime fromDate, DateTime toDate, ActivityReportType type, int topCount)
        {
            ArrayList    list = new ArrayList();
            Hashtable    hash = new Hashtable();
            ActivityInfo group;

            foreach (UserActivityInfo user in GetUsersActivity(fromDate, toDate, type, 0))
            {
                group = (ActivityInfo)hash[user.IMGroupId];
                if (group == null)
                {
                    string sDisplayName = "";
                    using (IDataReader _group = UserReport.GetIMGroup(user.IMGroupId))
                    {
                        if (_group.Read())
                        {
                            sDisplayName = _group["IMGroupName"].ToString();
                        }
                    }
                    group = new ActivityInfo(sDisplayName);
                    hash[user.IMGroupId] = group;
                    list.Add(group);
                }
                group.AddInfo(user);
            }

            // 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);
        }