/*-------------------------------------------------------------- POPOLARE CONTENUTI --------------------------------------------------------------*/ private void PopulateSelectedProject(ListBoxItem listBoxProject) { DbSet <TimeTrack> timeTracksDBSet = intimeDb.TimeTracks; DbSet <Assignment> AssignmentsDBSet = intimeDb.Assignments; selectedProject = (Project)listBoxProject.Tag; // POPOLA LA DATAGRID // seleziona tutti gli assignment per un progetto List <Assignment> assignmentList = (from Assignment in AssignmentsDBSet where Assignment.ProjectId == selectedProject.Id select Assignment).ToList(); List <AssignmentForDataGrid> dataGridAssignments = new List <AssignmentForDataGrid>(); long projectTotalTicks = 0; // serve per il tempo totale del progetto foreach (Assignment assignment in assignmentList) { int personId = assignment.PersonId; List <TimeTrack> timetracksList = (from TimeTrack in timeTracksDBSet // seleziona tutti i timetrack di UNA persona per IL progetto selezionato where TimeTrack.ProjectId == selectedProject.Id where TimeTrack.PersonId == personId select TimeTrack).ToList(); long personTotalTicks = 0; foreach (TimeTrack track in timetracksList) // calcola il tempo totale della persona { personTotalTicks += (long)track.WorkTime; } projectTotalTicks += personTotalTicks; // LISTA ASSIGNMENTS AssignmentForDataGrid assignmentForDataGrid = new AssignmentForDataGrid(); // creazione Assignment per DataGrid assignmentForDataGrid.name = assignment.Person.PersonName; assignmentForDataGrid.time = TimeTracker.ToString(TimeSpan.FromTicks(personTotalTicks)); assignmentForDataGrid.active = assignment.Active; assignmentForDataGrid.personId = assignment.PersonId; dataGridAssignments.Add(assignmentForDataGrid); } // COMBOBOX: FILTRO LISTA PERSONE GetPeopleListInComboBox(assignmentList); // PROPRIETà DEL PROGETTO (GROUPBOX) TotalWorkTime.Text = TimeTracker.ToString(TimeSpan.FromTicks(projectTotalTicks)); ProjectName.Text = selectedProject.ProjectName; // not null Customer.Text = selectedProject.Customer; // null Description.Text = selectedProject.Description; // null if (selectedProject.ProjectAssignedTime != null) { TimeSpan timespan = TimeSpan.FromTicks((long)selectedProject.ProjectAssignedTime); EstimatedTime.Text = TimeTracker.ToString(timespan); } // null else { EstimatedTime.Text = ""; } if (selectedProject.DueDate != null) { DueDate.Text = ((DateTime)selectedProject.DueDate).ToShortDateString(); } // null else { DueDate.Text = ""; } if (selectedProject.DateCreation != null) { CreationDate.Text = ((DateTime)selectedProject.DateCreation).ToShortDateString(); } // null else { CreationDate.Text = ""; } if (selectedProject.Active) // not null { Active.Text = "Sì"; } // not null else { Active.Text = "No"; } // BINDING CollectionViewSource itemCollectionViewSource; itemCollectionViewSource = (CollectionViewSource)(FindResource("ItemCollectionViewSource")); itemCollectionViewSource.Source = dataGridAssignments; }
/*-------------------------------------------------------------- DETTAGLIO ASSIGNMENT --------------------------------------------------------------*/ private void AssignmentGrid_RowDoubleClick(object sender, MouseButtonEventArgs e) { AssignmentForDataGrid ass = AssignmentGrid.SelectedItem as AssignmentForDataGrid; AssignmentDetailWindow assignment = new AssignmentDetailWindow(ass.personId, selectedProject.Id); }