private void StageHistoryDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { StageHistoryProxy currentRecord = StageHistoryDataGrid.SelectedItem as StageHistoryProxy; if (currentRecord != null) { Globals.SelectedHistory = ProjectFunctions.GetHistoryRecord(currentRecord.ID); AmendButton.IsEnabled = true; } else { AmendButton.IsEnabled = false; } }
// ---------------------------------------------------------- // // -------------------- Data Management --------------------- // // ---------------------------------------------------------- // // ------------- Data retrieval ------------- // private void refreshHistoryDataGrid() { try { if (!pageLoaded) { return; } int clientID = (Globals.SelectedClientProxy != null) ? Globals.SelectedClientProxy.ID : 0; int projectID = (Globals.SelectedProjectProxy != null) ? Globals.SelectedProjectProxy.ProjectID : 0; stageHistoryList = ProjectFunctions.StageHistoryList(clientID: clientID, statusFilter: Globals.SelectedStatusFilter, projectID: projectID, timelineType: Globals.SelectedTimelineType, fromDate: Globals.SelectedFromDate, toDate: Globals.SelectedToDate, stageNumber: stageNumber); int currentID = (Globals.SelectedHistory != null)? Globals.SelectedHistory.ID : 0; StageHistoryProxy currentRecord = null; StageHistoryDataGrid.ItemsSource = stageHistoryList; if (stageHistoryList.Count > 0) { try { if (currentID > 0 && stageHistoryList.Exists(shl => shl.ID == currentID)) { currentRecord = stageHistoryList.FirstOrDefault(shl => shl.ID == currentID); } else { currentRecord = stageHistoryList.OrderBy(shl => Math.Abs(((DateTime)shl.StartDate - Globals.Today).Days)).FirstOrDefault(); } StageHistoryDataGrid.SelectedItem = stageHistoryList.FirstOrDefault(shl => shl.ID == currentRecord.ID); StageHistoryDataGrid.ScrollIntoView(currentRecord); } catch { } // Do nothing, only the selection is affected } } catch (Exception generalException) { MessageFunctions.Error("Error populating stage history (timeline) data", generalException); } }