/Source Code/PowerSong/Item Management/frmSong.vb
Visual Basic | 157 lines | 105 code | 42 blank | 10 comment | 0 complexity | a8bb042f74a5c5ad995039ad2af62b67 MD5 | raw file
- Imports PowerSong.SongDatabase
- Imports PowerSong.SongDatabase.Items
-
- Public Class frmSong
-
- Private FDatabase As Database = Nothing
-
- Private FSong As New SongItem
-
- Public ReadOnly Property Song() As SongItem
- Get
- UpdateSong()
- Return FSong
- End Get
- End Property
-
- Private Enum EMode
- Add
- Edit
- End Enum
-
- Private FMode As EMode
-
- Public Sub New(ByVal database As Database)
-
- InitializeComponent()
-
- FDatabase = database
- FMode = EMode.Add
- Text = "Add Song"
- UpdateAvailableCategories()
- UpdateAvailableLicenses()
- Functionality.ConfigureForm(Me)
-
- End Sub
-
- Public Sub New(ByVal database As Database, ByVal existingSong As SongItem)
-
- InitializeComponent()
-
- FDatabase = database
- FMode = EMode.Edit
- FSong = existingSong
- txtTitle.Text = FSong.Title
- For Each Author As String In FSong.Authors
- txtAuthors.Text += Author
- txtAuthors.Text += Environment.NewLine
- Next
- txtCopyrightLine.Text = FSong.CopyrightLine
- txtParts.Text = FSong.CombineIntoString
- Text = "Edit Song"
- UpdateAvailableCategories()
- UpdateAvailableLicenses()
-
- ' TODO: Fix: cboLicense.SelectedItem = database.Songs.GetSongLicense(existingSong.SongID)
-
- Functionality.ConfigureForm(Me)
-
- End Sub
-
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
-
- ' Ensure at least one category is selected
- Dim CategorySelected As Boolean = False
- For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
- If lstCategories.GetItemChecked(ItemIndex) = True Then CategorySelected = True
- Next
- If Not CategorySelected Then
- MsgBox("You must assign the song to at least one category.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
-
- ' Close the form
- Me.DialogResult = System.Windows.Forms.DialogResult.OK
- Me.Close()
-
- End Sub
-
- Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
- Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
- Me.Close()
- End Sub
-
- Private Sub UpdateSong()
-
- ' Update song details
- FSong.Title = txtTitle.Text.Trim
- FSong.CopyrightLine = txtCopyrightLine.Text.Trim
-
- ' Update verses
- FSong.Parts = SongItem.SplitIntoParts(txtParts.Lines)
-
- ' Update authors
- FSong.Authors.Clear()
- For Each Author As String In txtAuthors.Lines
- If Author.Trim <> "" Then FSong.Authors.Add(Author.Trim)
- Next
-
- ' Update categories
- FSong.Categories.Clear()
- For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
- If lstCategories.GetItemChecked(ItemIndex) Then
- Dim Item As ListItem(Of Guid) = lstCategories.Items(ItemIndex)
- FSong.Categories.Add(Item.Key)
- End If
- Next
-
- End Sub
-
- Private Sub UpdateAvailableCategories()
-
- ' Clear the list
- lstCategories.Items.Clear()
-
- ' Add categories
- For Each Category As KeyValuePair(Of Guid, String) In FDatabase.Categories.GetAllCategories
- Dim Item As New ListItem(Of Guid)(Category.Value, Category.Key)
- Dim ItemIndex As Integer = lstCategories.Items.Add(Item)
-
- ' Determine if the currently added item should be selected
- For Each SongCategory As Guid In FSong.Categories
- If SongCategory = Category.Key Then
- lstCategories.SetItemChecked(ItemIndex, True)
- End If
- Next
-
- Next
-
- End Sub
-
- Private Sub btnManageCategories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManageCategories.Click
-
- Dim Form As New frmManageCategories(FDatabase)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- UpdateAvailableCategories()
- End If
-
- End Sub
-
- Private Sub btnInsertCopyrightSymbol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCopyrightSymbol.Click
- txtCopyrightLine.Text += "©"
- End Sub
-
- Private Sub frmSong_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
- txtTitle.Focus()
- End Sub
-
- Private Sub UpdateAvailableLicenses()
-
- cboLicense.Items.Clear()
- For Each License As License In Database.Licenses.GetAllLicenses
- cboLicense.Items.Add(License)
- Next
-
- End Sub
-
- End Class