/Source Code/PowerSong/Export and Import/frmDownload.vb
Visual Basic | 106 lines | 70 code | 27 blank | 9 comment | 1 complexity | e1249155ab1038fefcd53134e1762486 MD5 | raw file
- Imports System.Windows.Forms
- Imports System.Net
- Imports PowerSong.SongDatabase
- Imports PowerSong.SongDatabase.Bibles
- Imports System.IO
-
- Public Class frmDownload
-
- Private Const DATABASES_LOCATION As String = "http://www.nick-hill.com/powersong/Databases"
-
- Private FDatabase As Database
-
- Public Sub New(ByVal database As Database)
- InitializeComponent()
- FDatabase = database
- Functionality.ConfigureForm(Me)
- End Sub
-
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadSongs.Click
-
- Try
-
- ' Determine whether or not to overwrite existing items
- Dim Overwrite As Boolean = False
- If FDatabase.Songs.GetAllSongIDs.Count > 0 Then
- Overwrite = MsgBox("Do you wish to overwrite existing songs in the database?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
- End If
-
- ' Download the latest file
- Dim Filename As String = "Songs." + Database.MINIMUM_FILE_VERSION + ".PowerSong"
- Dim Request As WebRequest = Net.FileWebRequest.Create(DATABASES_LOCATION + "/" + Filename)
- Dim DatabaseStream As Stream = request.GetResponse.GetResponseStream
-
- ' Import the database
- Dim ImportForm As New frmImportProgress(FDatabase, DatabaseStream, Overwrite)
- ImportForm.ShowDialog()
- DatabaseStream.Close()
-
- Catch ex As Exception
- MsgBox("There was a problem downloading the latest songs:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- End Sub
-
- Private Sub btnDownloadStyles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadStyles.Click
-
- Try
-
- ' Determine whether or not to overwrite existing items
- Dim Overwrite As Boolean = False
- If FDatabase.Styles.GetAllStyleNames.Count > 1 Then
- Overwrite = MsgBox("Do you wish to overwrite existing styles in the database?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
- End If
-
- ' Download the latest file
- Dim Filename As String = "Styles." + Database.MINIMUM_FILE_VERSION + ".PowerSong"
- Dim Request As WebRequest = Net.FileWebRequest.Create(DATABASES_LOCATION + "/" + Filename)
- Dim DatabaseStream As Stream = request.GetResponse.GetResponseStream
-
- ' Import the database
- Dim ImportForm As New frmImportProgress(FDatabase, DatabaseStream, Overwrite)
- ImportForm.ShowDialog()
- DatabaseStream.Close()
-
- Catch ex As Exception
- MsgBox("There was a problem downloading the latest styles:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- End Sub
-
- Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
- Me.Close()
- End Sub
-
- Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
- Me.DialogResult = System.Windows.Forms.DialogResult.OK
- Me.Close()
- End Sub
-
- Private Sub btnDownloadBibles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadBibles.Click
-
- ' Check that the translation hasn't already been installed
- Const Translation As String = "BBE"
- If BibleTranslationManager.IsTranslationInstalled(Translation) Then
- MsgBox("The bible translation '" + Translation + "' is already installed!", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
-
- ' Download the translation
- Dim Filename As String = "Bible." + Translation + "." + Database.MINIMUM_FILE_VERSION + ".Bible"
- Dim Task As New DownloadFileTask(DATABASES_LOCATION + "/" + Filename)
- Dim Form As New ProgressForm(Task, "Downloading the 'Bible in Basic English'...")
- Form.ShowDialog()
- If Not Task.CancelRequested Then
-
- ' Import the bible
- Bibles.BibleTranslationManager.InstallTranslation(Task.DownloadedContents, Translation)
- MsgBox("The translation '" + Translation + "' has been installed." + Environment.NewLine + _
- "Go to the configuration screen to set it up for use.", MsgBoxStyle.Information)
-
- End If
-
- End Sub
-
- End Class