Imports DD_Rights Imports System.ComponentModel Public Class frmCheckRightsEntity Private DT_FILES As DataTable Private _error As Boolean = False Private Sub frmCheckRightsEntity_Load(sender As Object, e As EventArgs) Handles Me.Load Try Dim sql = String.Format("SELECT T.FORM_ID, [dbo].[FNPMO_GETOBJECTCAPTION]('{0}','FORMVIEW_TITLE' + CONVERT(VARCHAR(5), T.[FORM_VIEW_ID]), 1) AS FORM_TITLE FROM VWPMO_CONSTRUCTOR_FORMS T WHERE DOCUMENT_VIEW = 1", USER_LANGUAGE) Dim DT As DataTable = ClassDatabase.Return_Datatable(sql) cmbentity.DataSource = DT cmbentity.ValueMember = DT.Columns(0).ColumnName cmbentity.DisplayMember = DT.Columns(1).ColumnName Catch ex As Exception MsgBox("Unexpected error in load form: " & vbNewLine & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub btnCheckRights_Click(sender As Object, e As EventArgs) Handles btnCheckRights.Click If cmbentity.SelectedIndex <> -1 Then Try Me.ProgressBar1.Visible = True 'BackgroundWorker erstellen ... BW_RightsEntity = New BackgroundWorker BW_RightsEntity.WorkerReportsProgress = True DT_FILES = ClassDatabase.Return_Datatable(String.Format("SELECT * FROM VWPMO_WD_DOC_SEARCH where ENTITY_ID = {0}", cmbentity.SelectedValue)) If DD_Rights.ClassRights.Init(cmbentity.SelectedValue, chklogging.Checked, DT_FILES.Rows.Count) = False Then MsgBox("Could not init rights management. " & vbNewLine & "Check logfile", MsgBoxStyle.Critical) Exit Sub End If ProgressBar1.Maximum = DT_FILES.Rows.Count AddHandler BW_RightsEntity.DoWork, AddressOf bw_DoWork '.. und starten BW_RightsEntity.RunWorkerAsync() Catch ex As Exception MsgBox("Unexpected error in starting backgroundworker: " & vbNewLine & ex.Message, MsgBoxStyle.Critical) Me.ProgressBar1.Visible = False End Try End If End Sub Private Sub BW_RightsEntity_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BW_RightsEntity.ProgressChanged Me.ProgressBar1.Value = e.ProgressPercentage End Sub Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Dim worker As BackgroundWorker = CType(sender, BackgroundWorker) _error = False Dim i As Integer = 1 For Each row As DataRow In DT_FILES.Rows If BW_RightsEntity.CancellationPending = True Then e.Cancel = True Exit For Else If DD_Rights.ClassRights.Collect_Users(row.Item("RECORD_ID")) = True Then If DD_Rights.ClassRights.File_DeleteAndSetRight(row.Item("FULL_FILENAME"), True) Then If DD_Rights.ClassRights.MSG_RESULT <> "" Then MsgBox("Unexpected Errors in setting rights: " & vbNewLine & DD_Rights.ClassRights.MSG_RESULT, MsgBoxStyle.Exclamation) _error = True Else End If Else _error = True End If Else _error = True End If BW_RightsEntity.ReportProgress(i) i += 1 End If Next End Sub Private Sub btncancel_Click(sender As Object, e As EventArgs) Handles btncancel.Click ' Cancel the asynchronous operation. Me.BW_RightsEntity.CancelAsync() End Sub Private Sub BW_RightsEntity_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BW_RightsEntity.RunWorkerCompleted Try btncancel.Visible = False ProgressBar1.Visible = False If _error = False Then MsgBox("All rights of files belonging to entity were checked and refreshed successfully!", MsgBoxStyle.Information) Else MsgBox("Some errors occured while checking and setting the rights...please check the log!", MsgBoxStyle.Exclamation) End If Catch ex As Exception End Try End Sub End Class