PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 0ms 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
  1. Imports PowerSong.SongDatabase
  2. Public Class frmEditLicense
  3. Private _existingLicense As License = Nothing
  4. Public Sub New(Optional ByVal existingLicense As License = Nothing)
  5. InitializeComponent()
  6. ' Populate current license details
  7. If existingLicense IsNot Nothing Then
  8. _existingLicense = existingLicense
  9. txtName.Text = existingLicense.Name
  10. txtNumber.Text = existingLicense.Number
  11. txtDetails.Text = existingLicense.Details
  12. End If
  13. End Sub
  14. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  15. Try
  16. If _existingLicense Is Nothing Then
  17. ' Add a new license to the database
  18. Dim NewLicense As New License(txtName.Text)
  19. NewLicense.Number = txtNumber.Text
  20. NewLicense.Details = txtDetails.Text
  21. GlobalContext.Database.Licenses.AddLicense(NewLicense)
  22. Else
  23. ' Edit the existing license in the database
  24. _existingLicense.Name = txtName.Text
  25. _existingLicense.Number = txtNumber.Text
  26. _existingLicense.Details = txtDetails.Text
  27. GlobalContext.Database.Licenses.EditLicense(_existingLicense.LicenseID, _existingLicense)
  28. End If
  29. ' Close the form
  30. Me.DialogResult = System.Windows.Forms.DialogResult.OK
  31. Me.Close()
  32. Catch ex As Exception
  33. MsgBox("Could not write the license details to the database:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
  34. End Try
  35. End Sub
  36. Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  37. Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  38. Me.Close()
  39. End Sub
  40. End Class