internal static int AddDatesFromSchedule( ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, DataGridViewRow row, int startInd, int length, string user, string userMark) { int maxInd = row.Cells.Count - viewColumnsIndexes.FirstDateColumnIndex - 1; if (startInd > maxInd) return viewColumnsIndexes.FirstDateColumnIndex + maxInd + 1; int ind = 0; DateTime date = freeDaysCalculator.GetWorkDayFromCount(startInd); DateTime today = DateTime.Now.Date; while (length > 0) { var dayIndex = (int) Math.Ceiling(date.Subtract(today).TotalDays); if (dayIndex > maxInd) return viewColumnsIndexes.FirstDateColumnIndex + maxInd + 1; var cell = row.Cells[dayIndex + viewColumnsIndexes.FirstDateColumnIndex]; DayType dt = freeDaysCalculator.GetDayType(date, user); if (dt == DayType.WorkDay) cell.Value = userMark; cell.SetColorByDayType(dt); if (dt == DayType.WorkDay || dt == DayType.Vacations) --length; ++ind; date = date.AddDays(1); } return startInd + ind; }
internal static int AddLeadTaskRow( DataGridView dgv, ViewFiltersBuilder viewFiltersBuilder, WorkItemInfoFiller workItemInfoFiller, ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, WorkItem leadTask, DataContainer data, Dictionary<int, string> planningAssignments) { dgv.Rows.Add(new DataGridViewRow()); var leadTaskRow = dgv.Rows[dgv.Rows.Count - 1]; List<int> blockersIds = data.BlockersDict.ContainsKey(leadTask.Id) ? data.BlockersDict[leadTask.Id] : null; bool shouldCheckEstimate = workItemInfoFiller.FillLeadTaskInfo( viewFiltersBuilder, leadTask, leadTaskRow, data, blockersIds); viewFiltersBuilder.MarkLeadTaskRow(leadTaskRow); if (blockersIds != null) foreach (int blockerId in blockersIds) { AddBlockerRow( dgv, viewFiltersBuilder, workItemInfoFiller, data, planningAssignments, blockerId); } if (leadTask.IsProposed()) return ScheduleFiller.AddDatesProposed( viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, leadTask, leadTaskRow, viewColumnsIndexes.FirstDateColumnIndex, m_proposedLtMark, m_proposedLtMark, shouldCheckEstimate); return ScheduleFiller.AddDatesActive( viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, leadTask, leadTaskRow, viewColumnsIndexes.FirstDateColumnIndex, m_activeLtMark, m_activeLtMark); }
internal ViewFiltersApplier PresentData( DataContainer data, Dictionary<int, string> planningAssignments, List<string> allUsers, ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, DataGridView dgv) { var tasksSchedule = WorkItemsScheduler.MakeSchedule( data, planningAssignments, freeDaysCalculator, focusFactorCalculator); var alreadyAdded = new Dictionary<int, int>(); var tasksByUser = new Dictionary<string, int>(); var resultBuilder = new ViewFiltersBuilder(dgv, viewColumnsIndexes); var workItemInfoFiller = new WorkItemInfoFiller(dgv, viewColumnsIndexes); foreach (var leadTaskChildren in data.LeadTaskChildrenDict) { var leadTask = data.WiDict[leadTaskChildren.Key]; int nextLtInd = RowsAdder.AddLeadTaskRow( dgv, resultBuilder, workItemInfoFiller, viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, leadTask, data, planningAssignments); int ltRowInd = dgv.Rows.Count - 1; var childrenTasks = leadTaskChildren.Value .Where(i => data.WiDict.ContainsKey(i)) .Select(i => data.WiDict[i]) .OrderBy(i => i.Priority() ?? 999) .ToList(); if (childrenTasks.Count > 0) { int lastTaskInd = childrenTasks .Select(task => RowsAdder.AddTaskRow( dgv, resultBuilder, workItemInfoFiller, viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, task, childrenTasks, leadTask, data, planningAssignments, allUsers, alreadyAdded, tasksByUser, tasksSchedule)) .Max(); ScheduleFiller.ColorFdOutDays( viewColumnsIndexes, freeDaysCalculator, dgv.Rows[ltRowInd], nextLtInd, lastTaskInd); } var notAccessableChildren = leadTaskChildren.Value .Where(i => !data.WiDict.ContainsKey(i)) .ToList(); foreach (int notAccessableChildId in notAccessableChildren) { dgv.Rows.Add(new DataGridViewRow()); var taskRow = dgv.Rows[dgv.Rows.Count - 1]; workItemInfoFiller.FillNotAccessibleTaskInfo(viewColumnsIndexes, taskRow, notAccessableChildId); resultBuilder.MarkTaskRow(taskRow); } } return resultBuilder.Build(); }
private static int AddDates( ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, DataGridViewRow row, int startInd, int length, bool byDates, string user, string userMark) { int maxInd = row.Cells.Count - viewColumnsIndexes.FirstDateColumnIndex - 1; if (startInd - viewColumnsIndexes.FirstDateColumnIndex > maxInd) return viewColumnsIndexes.FirstDateColumnIndex + maxInd + 1; int ind = 0; while (length > 0) { int dateIndexShift = startInd - viewColumnsIndexes.FirstDateColumnIndex + ind; if (dateIndexShift > maxInd) return viewColumnsIndexes.FirstDateColumnIndex + maxInd + 1; var cell = row.Cells[startInd + ind]; ++ind; DateTime date = DateTime.Today.Date.AddDays(dateIndexShift); DayType dt = freeDaysCalculator.GetDayType(date, user); if (dt == DayType.WorkDay) cell.Value = userMark; cell.SetColorByDayType(dt); if (byDates || dt == DayType.WorkDay || dt == DayType.Vacations) --length; } return startInd + ind; }
internal static void ColorFdOutDays( ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, DataGridViewRow row, int startIndex, int finishIndex) { DateTime today = DateTime.Now.Date; for (int i = startIndex; i < finishIndex; i++) { DateTime date = today.AddDays(i - viewColumnsIndexes.FirstDateColumnIndex); if (freeDaysCalculator.GetDayType(date) != DayType.WorkDay) continue; row.Cells[i].SetErrorColor(); row.Cells[i].ToolTipText = Messages.ChildTaskHasLaterFd(); } }
internal static int AddDatesActive( ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, WorkItem workItem, DataGridViewRow row, int startInd, string user, string userMark) { var taskStart = workItem.StartDate(); var taskFinish = workItem.FinishDate(); DateTime today = DateTime.Now.Date; if (taskFinish == null || taskFinish.Value.Date < today) { if (taskFinish != null) row.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1].Value = taskFinish.Value.ToString("dd.MM"); var verificationResult = WorkItemVerifier.VerifyFinishDate(workItem); row.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1].SetColorByVerification(verificationResult.Result); row.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1].ToolTipText = verificationResult.AllMessagesString; double? remaining = workItem.Remaining(); if (remaining != null) { var length = focusFactorCalculator.CalculateDaysByTime(remaining.Value, user); return AddDates( viewColumnsIndexes, freeDaysCalculator, row, startInd, length, false, user, userMark); } } else if (taskStart.HasValue) { int maxInd = row.Cells.Count - viewColumnsIndexes.FirstDateColumnIndex - 1; var indStart = (int)taskStart.Value.Date.Subtract(today).TotalDays; if (indStart < 0) row.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1].Value = taskStart.Value.ToString("dd.MM"); indStart = Math.Min(Math.Max(1, indStart), maxInd) + viewColumnsIndexes.FirstDateColumnIndex; var indFinish = (int)taskFinish.Value.Date.Subtract(today).TotalDays; indFinish = Math.Min(Math.Max(1, indFinish), maxInd) + viewColumnsIndexes.FirstDateColumnIndex; AddDates( viewColumnsIndexes, freeDaysCalculator, row, indStart, indFinish - indStart + 1, true, user, userMark); return indFinish + 1; } return viewColumnsIndexes.FirstDateColumnIndex; }
internal static int AddDatesProposed( ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, WorkItem task, DataGridViewRow taskRow, int startInd, string user, string userMark, bool shouldCheckEstimate) { var verificationResult = WorkItemVerifier.VerifyEstimatePresence(task); if (verificationResult.Result != VerificationResult.Ok) { if (shouldCheckEstimate) { var estimateCell = taskRow.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1]; estimateCell.SetColorByVerification(verificationResult.Result); estimateCell.ToolTipText = verificationResult.AllMessagesString; } return viewColumnsIndexes.FirstDateColumnIndex; } double? estimate = task.Estimate(); var length = focusFactorCalculator.CalculateDaysByTime(estimate.Value, user); DateTime? finish = task.FinishDate(); if (finish != null) { verificationResult = WorkItemVerifier.VerifyFinishDate(task); var estimateCell = taskRow.Cells[viewColumnsIndexes.FirstDateColumnIndex - 1]; estimateCell.SetColorByVerification(verificationResult.Result); estimateCell.ToolTipText = verificationResult.AllMessagesString; estimateCell.Value = finish.Value.ToString("dd.MM"); int finishShift = length - 1; DateTime startDate = finish.Value.Date; DateTime today = DateTime.Now.Date; while (finishShift > 0 && startDate >= today) { startDate = startDate.AddDays(-1); if (freeDaysCalculator.GetDayType(startDate, user) == DayType.WorkDay) --finishShift; } if (finishShift == 0) { var startShift = (int) startDate.Subtract(today).TotalDays; startInd = Math.Max(startInd, startShift + viewColumnsIndexes.FirstDateColumnIndex); } else { length -= finishShift; } } return AddDates( viewColumnsIndexes, freeDaysCalculator, taskRow, startInd, length, false, user, userMark); }
internal static int AddTaskRow( DataGridView dgv, ViewFiltersBuilder viewFiltersBuilder, WorkItemInfoFiller workItemInfoFiller, ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, WorkItem task, List<WorkItem> siblings, WorkItem leadTask, DataContainer data, Dictionary<int, string> planningAssignments, List<string> allUsers, Dictionary<int, int> alreadyAdded, Dictionary<string, int> tasksByUser, Dictionary<int, Tuple<int?, int>> tasksSchedule) { if (alreadyAdded.ContainsKey(task.Id)) return viewColumnsIndexes.FirstDateColumnIndex; var nextInds = new List<int>(); List<int> blockerIds = ProcessBlockers( dgv, viewFiltersBuilder, workItemInfoFiller, viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, data, planningAssignments, allUsers, task, siblings, leadTask, alreadyAdded, nextInds, tasksByUser, tasksSchedule); dgv.Rows.Add(new DataGridViewRow()); var taskRow = dgv.Rows[dgv.Rows.Count - 1]; workItemInfoFiller.FillTaskInfo( viewFiltersBuilder, task, siblings, leadTask, taskRow, data, planningAssignments, allUsers, blockerIds); viewFiltersBuilder.MarkTaskRow(taskRow); if (blockerIds != null) foreach (int blockerId in blockerIds) { AddBlockerRow( dgv, viewFiltersBuilder, workItemInfoFiller, data, planningAssignments, blockerId); } if (task.IsResolved()) { alreadyAdded.Add(task.Id, viewColumnsIndexes.FirstDateColumnIndex); return viewColumnsIndexes.FirstDateColumnIndex; } string assignedTo = planningAssignments.GetAssignee(task); if (!assignedTo.IsUnassigned() && tasksByUser.ContainsKey(assignedTo)) nextInds.Add(tasksByUser[assignedTo]); int maxNextInd = viewColumnsIndexes.FirstDateColumnIndex; if (nextInds.Count > 0) maxNextInd = nextInds.Max(); string userMark = GetUserMark(assignedTo); Tuple<int?, int> taskSchedule = null; int nextInd; if (tasksSchedule != null && tasksSchedule.ContainsKey(task.Id)) taskSchedule = tasksSchedule[task.Id]; if (taskSchedule != null && taskSchedule.Item1 != null) { nextInd = ScheduleFiller.AddDatesFromSchedule( viewColumnsIndexes, freeDaysCalculator, taskRow, taskSchedule.Item1.Value, taskSchedule.Item2, assignedTo, userMark); } else { nextInd = task.IsProposed() ? ScheduleFiller.AddDatesProposed( viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, task, taskRow, maxNextInd, assignedTo, userMark, true) : ScheduleFiller.AddDatesActive( viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, task, taskRow, maxNextInd, assignedTo, userMark); } alreadyAdded.Add(task.Id, nextInd); tasksByUser[assignedTo] = nextInd; return nextInd; }
private static List<int> ProcessBlockers( DataGridView dgv, ViewFiltersBuilder viewFiltersBuilder, WorkItemInfoFiller workItemInfoFiller, ViewColumnsIndexes viewColumnsIndexes, FreeDaysCalculator freeDaysCalculator, FocusFactorCalculator focusFactorCalculator, DataContainer data, Dictionary<int, string> planningAssignments, List<string> allUsers, WorkItem task, List<WorkItem> childrenTasks, WorkItem leadTask, Dictionary<int, int> alreadyAdded, List<int> nextInds, Dictionary<string, int> tasksByUser, Dictionary<int, Tuple<int?, int>> tasksSchedule) { if (!data.BlockersDict.ContainsKey(task.Id)) return null; var blockerIds = data.BlockersDict[task.Id]; var blokers = blockerIds .Where(b => data.WiDict.ContainsKey(b)) .Select(b => data.WiDict[b]) .OrderBy(b => b.Priority()) .ToList(); foreach (var blocker in blokers) { if (alreadyAdded.ContainsKey(blocker.Id)) { nextInds.Add(alreadyAdded[blocker.Id]); continue; } var blockerSiblingTask = childrenTasks.FirstOrDefault(t => t.Id == blocker.Id); if (blockerSiblingTask != null) { int blockerNextInd = AddTaskRow( dgv, viewFiltersBuilder, workItemInfoFiller, viewColumnsIndexes, freeDaysCalculator, focusFactorCalculator, blockerSiblingTask, childrenTasks, leadTask, data, planningAssignments, allUsers, alreadyAdded, tasksByUser, tasksSchedule); nextInds.Add(blockerNextInd); } } return blockerIds; }