Private Sub btn_Continue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Continue.Click
Try
If ShowProcessFormBackgroundWorker.IsBusy Then
ShowProcessFormBackgroundWorker.CancelAsync()
End If
Catch ex As Exception
End Try
ShowProcessFormBackgroundWorker = New BackgroundWorker
ShowProcessFormBackgroundWorker.WorkerReportsProgress = True
ShowProcessFormBackgroundWorker.WorkerSupportsCancellation = True
ShowProcessFormBackgroundWorker.RunWorkerAsync()
' Checks that the name field, a schedule event and days (if needed) are set.
If txb_Name.Text = Nothing Then
MessageBox.Show("Please give your schedule a valid name", _
"Name field empty", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Select Case cmb_Schedule_Type.Text
Case ""
MessageBox.Show("Please select a schedule type from the schedule menu", _
"Schedule type not selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
Case "Run once", "Daily", "Run every 14 days"
' Do nothing
Case Else
' Checks that at least one day is selected (if needed).
Dim CheckState As New ArrayList
For Each item As CheckBox In Panel_Days.Controls
CheckState.Add(item.Checked.ToString)
Next
If Not CheckState.Contains("True") Then
MessageBox.Show("Please select at least one day from the schedule panel", _
"No days selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
End Select
' Adds all selected files and folders to the Collection Arrays.
Dim Temptree As TreeView = New TreeView
Temptree = ExplorerTree
Dim Nodelist As List(Of TreeNode) = FlattenDepth(Temptree)
MainForm.arrFileCollection.Clear()
MainForm.arrFolderCollection.Clear()
For Each node As TreeNode In Nodelist
If node.Checked = True AndAlso node.Text IsNot Nothing AndAlso node.Name IsNot Nothing AndAlso _
node.Text IsNot "[EMPTY]" AndAlso node.Name IsNot "[EMPTY]" Then
If node.Tag = "File" Then
If node.Parent.Checked = False Then
MainForm.arrFileCollection.Add(node.Name)
End If
ElseIf node.Tag = "Folder" Then
MainForm.arrFolderCollection.Add(node.Name)
End If
End If
Next
' Checks that at least one file or folder are selected.
If MainForm.arrFileCollection.Count = 0 AndAlso MainForm.arrFolderCollection.Count = 0 Then
MessageBox.Show("Please select at least one file or folder from the filebrowser", _
"No file or folder selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
' Verifies that the FTP Connection is OK, if not show the settings panel and exit the sub.
If Not FTP_Connection_Test(MainForm.FTP_Hostname, DeCrypt(ReadSingleNode("username", MainForm.strFilePathConfig)) _
, DeCrypt(ReadSingleNode("password", MainForm.strFilePathConfig)), MainForm.FTP_port) = "True" Then
MessageBox.Show("Please enter a valid username and password and run the 'test connection' again", _
"Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Stop)
AddSingleNode("ftp_check_ok", "False", MainForm.strFilePathConfig)
SettingsForm.ShowDialog()
Exit Sub
End If
' Sets counters variables.
Dim lngTotalSize As Long = 0
Dim intFileCount As Integer = 0
Dim intFolderCount As Integer = 0
' loops thru all folders in the foldercollection and gets the total size and file/folder count.
For Each item As String In MainForm.arrFolderCollection
lngTotalSize = lngTotalSize + GetTotalSize(item.ToString, True)
intFileCount = intFileCount + CountFiles(item.ToString)
intFolderCount = intFolderCount + CountFolders(item.ToString)
Next
' Format total size to B, KB, MB or GB.
Dim strTotalSize As String = Nothing
If lngTotalSize < 1000 Then
strTotalSize = lngTotalSize.ToString & " Bytes"
ElseIf lngTotalSize > 1000 And lngTotalSize < 1000000 Then
strTotalSize = CType(lngTotalSize.ToString / 1024, Integer) & " KB"
ElseIf lngTotalSize > 1000000 And lngTotalSize < 1000000000 Then
strTotalSize = CType(lngTotalSize.ToString / 1048576, Integer) & " MB"
Else
strTotalSize = CType(lngTotalSize.ToString / 1073741824, Integer) & " GB"
End If
' Sets the finish panel lables.
lbl_Job_name.Text = lbl_Job_name.Text & " " & txb_Name.Text
lbl_Total_size.Text = lbl_Total_size.Text & " " & strTotalSize & " " & "(" & CType((lngTotalSize / 1024), Integer).ToString & " KB)"
lbl_Number_of_folders.Text = lbl_Number_of_folders.Text & " " & intFolderCount.ToString
lbl_Number_of_files.Text = lbl_Number_of_files.Text & " " & intFileCount.ToString
' Runs the SaveScheduleData sub.
SaveScheduleData()
Try
If ShowProcessFormBackgroundWorker.IsBusy Then
ShowProcessFormBackgroundWorker.CancelAsync()
End If
Catch ex As Exception
End Try
' Show the Finish Panel
Panel_Start.Enabled = False
Panel_Start.Visible = False
Panel_Finish.Enabled = True
Panel_Finish.Visible = True
End Sub