private void CalcGroups(List<WorkLogDataRow> fileData, ObservableCollection<TaskGroup> groups, TaskGroup summary, DateTime dateFrom, DateTime dateTo, ModelSettings settings) { foreach (WorkLogDataRow row in fileData) { if (row.Key == null) continue; DateTime bookDate = GetDate(row.WorkDateStr, settings.SourceFileSettings.DateField); if (bookDate >= dateFrom && bookDate <= dateTo) { TaskGroup group = groups.FirstOrDefault(x => x.Id == row.UserName); if (group == null) { group = new TaskGroup(); group.Id = row.UserName; group.Title = row.UserName; groups.Add(group); } Task task = CreateTask(row, settings); AddTaskToGroup(group, task); AddTaskToGroup(summary, task); } } }
private void AddTaskToGroup(TaskGroup group, Task task) { Task taskCopy = task.ShallowCopy(); if (group.IsSummary) taskCopy.IsTaskAssigned = true; Task groupExistingTask = group.Tasks.FirstOrDefault(x => x.Key == taskCopy.Key); if (groupExistingTask == null) { group.Tasks.Add(taskCopy); } else { AddDataToTask(groupExistingTask, taskCopy); } }
public ObservableCollection<TaskGroup> LoadTimeSheetReport(string fileName, DateTime dateFrom, DateTime dateTo, ModelSettings settings) { if (!File.Exists(fileName)) return null; List<WorkLogDataRow> fileData = ReadFile(fileName, settings); if (fileData == null) return null; ObservableCollection<TaskGroup> groups = new ObservableCollection<TaskGroup>(); TaskGroup summary = new TaskGroup { IsSummary = true, Title = "All" }; groups.Add(summary); CalcGroups(fileData, groups, summary, dateFrom, dateTo, settings); CalcTotals(groups, settings); return groups; }
public static ObservableCollection<TaskGroup> CreateTestData() { ModelSettings settings = new ModelSettings(); TaskGroup group1 = new TaskGroup(); group1.Title = "Test 1"; group1.Tasks.Add(CreateTestTask()); group1.Tasks.Add(CreateTestTask()); group1.CalculateTotals(settings); TaskGroup group2 = new TaskGroup(); group2.Title = "Test 2"; group2.Tasks.Add(CreateTestTask()); group2.Tasks.Add(CreateTestTask()); group2.CalculateTotals(settings); ObservableCollection<TaskGroup> groups = new ObservableCollection<TaskGroup>(); groups.Add(group1); groups.Add(group2); return groups; }
private void WriteTasksForGroups(ExcelWorksheet ws, IEnumerable<TaskGroup> groups, TaskGroup summary, ref int row) { if (summary != null) { WriteTasksForGroup(ws, summary, ref row); row++; } foreach (TaskGroup group in groups) { if (group != summary) { WriteTasksForGroup(ws, group, ref row); row++; } } }
private void WriteTasksForGroup(ExcelWorksheet ws, TaskGroup group, ref int row) { row++; ws.Cells[row, 1].Value = group.Title; row++; foreach (Task task in group.Tasks) { WriteTaskData(ws, task, row); row++; } }
private int WriteGroups(ExcelWorksheet ws, IEnumerable<TaskGroup> groups, TaskGroup summary, ref int row) { if (summary != null) { WriteGroupData(ws, summary, row); row++; } foreach (TaskGroup group in groups) { if (group != summary) { WriteGroupData(ws, group, row); row++; } } return row; }
private void WriteGroupData(ExcelWorksheet ws, TaskGroup group, int row) { ws.Cells[row, (int)TaskGroupDataPosition.Title].Value = group.Title; ws.Cells[row, (int)TaskGroupDataPosition.TotalEstimationDevelopment].Value = PrepareDouble(group.TotalEstimationDevelopment); ws.Cells[row, (int)TaskGroupDataPosition.TotalEstimationDevelopment].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalDoneEstimationDevelopment].Value = PrepareDouble(group.TotalDoneEstimationDevelopment); ws.Cells[row, (int)TaskGroupDataPosition.TotalDoneEstimationDevelopment].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalDoneBookedDevelopment].Value = PrepareDouble(group.TotalDoneBookedDevelopment); ws.Cells[row, (int)TaskGroupDataPosition.TotalDoneBookedDevelopment].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalTimeBooked].Value = PrepareDouble(group.TotalTimeBooked); ws.Cells[row, (int)TaskGroupDataPosition.TotalTimeBooked].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalBookedDevelopment].Value = PrepareDouble(group.TotalBookedDevelopment); ws.Cells[row, (int)TaskGroupDataPosition.TotalBookedDevelopment].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalBookedMeetings].Value = PrepareDouble(group.TotalBookedMeetings); ws.Cells[row, (int)TaskGroupDataPosition.TotalBookedMeetings].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.TotalUnderEstimate].Value = PrepareDouble(group.TotalUnderEstimate); ws.Cells[row, (int)TaskGroupDataPosition.TotalUnderEstimate].Style.NumberFormat = DOUBLE_FORMAT; ws.Cells[row, (int)TaskGroupDataPosition.RateDoneBookedToBookedDevelopment].Value = PrepareDouble(group.RateDoneBookedToBookedDevelopment); ws.Cells[row, (int)TaskGroupDataPosition.RateDoneBookedToBookedDevelopment].Style.NumberFormat = DOUBLE_FORMAT; }