Beispiel #1
0
        //获取用户的活动数据所有,按每个活动用户进行解析
        private static DataTable GetActivityByUser(int userID, string webUrl)
        {
            string listName = ConfigurationManager.AppSettings["listMyActivity"];//活动列表

            string    siteUrl      = "http://localhost";
            DataTable retDataTable = null;

            using (SPSite spSite = new SPSite(siteUrl)) //找到网站集
            {
                using (SPWeb spWeb = spSite.OpenWeb(webUrl))
                {
                    SPList spList = spWeb.Lists.TryGetList(listName);

                    if (spList != null)
                    {
                        SPQuery qry = new SPQuery();
                        qry.ViewFields = "<FieldRef Name='Action' /><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Author' />";
                        qry.Query      = @"<Where>
      <Eq><FieldRef Name='Author' LookupId='True' /><Value Type='Integer'>" + userID + "</Value></Eq></Where>";

                        SPListItemCollectionPosition lstPosi;
                        retDataTable = spList.GetDataTable(qry, SPListGetDataTableOptions.RetrieveLookupIdsOnly, out lstPosi);
                    }
                }
            }
            return(retDataTable);
        }
        // Private Methods (1) 

        private IEnumerable <INavObject> GetSettings()
        {
            return((IEnumerable <INavObject>)CacheStore.Current.Get(_key, new CacheStoreCategory(Web).Navigation, () =>
            {
                var links = new List <NavLink>();

                using (var spSite = new SPSite(SiteId, GetUserToken()))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(WebId))
                    {
                        SPList settingsList = spWeb.Lists.TryGetList("EPM Live Settings");

                        if (settingsList != null)
                        {
                            SPListItemCollectionPosition position;

                            DataTable settings = settingsList.GetDataTable(new SPQuery
                            {
                                Query = QUERY,
                                ViewFields = VIEW_FIELDS
                            }, SPListGetDataTableOptions.None, out position);

                            string webUrl = spWeb.Url;

                            var catLinks = new SortedDictionary <string, List <NavLink> >();

                            foreach (DataRow row in settings.Rows)
                            {
                                string category = (S(row["Category"]).Split(')')[1]).Trim();

                                var link = new NavLink
                                {
                                    Title = S(row["Title"]),
                                    Url = webUrl + S(row["URL"]) + "?Source={page}&BackTo={page}",
                                    Category = category
                                };

                                if (!catLinks.ContainsKey(category))
                                {
                                    catLinks.Add(category, new List <NavLink>());
                                }

                                catLinks[category].Add(link);
                            }

                            links.AddRange(catLinks.SelectMany(p => p.Value.OrderBy(l => l.Title)));
                        }
                    }
                }

                return links;
            }, true).Value);
        }
Beispiel #3
0
        private static System.Data.DataTable GetDataTable(SPList list, SPView view)
        {
            var query = new SPQuery(view);
            SPListItemCollectionPosition position;
            var flags  = SPListGetDataTableOptions.UseBooleanDataType | SPListGetDataTableOptions.UseCalculatedDataType;
            var result = list.GetDataTable(query, flags, out position);

            while (position != null)
            {
                query.ListItemCollectionPosition = position;
                list.AppendDataTable(query, flags, result, out position);
            }
            return(result);
        }
        /// <summary>
        /// 某个人的一段时间内,助手数据ActualDuring
        /// tDays,按日期还是所有的操作
        /// </summary>
        /// <returns></returns>
        private static DataTable GetAssitants(int userID, int tDays, string listName, DateTime dtStart, DateTime dtTo)
        {
            DataTable retDataTable = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite spSite = new SPSite(SPContext.Current.Site.ID)) //找到网站集
                {
                    using (SPWeb spWeb = spSite.OpenWeb(SPContext.Current.Web.ID))
                    {
                        SPList spList = spWeb.Lists.TryGetList(listName);
                        if (spList != null)
                        {
                            SPQuery qry = new SPQuery();

                            qry.ViewFields = "<FieldRef Name='Author' /><FieldRef Name='ActualDuring' /><FieldRef Name='Action' /><FieldRef Name='ActualDate' />";
                            if (tDays > 0)//按日期
                            {
                                string strFrom = SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtStart);
                                string strTo   = SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtTo.AddDays(1));

                                qry.Query = @"<Where><And><And><Geq><FieldRef Name='ActualDate' /><Value Type='DateTime'>" + strFrom
                                            + "</Value></Geq><Lt><FieldRef Name = 'ActualDate' /><Value Type = 'DateTime'> " + strTo
                                            + "</Value></Lt></And><Eq><FieldRef Name='Author' LookupId='True' /><Value Type='Lookup'>" + userID + "</Value></Eq></And></Where><OrderBy><FieldRef Name='ActualDate' /></OrderBy>";
                            }
                            else//等于0为所有的数据
                            {
                                qry.Query = @"<Where><Eq><FieldRef Name='Author' LookupId='True' /><Value Type='Lookup'>" + userID + "</Value></Eq></Where><OrderBy><FieldRef Name='ActualDate' /></OrderBy>";
                            }

                            SPListItemCollectionPosition lstPosi;
                            retDataTable = spList.GetDataTable(qry, SPListGetDataTableOptions.RetrieveLookupIdsOnly, out lstPosi);
                            //SPListItemCollection listItems = spList.GetItems(qry);
                            //if (listItems.Count > 0)
                            //    retDataTable = listItems.GetDataTable();
                        }
                    }
                }
            });
            return(retDataTable);
        }