/Source Code/PowerSong/Configuration/frmEditLicense.vb
Visual Basic | 58 lines | 36 code | 18 blank | 4 comment | 0 complexity | ba6f0298e0caf1e31c6373ced7c8c388 MD5 | raw file
- Imports PowerSong.SongDatabase
-
- Public Class frmEditLicense
-
- Private _existingLicense As License = Nothing
-
- Public Sub New(Optional ByVal existingLicense As License = Nothing)
-
- InitializeComponent()
-
- ' Populate current license details
- If existingLicense IsNot Nothing Then
- _existingLicense = existingLicense
- txtName.Text = existingLicense.Name
- txtNumber.Text = existingLicense.Number
- txtDetails.Text = existingLicense.Details
- End If
-
- End Sub
-
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
-
- Try
-
- If _existingLicense Is Nothing Then
-
- ' Add a new license to the database
- Dim NewLicense As New License(txtName.Text)
- NewLicense.Number = txtNumber.Text
- NewLicense.Details = txtDetails.Text
- GlobalContext.Database.Licenses.AddLicense(NewLicense)
-
- Else
-
- ' Edit the existing license in the database
- _existingLicense.Name = txtName.Text
- _existingLicense.Number = txtNumber.Text
- _existingLicense.Details = txtDetails.Text
- GlobalContext.Database.Licenses.EditLicense(_existingLicense.LicenseID, _existingLicense)
-
- End If
-
- ' Close the form
- Me.DialogResult = System.Windows.Forms.DialogResult.OK
- Me.Close()
-
- Catch ex As Exception
- MsgBox("Could not write the license details to the database:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- 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