PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Visual Basic | 91 lines | 67 code | 20 blank | 4 comment | 1 complexity | e488b92b316871dc50eef60fef75767e MD5 | raw file
  1. Imports System.Windows.Forms
  2. Imports PowerSong.SongDatabase
  3. Imports PowerSong.SongDatabase.Items
  4. Public Class frmVerse
  5. Private FItem As BaseItem = Nothing
  6. Public ReadOnly Property Item() As BaseItem
  7. Get
  8. Return FItem
  9. End Get
  10. End Property
  11. Private FPart As Integer = -1
  12. Public ReadOnly Property Part() As Integer
  13. Get
  14. Return FPart
  15. End Get
  16. End Property
  17. Private Enum EMode
  18. Add
  19. Edit
  20. End Enum
  21. Private FMode As EMode
  22. Public Sub New(ByVal item As BaseItem)
  23. InitializeComponent()
  24. FItem = item
  25. FPart = -1
  26. txtSongName.Text = item.Title
  27. FMode = EMode.Add
  28. Text = "Add Verse"
  29. End Sub
  30. Public Sub New(ByVal item As BaseItem, ByVal part As Integer)
  31. InitializeComponent()
  32. FItem = item
  33. FPart = part
  34. txtSongName.Text = item.Title
  35. txtVerse.Text = item.Parts(part)
  36. FMode = EMode.Edit
  37. Text = "Edit Verse"
  38. End Sub
  39. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  40. ' Compose a usable verse
  41. Dim Text As String = ComposeUsableVerse()
  42. ' Exit if no text specified
  43. If Text = "" Then
  44. MsgBox("Please specify some words for the verse.", MsgBoxStyle.Information)
  45. Exit Sub
  46. End If
  47. ' Save the verse
  48. Select Case FMode
  49. Case EMode.Add : FItem.Parts.Add(Text)
  50. Case EMode.Edit : FItem.Parts(FPart) = Text
  51. End Select
  52. ' Close the form
  53. Me.DialogResult = System.Windows.Forms.DialogResult.OK
  54. Me.Close()
  55. End Sub
  56. Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  57. Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  58. Me.Close()
  59. End Sub
  60. Private Function ComposeUsableVerse() As String
  61. Dim Text As String = ""
  62. For I As Integer = 0 To txtVerse.Lines.Length - 1
  63. Dim NextLine As String = txtVerse.Lines(I).Trim
  64. If NextLine <> "" AndAlso NextLine <> Environment.NewLine Then
  65. Text += NextLine
  66. If I < txtVerse.Lines.Length - 1 Then Text += Environment.NewLine
  67. End If
  68. Next
  69. Return Text
  70. End Function
  71. End Class