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