|
Imports ZipTrack.Gui.Components
Imports ICSharpCode.SharpZipLib.Zip
Namespace Gui.Forms
Public Class FrmOpen
Private _DirectoryUrl As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Private _WebsiteID As Integer = -1
Private Sub FrmOpen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeCombo()
End Sub
#Region "InitializeCombo"
Private Sub InitializeCombo()
Try
Dim bizList As List(Of Business.Website) = Cache.AllWebsites
'Me.GroupSelect1.GroupCombo.Items.Add("(ALL)")
With Me.ImageComboBox1
.ImageList = Me.ImageList1
'.Items.Clear()
For Each biz As Business.Website In bizList
.Items.Add(New ComboBoxItem(biz.Name, biz.WebsiteID))
Next biz
.SelectedIndex = 0
End With
Catch ex As Exception
End Try
End Sub
#End Region
#Region "btnBrowse_Click"
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Me.Cursor = Cursors.WaitCursor
Try
If ImageComboBox1.SelectedItem Is Nothing Then
MessageBox.Show("To begin archive indexing you must select a Website from the list.", "Open Zip Files", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Me._WebsiteID = CType(ImageComboBox1.SelectedItem, ComboBoxItem).PrimaryID
With ofd
.Dialog.Title = "Browse file directory"
.Dialog.Filter = "All Files (*.*)|*.*"
If Me.txtDirectory.Text.Length > 0 And Directory.Exists(Me.txtDirectory.Text) Then
.Dialog.InitialDirectory = Me.txtDirectory.Text
End If
If .ShowDialog = DialogResult.OK Then
_DirectoryUrl = Path.GetDirectoryName(.Dialog.FileName)
Me.txtDirectory.Text = _DirectoryUrl
End If
End With
Catch ex As Exception
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
#End Region
#Region "btnAccept_Click"
Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
Scan()
End Sub
#End Region
#Region "btnCancel_Click"
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
While Me.BackgroundWorker1.IsBusy
Me.BackgroundWorker1.CancelAsync()
End While
Me.Close()
End Sub
#End Region
#Region "Scan"
Private Sub Scan()
Try
Dim nProgress As Integer = -1
Dim nCount As Integer = 0
Dim FileList As List(Of FileInfo) = New List(Of FileInfo)
FileList.AddRange(GetFiles)
nCount = FileList.Count
Me.ProgressBar1.Maximum = nCount
Me.ProgressBar1.Visible = True
Me.ProgressBar1.Value = 0
Me.labelStatus.Text = "Begin processing " & nCount.ToString & " file(s). Please wait."
If nCount > 0 AndAlso _WebsiteID > 0 Then
'start a new thread to increment the progressbar
BackgroundWorker1.WorkerSupportsCancellation = True
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.RunWorkerAsync(FileList)
End If
Catch ex As Exception
End Try
End Sub
#End Region
#Region "GetFiles"
Private Function GetFiles() As FileInfo()
Dim di As New DirectoryInfo(_DirectoryUrl)
Dim nfo As FileInfo() = di.GetFiles("*.zip")
Return nfo
End Function
#End Region
#Region "BackgroundWorker methods"
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'This method will run on a thread other than the UI thread.
'Be sure not to manipulate any Windows Forms controls created
'on the UI thread from this method.
Dim progress As Integer = 0
Dim FileList As List(Of FileInfo) = CType(e.Argument, List(Of FileInfo))
For Each nfo As FileInfo In FileList
If Me.BackgroundWorker1.CancellationPending Then Exit For
Dim FileSize As Integer = 1
Dim Comment As String = "n/a"
Dim zip As ICSharpCode.SharpZipLib.Zip.ZipFile = Nothing
Using fstream As New FileStream(nfo.FullName, FileMode.Open)
zip = New ZipFile(fstream)
FileSize = CInt(zip.Count)
Comment = zip.ZipFileComment
End Using
Dim biz As New Business.Archive
With biz
.Datestamp = nfo.CreationTime
.FileUrl = nfo.FullName
.Name = Path.GetFileNameWithoutExtension(nfo.Name)
.WebsiteID = _WebsiteID
.FileSize = FileSize
.Comment = Comment
End With
progress += 1
' Insert the Archive into our database
biz.ArchiveID = ArchiveManager.Insert(biz)
BackgroundWorker1.ReportProgress(progress, biz)
Next nfo
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
Me.labelStatus.Text = "Processed: " + CType(e.UserState, Business.Archive).Name + " (" & e.ProgressPercentage.ToString & " of " & Me.ProgressBar1.Maximum & ") "
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Me.labelStatus.Text = " (" & Me.ProgressBar1.Value.ToString & " of " & Me.ProgressBar1.Maximum & ") file(s) processed. Completed."
Me.ProgressBar1.Value = Me.ProgressBar1.Maximum
Me.ProgressBar1.Visible = False
End Sub
#End Region
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.