PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/PowerSong/Categories/frmProblemSongs.vb

#
Visual Basic | 92 lines | 66 code | 20 blank | 6 comment | 0 complexity | 067aedc039c33db1be9e4529c350a7e1 MD5 | raw file
  1. Imports System.Windows.Forms
  2. Imports PowerSong.SongDatabase
  3. Public Class frmProblemSongs
  4. Private FDatabase As Database = Nothing
  5. Private FCategoryID As Guid = Nothing
  6. Private FAffectedSongs As List(Of Guid) = Nothing
  7. Public Enum ChoiceResult
  8. DoNothing
  9. Delete
  10. Reassign
  11. End Enum
  12. Public Sub New(ByVal database As Database, ByVal categoryID As Guid, ByVal affectedSongs As List(Of Guid))
  13. InitializeComponent()
  14. FDatabase = database
  15. FCategoryID = categoryID
  16. FAffectedSongs = affectedSongs
  17. lblWarningMessage.Text = String.Format(lblWarningMessage.Text, FDatabase.Categories.GetCategoryName(categoryID))
  18. ' Populate the list of alternative categories
  19. cboCategories.Items.Clear()
  20. For Each AlternativeCategory As KeyValuePair(Of Guid, String) In FDatabase.Categories.GetAllCategories
  21. If AlternativeCategory.Key <> categoryID Then
  22. cboCategories.Items.Add(New ListItem(Of Guid)(AlternativeCategory.Value, AlternativeCategory.Key))
  23. End If
  24. Next
  25. ' Set available options
  26. If cboCategories.Items.Count = 0 Then optReassign.Enabled = False
  27. End Sub
  28. Public ReadOnly Property SelectedChoice() As ChoiceResult
  29. Get
  30. If optNothing.Checked Then Return ChoiceResult.DoNothing
  31. If optDelete.Checked Then Return ChoiceResult.Delete
  32. If optReassign.Checked Then Return ChoiceResult.Reassign
  33. Throw New Exception("Unknown choice selected.")
  34. End Get
  35. End Property
  36. Public ReadOnly Property SelectedReassignmentCategory() As Guid
  37. Get
  38. Dim Item As ListItem(Of Guid) = cboCategories.SelectedItem
  39. Return Item.Key
  40. End Get
  41. End Property
  42. Private Sub btnViewSongs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewSongs.Click
  43. ' Show the affected songs
  44. Call New frmSongList(FDatabase, _
  45. "Songs that are affected by the removal of category '" + FDatabase.Categories.GetCategoryName(FCategoryID) + "':", _
  46. FAffectedSongs).ShowDialog()
  47. End Sub
  48. Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
  49. ' Check a category has been selected
  50. If optReassign.Checked AndAlso cboCategories.SelectedItem Is Nothing Then
  51. MsgBox("Please select a category to reassign to.", MsgBoxStyle.Exclamation)
  52. Exit Sub
  53. End If
  54. ' Confirm deletion of songs
  55. Dim Proceed As Boolean = True
  56. If optDelete.Checked Then
  57. If MsgBox("Are you absolutely sure that you wish to permanently delete all of the songs " + _
  58. "assigned solely to the category '" + _
  59. FDatabase.Categories.GetCategoryName(FCategoryID) + "'?", _
  60. MsgBoxStyle.Question + MsgBoxStyle.YesNo) <> MsgBoxResult.Yes Then
  61. Proceed = False
  62. End If
  63. End If
  64. If Not Proceed Then Exit Sub
  65. ' Close the form
  66. DialogResult = Windows.Forms.DialogResult.OK
  67. Close()
  68. End Sub
  69. Private Sub optReassign_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optReassign.CheckedChanged
  70. cboCategories.Enabled = optReassign.Checked
  71. End Sub
  72. End Class