PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Visual Basic | 106 lines | 70 code | 27 blank | 9 comment | 1 complexity | e1249155ab1038fefcd53134e1762486 MD5 | raw file
  1Imports System.Windows.Forms
  2Imports System.Net
  3Imports PowerSong.SongDatabase
  4Imports PowerSong.SongDatabase.Bibles
  5Imports System.IO
  6
  7Public Class frmDownload
  8
  9    Private Const DATABASES_LOCATION As String = "http://www.nick-hill.com/powersong/Databases"
 10
 11    Private FDatabase As Database
 12
 13    Public Sub New(ByVal database As Database)
 14        InitializeComponent()
 15        FDatabase = database
 16        Functionality.ConfigureForm(Me)
 17    End Sub
 18
 19    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadSongs.Click
 20
 21        Try
 22
 23            ' Determine whether or not to overwrite existing items
 24            Dim Overwrite As Boolean = False
 25            If FDatabase.Songs.GetAllSongIDs.Count > 0 Then
 26                Overwrite = MsgBox("Do you wish to overwrite existing songs in the database?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
 27            End If
 28
 29            ' Download the latest file
 30            Dim Filename As String = "Songs." + Database.MINIMUM_FILE_VERSION + ".PowerSong"
 31            Dim Request As WebRequest = Net.FileWebRequest.Create(DATABASES_LOCATION + "/" + Filename)
 32            Dim DatabaseStream As Stream = request.GetResponse.GetResponseStream
 33
 34            ' Import the database
 35            Dim ImportForm As New frmImportProgress(FDatabase, DatabaseStream, Overwrite)
 36            ImportForm.ShowDialog()
 37            DatabaseStream.Close()
 38
 39        Catch ex As Exception
 40            MsgBox("There was a problem downloading the latest songs:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
 41        End Try
 42
 43    End Sub
 44
 45    Private Sub btnDownloadStyles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadStyles.Click
 46
 47        Try
 48
 49            ' Determine whether or not to overwrite existing items
 50            Dim Overwrite As Boolean = False
 51            If FDatabase.Styles.GetAllStyleNames.Count > 1 Then
 52                Overwrite = MsgBox("Do you wish to overwrite existing styles in the database?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes
 53            End If
 54
 55            ' Download the latest file
 56            Dim Filename As String = "Styles." + Database.MINIMUM_FILE_VERSION + ".PowerSong"
 57            Dim Request As WebRequest = Net.FileWebRequest.Create(DATABASES_LOCATION + "/" + Filename)
 58            Dim DatabaseStream As Stream = request.GetResponse.GetResponseStream
 59
 60            ' Import the database
 61            Dim ImportForm As New frmImportProgress(FDatabase, DatabaseStream, Overwrite)
 62            ImportForm.ShowDialog()
 63            DatabaseStream.Close()
 64
 65        Catch ex As Exception
 66            MsgBox("There was a problem downloading the latest styles:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
 67        End Try
 68
 69    End Sub
 70
 71    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 72        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
 73        Me.Close()
 74    End Sub
 75
 76    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
 77        Me.DialogResult = System.Windows.Forms.DialogResult.OK
 78        Me.Close()
 79    End Sub
 80
 81    Private Sub btnDownloadBibles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadBibles.Click
 82
 83        ' Check that the translation hasn't already been installed
 84        Const Translation As String = "BBE"
 85        If BibleTranslationManager.IsTranslationInstalled(Translation) Then
 86            MsgBox("The bible translation '" + Translation + "' is already installed!", MsgBoxStyle.Exclamation)
 87            Exit Sub
 88        End If
 89
 90        ' Download the translation
 91        Dim Filename As String = "Bible." + Translation + "." + Database.MINIMUM_FILE_VERSION + ".Bible"
 92        Dim Task As New DownloadFileTask(DATABASES_LOCATION + "/" + Filename)
 93        Dim Form As New ProgressForm(Task, "Downloading the 'Bible in Basic English'...")
 94        Form.ShowDialog()
 95        If Not Task.CancelRequested Then
 96
 97            ' Import the bible
 98            Bibles.BibleTranslationManager.InstallTranslation(Task.DownloadedContents, Translation)
 99            MsgBox("The translation '" + Translation + "' has been installed." + Environment.NewLine + _
100                   "Go to the configuration screen to set it up for use.", MsgBoxStyle.Information)
101
102        End If
103
104    End Sub
105
106End Class