/Source Code/PowerSong/Export and Import/frmExportDatabase.vb
Visual Basic | 79 lines | 76 code | 3 blank | 0 comment | 0 complexity | a3c304ebd515c0e5e949ee451b04bfe3 MD5 | raw file
- Imports System.Windows.Forms
- Imports System.IO
- Imports PowerSong.SongDatabase
-
- Public Class frmExportDatabase
-
- Private FDatabase As Database
-
- Public Sub New(ByVal database As Database)
- InitializeComponent()
- FDatabase = database
- txtFileName.Text = My.Computer.FileSystem.SpecialDirectories.Desktop + _
- "\" + Path.GetFileName(database.Location) + ".PowerSong"
- End Sub
-
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
-
- ' Export the database to the selected file
- If txtFileName.Text = "" Then
- lblNotice.Change(NoticeLabel.IconType.Warning, "Please enter a valid database location.", True)
- Exit Sub
- End If
-
- Try
-
- ' Check if the file already exists
- Dim Proceed As Boolean = True
- If File.Exists(txtFileName.Text) Then
- Proceed = MsgBox("The file '" + Path.GetFileName(txtFileName.Text) + "' already exists. Do you wish to overwrite the file?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
- End If
-
- If Proceed Then
-
- ' Export the database
- lblNotice.Change(NoticeLabel.IconType.Running, "Exporting the database...")
- Call New ExportImport.PrimaryFacility(FDatabase).Export(txtFileName.Text, _
- chkExportSongs.Checked, _
- chkIncludeCategories.Checked, _
- chkExportPlugins.Checked, _
- chkExportStyles.Checked)
-
- ' Close the form
- lblNotice.Change(NoticeLabel.IconType.Passed, "The database has been exported.", True)
- Me.DialogResult = System.Windows.Forms.DialogResult.OK
- Me.Close()
-
- Else
- lblNotice.Change(NoticeLabel.IconType.Error, "The operation was manually cancelled because the file already exists.")
- End If
-
- Catch ex As Exception
- MsgBox(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
-
- Private Sub btnSelectFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFileName.Click
-
- ' Set the file name in the dialog box
- dlgSave.FileName = txtFileName.Text
-
- ' Change the file name
- If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
- txtFileName.Text = dlgSave.FileName
- End If
-
- End Sub
-
- Private Sub chkExportSongs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkExportSongs.CheckedChanged
- chkIncludeCategories.Enabled = chkExportSongs.Checked
- chkIncludeCategories.Checked = chkExportSongs.Checked
- End Sub
-
- End Class