PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/PowerSong/Configuration/frmEditLicense.vb

#
Visual Basic | 58 lines | 36 code | 18 blank | 4 comment | 0 complexity | ba6f0298e0caf1e31c6373ced7c8c388 MD5 | raw file
 1Imports PowerSong.SongDatabase
 2
 3Public Class frmEditLicense
 4
 5    Private _existingLicense As License = Nothing
 6
 7    Public Sub New(Optional ByVal existingLicense As License = Nothing)
 8
 9        InitializeComponent()
10
11        ' Populate current license details
12        If existingLicense IsNot Nothing Then
13            _existingLicense = existingLicense
14            txtName.Text = existingLicense.Name
15            txtNumber.Text = existingLicense.Number
16            txtDetails.Text = existingLicense.Details
17        End If
18
19    End Sub
20
21    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
22
23        Try
24
25            If _existingLicense Is Nothing Then
26
27                ' Add a new license to the database
28                Dim NewLicense As New License(txtName.Text)
29                NewLicense.Number = txtNumber.Text
30                NewLicense.Details = txtDetails.Text
31                GlobalContext.Database.Licenses.AddLicense(NewLicense)
32
33            Else
34
35                ' Edit the existing license in the database
36                _existingLicense.Name = txtName.Text
37                _existingLicense.Number = txtNumber.Text
38                _existingLicense.Details = txtDetails.Text
39                GlobalContext.Database.Licenses.EditLicense(_existingLicense.LicenseID, _existingLicense)
40
41            End If
42
43            ' Close the form
44            Me.DialogResult = System.Windows.Forms.DialogResult.OK
45            Me.Close()
46
47        Catch ex As Exception
48            MsgBox("Could not write the license details to the database:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
49        End Try
50
51    End Sub
52
53    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
54        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
55        Me.Close()
56    End Sub
57
58End Class