PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Source Code/PowerSong/Item Management/frmSong.vb

#
Visual Basic | 157 lines | 105 code | 42 blank | 10 comment | 0 complexity | a8bb042f74a5c5ad995039ad2af62b67 MD5 | raw file
  1. Imports PowerSong.SongDatabase
  2. Imports PowerSong.SongDatabase.Items
  3. Public Class frmSong
  4. Private FDatabase As Database = Nothing
  5. Private FSong As New SongItem
  6. Public ReadOnly Property Song() As SongItem
  7. Get
  8. UpdateSong()
  9. Return FSong
  10. End Get
  11. End Property
  12. Private Enum EMode
  13. Add
  14. Edit
  15. End Enum
  16. Private FMode As EMode
  17. Public Sub New(ByVal database As Database)
  18. InitializeComponent()
  19. FDatabase = database
  20. FMode = EMode.Add
  21. Text = "Add Song"
  22. UpdateAvailableCategories()
  23. UpdateAvailableLicenses()
  24. Functionality.ConfigureForm(Me)
  25. End Sub
  26. Public Sub New(ByVal database As Database, ByVal existingSong As SongItem)
  27. InitializeComponent()
  28. FDatabase = database
  29. FMode = EMode.Edit
  30. FSong = existingSong
  31. txtTitle.Text = FSong.Title
  32. For Each Author As String In FSong.Authors
  33. txtAuthors.Text += Author
  34. txtAuthors.Text += Environment.NewLine
  35. Next
  36. txtCopyrightLine.Text = FSong.CopyrightLine
  37. txtParts.Text = FSong.CombineIntoString
  38. Text = "Edit Song"
  39. UpdateAvailableCategories()
  40. UpdateAvailableLicenses()
  41. ' TODO: Fix: cboLicense.SelectedItem = database.Songs.GetSongLicense(existingSong.SongID)
  42. Functionality.ConfigureForm(Me)
  43. End Sub
  44. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  45. ' Ensure at least one category is selected
  46. Dim CategorySelected As Boolean = False
  47. For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
  48. If lstCategories.GetItemChecked(ItemIndex) = True Then CategorySelected = True
  49. Next
  50. If Not CategorySelected Then
  51. MsgBox("You must assign the song to at least one category.", MsgBoxStyle.Exclamation)
  52. Exit Sub
  53. End If
  54. ' Close the form
  55. Me.DialogResult = System.Windows.Forms.DialogResult.OK
  56. Me.Close()
  57. End Sub
  58. Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  59. Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  60. Me.Close()
  61. End Sub
  62. Private Sub UpdateSong()
  63. ' Update song details
  64. FSong.Title = txtTitle.Text.Trim
  65. FSong.CopyrightLine = txtCopyrightLine.Text.Trim
  66. ' Update verses
  67. FSong.Parts = SongItem.SplitIntoParts(txtParts.Lines)
  68. ' Update authors
  69. FSong.Authors.Clear()
  70. For Each Author As String In txtAuthors.Lines
  71. If Author.Trim <> "" Then FSong.Authors.Add(Author.Trim)
  72. Next
  73. ' Update categories
  74. FSong.Categories.Clear()
  75. For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
  76. If lstCategories.GetItemChecked(ItemIndex) Then
  77. Dim Item As ListItem(Of Guid) = lstCategories.Items(ItemIndex)
  78. FSong.Categories.Add(Item.Key)
  79. End If
  80. Next
  81. End Sub
  82. Private Sub UpdateAvailableCategories()
  83. ' Clear the list
  84. lstCategories.Items.Clear()
  85. ' Add categories
  86. For Each Category As KeyValuePair(Of Guid, String) In FDatabase.Categories.GetAllCategories
  87. Dim Item As New ListItem(Of Guid)(Category.Value, Category.Key)
  88. Dim ItemIndex As Integer = lstCategories.Items.Add(Item)
  89. ' Determine if the currently added item should be selected
  90. For Each SongCategory As Guid In FSong.Categories
  91. If SongCategory = Category.Key Then
  92. lstCategories.SetItemChecked(ItemIndex, True)
  93. End If
  94. Next
  95. Next
  96. End Sub
  97. Private Sub btnManageCategories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManageCategories.Click
  98. Dim Form As New frmManageCategories(FDatabase)
  99. If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
  100. UpdateAvailableCategories()
  101. End If
  102. End Sub
  103. Private Sub btnInsertCopyrightSymbol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCopyrightSymbol.Click
  104. txtCopyrightLine.Text += "©"
  105. End Sub
  106. Private Sub frmSong_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
  107. txtTitle.Focus()
  108. End Sub
  109. Private Sub UpdateAvailableLicenses()
  110. cboLicense.Items.Clear()
  111. For Each License As License In Database.Licenses.GetAllLicenses
  112. cboLicense.Items.Add(License)
  113. Next
  114. End Sub
  115. End Class