From 75a325056ca1806e65ca42b234fc69b5d326259b Mon Sep 17 00:00:00 2001 From: Letsibogo Ramadi Date: Fri, 26 May 2017 12:54:46 +0100 Subject: [PATCH] CA-252871 - Updates order is not preserved on Exporting updates to a file Applies sort order of DataGridView to the unfiltered list of updates before exporting all to file, thereby preserving the update order in the file --- XenAdmin/TabPages/ManageUpdatesPage.cs | 42 +++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/XenAdmin/TabPages/ManageUpdatesPage.cs b/XenAdmin/TabPages/ManageUpdatesPage.cs index c84221b1e..daaf50f3e 100644 --- a/XenAdmin/TabPages/ManageUpdatesPage.cs +++ b/XenAdmin/TabPages/ManageUpdatesPage.cs @@ -271,23 +271,7 @@ namespace XenAdmin.TabPages updates.RemoveAll(FilterAlert); tableLayoutPanel3.Visible = false; - - if (dataGridViewUpdates.SortedColumn != null) - { - if (dataGridViewUpdates.SortedColumn.Index == ColumnMessage.Index) - updates.Sort(Alert.CompareOnTitle); - else if (dataGridViewUpdates.SortedColumn.Index == ColumnDate.Index) - updates.Sort(Alert.CompareOnDate); - else if (dataGridViewUpdates.SortedColumn.Index == ColumnLocation.Index) - updates.Sort(Alert.CompareOnAppliesTo); - - if (dataGridViewUpdates.SortOrder == SortOrder.Descending) - updates.Reverse(); - } - else - { - updates.Sort(new NewVersionPriorityAlertComparer()); - } + sortUpdates(updates); var rowList = new List(); @@ -948,7 +932,9 @@ namespace XenAdmin.TabPages if (exportAll) { - foreach (Alert a in Updates.UpdateAlerts) + var updates = new List(Updates.UpdateAlerts); + sortUpdates(updates); + foreach (Alert a in updates) stream.WriteLine(a.GetUpdateDetailsCSVQuotes()); } else @@ -985,6 +971,26 @@ namespace XenAdmin.TabPages } } } + + private void sortUpdates(List updatesList) + { + if (dataGridViewUpdates.SortedColumn != null) + { + if (dataGridViewUpdates.SortedColumn.Index == ColumnMessage.Index) + updatesList.Sort(Alert.CompareOnTitle); + else if (dataGridViewUpdates.SortedColumn.Index == ColumnDate.Index) + updatesList.Sort(Alert.CompareOnDate); + else if (dataGridViewUpdates.SortedColumn.Index == ColumnLocation.Index) + updatesList.Sort(Alert.CompareOnAppliesTo); + + if (dataGridViewUpdates.SortOrder == SortOrder.Descending) + updatesList.Reverse(); + } + else + { + updatesList.Sort(new NewVersionPriorityAlertComparer()); + } + } private void checkForUpdatesNowButton_Click(object sender, EventArgs e) {