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