PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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

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