/Source Code/PowerSong/Categories/frmCategory.vb
Visual Basic | 81 lines | 57 code | 19 blank | 5 comment | 1 complexity | ef78b0ee6331e806b3ed923ee39128df MD5 | raw file
- Imports System.Windows.Forms
- Imports PowerSong.SongDatabase
-
- Public Class frmCategory
-
- Private FDatabase As Database = Nothing
-
- Private FCategoryID As Guid = Nothing
-
- Private Enum EMode
- Add
- Edit
- End Enum
-
- Private FMode As EMode = EMode.Add
-
- Public Sub New(ByVal database As Database)
- InitializeComponent()
- FDatabase = database
- FMode = EMode.Add
- Text = "Add Category"
- End Sub
-
- Public Sub New(ByVal database As Database, ByVal categoryID As Guid)
- InitializeComponent()
- FDatabase = database
- FMode = EMode.Edit
- Text = "Edit Category"
- FCategoryID = categoryID
- txtCategoryName.Text = database.Categories.GetCategoryName(categoryID)
- End Sub
-
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
-
- ' Ensure a name has been specified for the category
- If txtCategoryName.Text = "" Then
- MsgBox("Please enter a name for the category.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
-
- ' Add or edit the category
- Select Case FMode
-
- Case EMode.Add
-
- ' Add the category
- If FDatabase.Categories.CategoryExists(txtCategoryName.Text) Then
- MsgBox("The category '" + txtCategoryName.Text + "' already exists. Please specify a different name.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
- FDatabase.Categories.AddCategory(Guid.NewGuid, txtCategoryName.Text.Trim)
-
- Case EMode.Edit
-
- ' Edit an existing category
- Dim CategoryExists As Boolean = False
- For Each Category As KeyValuePair(Of Guid, String) In FDatabase.Categories.GetAllCategories
- If Category.Value.ToUpper.Trim = txtCategoryName.Text.ToUpper.Trim AndAlso Category.Key <> FCategoryID Then
- CategoryExists = True
- End If
- Next
- If CategoryExists Then
- MsgBox("The category '" + txtCategoryName.Text + "' already exists. Please specify a different name.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
- FDatabase.Categories.ChangeCategoryName(FCategoryID, txtCategoryName.Text.Trim)
-
- End Select
-
- ' 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
-
- End Class