PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Source Code/PowerSong/Export and Import/frmExportDatabase.vb

#
Visual Basic | 79 lines | 76 code | 3 blank | 0 comment | 0 complexity | a3c304ebd515c0e5e949ee451b04bfe3 MD5 | raw file
  1. Imports System.Windows.Forms
  2. Imports System.IO
  3. Imports PowerSong.SongDatabase
  4. Public Class frmExportDatabase
  5. Private FDatabase As Database
  6. Public Sub New(ByVal database As Database)
  7. InitializeComponent()
  8. FDatabase = database
  9. txtFileName.Text = My.Computer.FileSystem.SpecialDirectories.Desktop + _
  10. "\" + Path.GetFileName(database.Location) + ".PowerSong"
  11. End Sub
  12. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  13. ' Export the database to the selected file
  14. If txtFileName.Text = "" Then
  15. lblNotice.Change(NoticeLabel.IconType.Warning, "Please enter a valid database location.", True)
  16. Exit Sub
  17. End If
  18. Try
  19. ' Check if the file already exists
  20. Dim Proceed As Boolean = True
  21. If File.Exists(txtFileName.Text) Then
  22. Proceed = MsgBox("The file '" + Path.GetFileName(txtFileName.Text) + "' already exists. Do you wish to overwrite the file?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
  23. End If
  24. If Proceed Then
  25. ' Export the database
  26. lblNotice.Change(NoticeLabel.IconType.Running, "Exporting the database...")
  27. Call New ExportImport.PrimaryFacility(FDatabase).Export(txtFileName.Text, _
  28. chkExportSongs.Checked, _
  29. chkIncludeCategories.Checked, _
  30. chkExportPlugins.Checked, _
  31. chkExportStyles.Checked)
  32. ' Close the form
  33. lblNotice.Change(NoticeLabel.IconType.Passed, "The database has been exported.", True)
  34. Me.DialogResult = System.Windows.Forms.DialogResult.OK
  35. Me.Close()
  36. Else
  37. lblNotice.Change(NoticeLabel.IconType.Error, "The operation was manually cancelled because the file already exists.")
  38. End If
  39. Catch ex As Exception
  40. MsgBox(ex.Message, MsgBoxStyle.Exclamation)
  41. End Try
  42. End Sub
  43. Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  44. Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  45. Me.Close()
  46. End Sub
  47. Private Sub btnSelectFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFileName.Click
  48. ' Set the file name in the dialog box
  49. dlgSave.FileName = txtFileName.Text
  50. ' Change the file name
  51. If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
  52. txtFileName.Text = dlgSave.FileName
  53. End If
  54. End Sub
  55. Private Sub chkExportSongs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkExportSongs.CheckedChanged
  56. chkIncludeCategories.Enabled = chkExportSongs.Checked
  57. chkIncludeCategories.Checked = chkExportSongs.Checked
  58. End Sub
  59. End Class