|
-
Nov 17th, 2011, 02:22 PM
#1
Thread Starter
Member
BackGroundWorker and ListView
Hi,
I am trying to populate a listview from a sql table and at the same time run a progress bar. Currently my progressbar does't run and also the listview does not poulate. I believe there is something wrong with my arraylist but I can't figure it out. Please help. I am using VB.net.
HTML Code:
Dim lsvdupsitemlist As New List(Of ListViewItem)
Private Sub FindDupsBGW_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles FindDupsBGW.DoWork
Try
'Connect to Laserfiche
Dim app As LFApplication = New LFApplication
Dim serv As LFServer = app.GetServerByName("")
Dim db As LFDatabase = serv.GetDatabaseByName("")
Dim conn As New LFConnection
conn.UserName = ""
conn.Password = ""
conn.Create(db)
'Use to cause Permission denied error and checks to see if folder path exists
Try
Dim CheckFolderExists As LFFolder = db.GetEntryByPath(SearchTextBox.Text)
Dim st As ILFFolderStats = CType(CheckFolderExists.Stats(False), ILFFolderStats)
Catch
MessageBox.Show("Unable to access folder. Folder access is not authorized. Please re-enter the folder path or contact your system Administrator.", "Access Denied:", MessageBoxButtons.OK, MessageBoxIcon.Stop)
e.Cancel = True
Exit Sub
End Try
LFcnn = LFSQLDBConnect()
LFcnn.Open()
'Checks to see if table already exists in SQL. If yes, drop and recreate.
'Try
Dim format As String = "HHmmss"
Dim SQLTable As String = "T" + strip(GetdateLabel.Text)
Dim command0 As SqlClient.SqlCommand = New SqlClient.SqlCommand("IF EXISTS(SELECT name FROM [LFDUPS]..sysobjects WHERE name = N'" & SQLTable & "' AND xtype='U') DROP TABLE " & SQLTable & "", LFcnn)
Dim command1 As SqlClient.SqlCommand = New SqlClient.SqlCommand("create table " & SQLTable & " (Tocid nvarchar(max), FolderName nvarchar(max), FullPath nvarchar(max))", LFcnn)
command0.ExecuteNonQuery()
command1.ExecuteNonQuery()
' Catch ex As Exception
'MessageBox.Show(ex.ToString)
' End Try
'Check Cancel command
If (FindDupsBGW.CancellationPending) Then
e.Cancel = True
Exit Sub
End If
'Performs search within Laserfiche
Dim SearchVar As String = "ThurstonCounty\" + SearchTextBox.Text
''Dim SQLTable As String = "T" + strip(GetdateLabel.Text)
Dim NewSearch As LFSearch = db.CreateSearch
'NewSearch.Command = "{LF:Lookin=""" + SearchVar + """,subfolders=y} & {LF:Name=""*"",Type=""D""}"
NewSearch.Command = "{LF:Lookin=""" + SearchVar + """} & {LF:Name=""*"",Type=""F""}"
'NewSearch.Command = "{LF:LOOKIN=""ThurstonCounty\_Central_Services\Projects\7117-25190 ARC Phase 1\Contract Documents\Change Order Requests Proposal (PCO's)""} & {LF:Name=""*"", Type=""F""}"
NewSearch.BeginSearch(True)
Dim allhits As ILFCollection = NewSearch.GetSearchHits
For Each hit As LFSearchHit In allhits
Dim entryhits As ILFEntry = hit.Entry
Dim command3 As SqlClient.SqlCommand = New SqlClient.SqlCommand("Insert INTO " & SQLTable & " (TocId, FolderName, Fullpath) Values('" & CleanSQLValue(entryhits.ID) & "','" & CleanSQLValue(entryhits.Name) & "','" & CleanSQLValue(entryhits.FullPath.ToString) & "')", LFcnn)
command3.ExecuteNonQuery()
Next
'End If
LFcnn.Close()
LFcnn.Dispose()
conn.Terminate()
Catch ex As Exception
'MessageBox.Show("Unable to search Folder." + " " + " Please re-enter Folder Path or contact your System Administrator.", "Search Error:", MessageBoxButtons.OK, MessageBoxIcon.Error)
MessageBox.Show("Unable to search Folder." + ex.ToString + " Please re-enter Folder Path or contact your System Administrator.", "Search Error:", MessageBoxButtons.OK, MessageBoxIcon.Error)
e.Cancel = True
End Try
'add to listview
'If ToDateTimePicker.Checked = False AndAlso FromDateTimePicker.Checked = False Then
SearchByDateval = "and created between '1/01/2000' and" + " " + "'" + Format(Date.Now, "MM/dd/yyyy") + "'"
'Else
'SearchByDateval = "and created between" & " '" & Format(FromDateTimePicker.Value, "MM/dd/yyyy") & " '" & " and" + " " & " '" & Format(ToDateTimePicker.Value.AddDays(1), "MM/dd/yyyy") & " '"
'End If
'Populate ListView with results. Displays potential duplicates from Diferent folders within laserfiche.
Try
LFcnn = LFSQLDBConnect()
LFcnn.Open()
Dim SQLTable As String = "T" + strip(GetdateLabel.Text)
Dim LFsqlresult As Object
Dim command01 As SqlClient.SqlCommand = New SqlClient.SqlCommand("select count(*) from LFContents," & SQLTable & " where LFContents.Name in (select LFContents.Name from LFContents," & SQLTable & " where LFContents.PARENTid = " & SQLTable & " " & ".TocId" & " group by LFContents.Name having count(*) > 1 ) AND ETYPE = -2", LFcnn)
command01.CommandType = CommandType.Text
command01.CommandTimeout = 600
command01.ExecuteScalar()
LFsqlresult = command01.ExecuteScalar
If LFsqlresult = 0 Then
ResultsListView.Items.Add("No Duplicates Found")
ProgressBar.Hide()
ExportToFileButton.Enabled = False
LFcnn.Close()
Exit Sub
Else
Dim LFsqlresultRead As Object
Dim command02 As SqlClient.SqlCommand = New SqlClient.SqlCommand("select distinct LFContents.Name as EntryName, LFContents.edoc_size as FileSize, LFContents.Created as CreationDate, " & SQLTable & " " & ".Fullpath from LFContents, " & SQLTable & " where LFContents.Name in (select LFContents.Name from LFContents," & SQLTable & " where LFContents.PARENTid = " & SQLTable & " " & ".TocId" & " group by LFContents.Name having count(*) > 1 ) and LFContents.PARENTid = " & SQLTable & " " & ".TocId" & " " & " AND ETYPE = -2" & " " & SearchByDateval & "Union select distinct LFContents.Name, LFContents.edoc_size as FileSize, LFContents.Created, " & SQLTable & " " & ".Fullpath from LFContents, " & SQLTable & " where LFContents.Name like '%(%' and LFContents.PARENTid = " & " " & SQLTable & " " & ".TocId" & " " & "AND ETYPE = -2" & " " & SearchByDateval & " order by LFContents.Name ", LFcnn)
command02.CommandType = CommandType.Text
command02.CommandTimeout = 600
LFsqlresultRead = command02.ExecuteReader
'lsvdupsitems.SubItems.Clear()
While LFsqlresultRead.Read()
If LFsqlresultRead.Item(0).ToString <> "" Then
'Column name of ListView needs to be the same as SQl table coulumn names
Dim lsvdupsitems As New ListViewItem '= ResultsListView.Items.Add(".")
lsvdupsitemlist.Add(lsvdupsitems)
FindDupsBGW.ReportProgress(LFsqlresultRead.Item(0))
Threading.Thread.Sleep(100)
End If
End While
End If
LFcnn.Close()
LFcnn.Dispose()
Catch ex As Exception
MessageBox.Show("Unable to populate List of results." + " " + ex.Message + "Please try again or contact your System Administrator.", "Database Connection Error:", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles FindDupsBGW.ProgressChanged
ProgressBar.Value = e.ProgressPercentage
ResultsListView.Items.AddRange(lsvdupsitemlist.toarray())
End Sub
Dim SearchByDateval As String
Private Sub FindDupsBGW_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles FindDupsBGW.RunWorkerCompleted
If e.Cancelled = True Then
ProgressBar.Hide()
ExportToFileButton.Enabled = False
Exit Sub
Else
CancelButton.Enabled = False
End If
TimeLapseTimer.Stop()
ProgressBar.Hide()
ExportToFileButton.Enabled = True
AutoFitListView(ResultsListView)
LFcnn.Close()
LFcnn.Dispose()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|