Esempio n. 1
0
        /// </summary>
        /// <param name="ListName">列表名称连接的字符串</param>
        /// <param name="subWebUrl">子网站Url</param>
        /// <returns>统计的各项活动积分数组</returns>
        private int[] StatisticAllList(string ListName, string subWebUrl)
        {
            SPQuery oQuery;
            SPList  sList;

            string[] lstName   = ListName.Split(';');
            string[] qr        = QR.Split(';');
            string[] ppr       = PPR.Split(';');
            int[]    itmCounts = new int[lstName.Length + 1];
            int[]    scores    = new int[lstName.Length + 1];
            SPUser   logUser   = SPContext.Current.Web.CurrentUser;

            if (logUser == null)//获取所有用户的信息
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID])
                        {
                            itmCounts[0] = GetTotalNewsFeeds();//微博
                            scores[0]    = itmCounts[0] * int.Parse(qr[0]) * int.Parse(ppr[0]);
                            int i        = 0;
                            int j        = 0;
                            foreach (string mList in lstName)
                            {
                                try
                                {
                                    if (mList == "Posts" && subWebUrl != "")//统计备忘录
                                    {
                                        SPWeb subWeb = web.Webs[subWebUrl];
                                        sList        = subWeb.Lists.TryGetList(mList);
                                    }
                                    else
                                    {
                                        sList = web.Lists.TryGetList(mList);
                                    }
                                    i      = i + 1;
                                    oQuery = new SPQuery();
                                    oQuery.ViewAttributes = "Scope='RecursiveAll'";
                                    //oQuery.Query = "<Where><Eq><FieldRef Name='Author'/><Value Type='Text'>" + logUser.Name + "</Value></Eq></Where>";
                                    SPListItemCollection lstItems = sList.GetItems(oQuery);
                                    j = lstItems.Count;//个人
                                    EnumerateList(ref j, web, mList, "");
                                    itmCounts[i] = j;
                                    scores[i]    = itmCounts[i] * int.Parse(qr[i]) * int.Parse(ppr[i]);
                                }
                                catch
                                { }
                            }
                        }
                    }
                });
            }
            else
            {
                //int i = 1;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID])
                        {
                            itmCounts[0] = GetTotalNewsFeeds();//微博
                            scores[0]    = itmCounts[0] * int.Parse(qr[0]) * int.Parse(ppr[0]);
                            int i        = 0;
                            int j        = 0;
                            foreach (string mList in lstName)
                            {
                                try
                                {
                                    if (mList == "Posts" && subWebUrl != "")//统计备忘录
                                    {
                                        SPWeb subWeb = web.Webs[subWebUrl];
                                        sList        = subWeb.Lists.TryGetList(mList);
                                    }
                                    else
                                    {
                                        sList = web.Lists.TryGetList(mList);
                                    }
                                    i      = i + 1;
                                    oQuery = new SPQuery();
                                    oQuery.ViewAttributes         = "Scope='RecursiveAll'";
                                    oQuery.Query                  = "<Where><Eq><FieldRef Name='Author'/><Value Type='Text'>" + logUser.Name + "</Value></Eq></Where>";
                                    SPListItemCollection lstItems = sList.GetItems(oQuery);
                                    j = lstItems.Count;//个人
                                    EnumerateList(ref j, web, mList, logUser.Name);
                                    itmCounts[i] = j;
                                    scores[i]    = itmCounts[i] * int.Parse(qr[i]) * int.Parse(ppr[i]);
                                }
                                catch
                                { }
                            }
                        }
                    }
                });
            }

            return(scores);
        }