public static List <Objective> GetAppraisalFormObjectives(int appraisalFormID, string currentWebUrl) { List <Objective> result = new List <Objective>(); SPQuery objectivesQuery = new SPQuery() { Query = String.Format(@"<Where><Eq><FieldRef Name='AppraisalFormID'/><Value Type='Lookup'>{0}</Value></Eq></Where>", appraisalFormID) }; SPListItemCollection queryObjectivesItems = SPListHelper.GetListItemsByQuery(Configuration.ObjectivesListName, objectivesQuery, currentWebUrl); if (queryObjectivesItems != null && queryObjectivesItems.Count > 0) { List <int> objectiveIds = queryObjectivesItems.OfType <SPListItem>().Select(i => i.ID).ToList(); SPQuery helpersQuery = new SPQuery() { Query = String.Format(@"<Where>{0}</Where>", objectiveIds.ToCamlIn("ObjectiveID", null)) }; SPListItemCollection queryHelpersItems = SPListHelper.GetListItemsByQuery(Configuration.HelpersListName, helpersQuery, currentWebUrl); List <Helper> helpers = ExtractHelpersFromSPList(queryHelpersItems); foreach (SPListItem objective in queryObjectivesItems) { result.Add(new Objective() { ID = objective.ID, AppraisalFormID = appraisalFormID, IsCompleted = objective["IsCompleted"] != null ? bool.Parse(objective["IsCompleted"].ToString()) : false, Helpers = helpers.Where(helper => helper.ObjectiveID == objective.ID).Select(helper => helper).ToList() }); } } return(result); }
public void TesteDePaginacao() { // 1 || 2 || 3 || 4 // Pasta 1, Pasta 5, Pasta 6, Pasta 7, Pasta 8, Pasta 9, Pasta 10 //<Where><Includes><FieldRef Name=\"PGCSCPublicoAlvoCentralArquivos\" LookupId=\"TRUE\" /><Value Type=\"Integer\">{0}</Value></Includes></Where> using (SPSite site = new SPSite(siteurl)) { var web = site.OpenWeb(); var pageIndex = 1; // baseado em 1 var pageSize = 2; var publicoAlvoId = "1"; var lista = web.Lists.TryGetList("Nova Central de Arquivos"); SPListItemCollection results = default(SPListItemCollection); IEnumerable <SPListItem> coll = default(IEnumerable <SPListItem>); if (lista != null) { var query = new SPQuery(); query.Query = string.Format(@"<Where><Includes><FieldRef Name='PGCSCPublicoAlvoCentralArquivos' LookupId='TRUE' /><Value Type='Integer'>{0}</Value></Includes></Where>", publicoAlvoId); results = lista.GetItems(query); coll = results.OfType <SPListItem>().Skip((pageIndex - 1) * pageSize).Take(pageSize); } var el1 = coll.ElementAt(0); var el2 = coll.ElementAt(1); Assert.IsTrue(el1.Title == "Pasta 1" && el2.Title == "Pasta 5"); } }
private void checkReportFromManager() { using (SPSite site = new SPSite("http://xrm")) { using (SPWeb webApp = site.OpenWeb("crm")) { Guid guidObj = new Guid("6318a62c-dfbd-4452-af42-919e3c66f011"); //получаем список обьекты по GUID SPList listObj = webApp.Lists[guidObj]; SPListItemCollection spListObjectsColl = listObj.Items; Guid guidInfoList = new Guid("043891f9-e187-4365-9d80-dfa908f5ced0"); //получаем список записей от менеджеров по GUID SPList listInfo = webApp.Lists[guidInfoList]; SPListItemCollection spListInfoColl = listInfo.Items; DateTime CurrentDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(-7); //получаем записи из списка обьектов var listObjects = from i in spListObjectsColl.OfType <SPListItem>() where i["Status"].ToString() == "Текущий" && i["Manager"] != null select i; //записи из списка с информацией от управляющих созданых за последние 7 дней. var listqueryInfoColl = from i in spListInfoColl.OfType <SPListItem>() where ((DateTime)i["Created"]).Date >= CurrentDay && i["Object"] != null select i; //создаем список из ИД оьтектов списка информации от управляющих List <int> listidobjects = new List <int>(); foreach (SPListItem item in listqueryInfoColl) { SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(item["Object"].ToString()); int lookupIDObject = fieldLookupValue.LookupId; listidobjects.Add((int)lookupIDObject); } // выбираем обьекты у которых нет записей var noexistObjectList = from itemObj in listObjects where !listidobjects.Any(infoitem => (infoitem.ToString() == itemObj["ID"].ToString())) select itemObj; //перебираем записи, от правляем уведомления управляющим foreach (SPListItem item in noexistObjectList) { SPFieldUserValue managercantin = new SPFieldUserValue(webApp, item["Manager"].ToString()); //учетная запись управляющего if (IsValidEmailId(managercantin.User.Email)) { sendEmail(managercantin.User.Email, "Журнал - Информация от управляющих", managercantin.User.Name); } } } } }