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