public static void UpdateTasksList(string serviceUrl, Guid projectUID) { DataRepository.ClearImpersonation(); if (DataRepository.P14Login(serviceUrl)) { DataAccess dataAccess = new Repository.DataAccess(projectUID); DataSet dataset = dataAccess.ReadProject(TaskItemRepository.GetProjectDataSetFromList()); DataTable tasksDataTable = dataset.Tables["Task"]; DataTable tDeletedRows = tasksDataTable.GetChanges(DataRowState.Deleted); var queryTasks = (from m in tasksDataTable.GetChanges(DataRowState.Added | DataRowState.Modified | DataRowState.Unchanged).AsEnumerable() select new TaskItem { ID = m.Field<int>("TASK_ID"), UniqueID = m.Field<Guid>("TASK_UID").ToString(), DrivingPath = m.Field<String>("TASK_DRIVINGPATH_ID"), Task = m.Field<String>("TASK_NAME"), Predecessor = m.Field<String>("TASK_PREDECESSORS"), Start = m.Field<DateTime?>("TASK_START_DATE"), Finish = m.Field<DateTime?>("TASK_FINISH_DATE"), Deadline = m.Field<DateTime?>("TASK_DEADLINE"), ShowOn = GetShownOnColumnValue(m.Field<String>("CUSTOMFIELD_DESC")), ModifiedOn = m.Field<DateTime?>("TASK_MODIFIED_ON"), WorkCompletePercentage = m.Field<int>("TASK_PCT_COMP") }); var items = queryTasks.ToList(); SPWeb web; if (SPContext.Current != null) web = SPContext.Current.Web; else web = new SPSite("http://finweb.contoso.com/sites/PMM").OpenWeb(); var list = web.Lists.TryGetList(Constants.LIST_NAME_PROJECT_TASKS); var dPathsField = list.Fields[Constants.FieldId_DrivingPath] as SPFieldMultiChoice; var dShownField = list.Fields[Constants.FieldId_ShowOn] as SPFieldMultiChoice; var dIdField = list.Fields[Constants.FieldId_UniqueID] as SPFieldGuid; if (list != null) { if (tDeletedRows != null && tDeletedRows.Rows.Count > 0) { foreach (DataRow row in tDeletedRows.Rows) { row.RejectChanges(); var q = new SPQuery(); q.Query += "<Where>" + "<Eq>" + "<FieldRef ID='" + dIdField.Id + "' />" + "<Value Type='Guid'>" + row["TASK_UID"].ToString() + "</Value>" + "</Eq>" + //"<OrderBy>" + // "<FieldRef ID='" + startField.Id + "' Ascending='True' />" + //"</OrderBy>" + "</Where>"; list.GetItems(q)[0].Delete(); row.Delete(); } list.Update(); } foreach (TaskItem task in items) { var q = new SPQuery(); q.Query += "<Where>" + "<Eq>" + "<FieldRef ID='" + dIdField.Id + "' />" + "<Value Type='Text'>" + task.UniqueID + "</Value>" + "</Eq>" + //"<OrderBy>" + // "<FieldRef ID='" + startField.Id + "' Ascending='True' />" + //"</OrderBy>" + "</Where>"; SPListItemCollection listItems = list.GetItems(q); if (listItems.Count > 0) { var existingItem = listItems[0]; BuildListItem(existingItem, task); existingItem.Update(); } else { var newItem = list.Items.Add(); BuildListItem(newItem, task); newItem.Update(); } //web.AllowUnsafeUpdates = true; //web.AllowUnsafeUpdates = false; } } dPathsField.Update(); dShownField.Update(); } }
private static DateTime? GetProjectCurrentDate(Guid projectUID, ProjectDataSet projectDataSet) { DataAccess da = new DataAccess(projectUID); return da.GetProjectCurrentDate(projectDataSet, projectUID); }
private static List<FiscalUnit> GetProjectStatusWeekPeriods(DateTime? projectStatusDate) { DataAccess da = new DataAccess(Guid.Empty); return da.GetProjectStatusWeekPeriods(projectStatusDate); }
public static TaskGroupData GetTaskGroups(string projectUID) { Repository.Utility.WriteLog("GetTaskGroups started", System.Diagnostics.EventLogEntryType.Information); IList<TaskItemGroup> retVal = new List<TaskItemGroup>(); CustomFieldDataSet customFieldDataSet = DataRepository.ReadCustomFields(); DataAccess dataAccess = new Repository.DataAccess(new Guid(projectUID)); DataSet dataset = dataAccess.ReadProject(null); ProjectDataSet ds = DataRepository.ReadProject(new Guid(projectUID)); DataTable tasksDataTable = dataset.Tables["Task"]; Dictionary<string, IList<TaskItem>> ChartsData = GetChartsData(tasksDataTable, customFieldDataSet); TaskGroupData taskData = new TaskGroupData(); DateTime? projectStatusDate = GetProjectCurrentDate(new Guid(projectUID), ds); FiscalUnit fiscalPeriod = DataRepository.GetFiscalMonth(projectStatusDate); taskData.FiscalPeriod = fiscalPeriod; IList<TaskItemGroup> LateTasksData = GetLateTasksData(tasksDataTable, fiscalPeriod, customFieldDataSet); IList<TaskItemGroup> UpComingTasksData = GetupComingTasksData(tasksDataTable, fiscalPeriod, customFieldDataSet); taskData.TaskItemGroups = retVal; taskData.ChartsData = ChartsData; taskData.LateTaskGroups = LateTasksData; taskData.UpComingTaskGroups = UpComingTasksData; taskData.SPDLSTartToBL = GetSPDLSTartToBLData(new Guid(projectUID), ds); taskData.SPDLFinishToBL = GetSPDLFinishToBLData(new Guid(projectUID), ds); taskData.BEIData = GetBEIData(new Guid(projectUID), ds); if (tasksDataTable != null) { var dPaths = tasksDataTable.AsEnumerable().Where(t => !string.IsNullOrEmpty(t.Field<string>("TASK_DRIVINGPATH_ID"))).Select(t => t.Field<string>("TASK_DRIVINGPATH_ID")).Distinct(); var chartTypes = tasksDataTable.AsEnumerable().Select(t => t.Field<string>("CUSTOMFIELD_DESC")).Distinct(); ; foreach (string dPath in dPaths) { int taskCount = -1; var taskItemGroup = new TaskItemGroup { DrivingPath = dPath, TaskItems = new List<TaskItem>() }; string previousTitle = string.Empty; Dictionary<string, string> dictTitle = new Dictionary<string, string>(); int totalUnCompletedtaskCount = 0, totalCompletedTaskCount = 0; List<TaskItem> chartItems = new List<TaskItem>(); List<TaskItemGroup> completedTasks = new List<TaskItemGroup>(); EnumerableRowCollection<DataRow> collection = tasksDataTable.AsEnumerable().Where(t => t.Field<string>("TASK_DRIVINGPATH_ID") != null && t.Field<string>("TASK_DRIVINGPATH_ID").Split(",".ToCharArray()).Contains(dPath)); int completedTaskCount = -1; //DateTime? lastUpdate = GetLastUpdateDate(); TaskItemGroup completedTaskItemGroup = new TaskItemGroup { DrivingPath = dPath, TaskItems = new List<TaskItem>() }; foreach (DataRow item in collection) { if (item["TASK_DEADLINE"] != System.DBNull.Value && !string.IsNullOrEmpty(item["TASK_DEADLINE"].ToString())) { if (!dictTitle.ContainsKey(dPath.Split(",".ToCharArray())[0])) { dictTitle.Add(dPath.Split(",".ToCharArray())[0], item["TASK_NAME"].ToString()); } } if (item["CUSTOMFIELD_DESC"] != null) { chartItems.Add(BuildTaskItem(dPath, item, customFieldDataSet)); } if (!string.IsNullOrEmpty(item["TASK_ACT_FINISH"].ToString()) && (Convert.ToDateTime(item["TASK_ACT_FINISH"].ToString())).InCurrentFiscalMonth(fiscalPeriod)) { totalCompletedTaskCount++; completedTaskCount++; if (completedTaskCount == 10) { completedTasks.Add(completedTaskItemGroup); completedTaskItemGroup = new TaskItemGroup { DrivingPath = dPath, TaskItems = new List<TaskItem>() }; completedTaskCount = 0; completedTaskItemGroup.TaskItems.Add(BuildTaskItem(dPath, item, customFieldDataSet)); } else { completedTaskItemGroup.TaskItems.Add(BuildTaskItem(dPath, item, customFieldDataSet)); } } else { if (item["TASK_PCT_COMP"] != null && (Convert.ToInt32(item["TASK_PCT_COMP"].ToString().Trim().Trim("%".ToCharArray()).Trim()) < 100)) { totalUnCompletedtaskCount++; taskCount++; if (taskCount == 10) { retVal.Add(taskItemGroup); taskItemGroup = new TaskItemGroup { DrivingPath = dPath, TaskItems = new List<TaskItem>() }; taskItemGroup.Title = previousTitle; taskCount = 0; taskItemGroup.TaskItems.Add(BuildTaskItem(dPath, item, customFieldDataSet)); } else { taskItemGroup.TaskItems.Add(BuildTaskItem(dPath, item, customFieldDataSet)); } } } } if (totalUnCompletedtaskCount % 10 != 0) { retVal.Add(taskItemGroup); } if (totalCompletedTaskCount % 10 != 0) { completedTasks.Add(completedTaskItemGroup); if (totalUnCompletedtaskCount == 0) { retVal.Add(taskItemGroup); } } if (taskItemGroup.TaskItems.Count > 0 || (completedTasks.Count > 0 && completedTasks[0].TaskItems != null && completedTasks[0].TaskItems.Count > 0)) { taskItemGroup.CompletedTaskgroups = completedTasks; taskItemGroup.ChartTaskItems = chartItems; taskItemGroup.Charts = new string[chartTypes.Count()]; chartTypes.ToList().CopyTo(taskItemGroup.Charts, 0); taskItemGroup.Title = dictTitle.ContainsKey(dPath) ? dictTitle[dPath] : "Driving Path template"; } if (dPath != null && dictTitle.ContainsKey(dPath.Split(",".ToCharArray())[0])) { foreach (TaskItemGroup group in retVal) { if (group.DrivingPath == dPath) { group.Title = dictTitle[dPath.Split(",".ToCharArray())[0]]; } if (group.CompletedTaskgroups != null) { foreach (TaskItemGroup completedGroup in group.CompletedTaskgroups) { completedGroup.Title = dictTitle[dPath.Split(",".ToCharArray())[0]]; } } } } } } Repository.Utility.WriteLog("GetTaskGroups completed successfully", System.Diagnostics.EventLogEntryType.Information); return taskData; }