Imports DD_Rights Imports System.ComponentModel Public Class frmCheckRightsEntity Private DT_FILES As DataTable Private _error As Boolean = False Private countfiles As Integer = 0 Private WorkingFiles As Integer = 0 Private CURR_DOCID As Integer Private ENTITY_ID As Integer Dim righterrors 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 = clsDatabase.Return_Datatable(sql) cmbentity.DataSource = DT cmbentity.ValueMember = DT.Columns(0).ColumnName cmbentity.DisplayMember = DT.Columns(1).ColumnName lblstate.Visible = False 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 righterrors = False CURR_DOCID = 0 ENTITY_ID = cmbentity.SelectedValue Me.ProgressBar1.Visible = True 'BackgroundWorker erstellen ... BW_RightsEntity = New BackgroundWorker BW_RightsEntity.WorkerReportsProgress = True BW_RightsEntity.WorkerSupportsCancellation = True Dim sqlfiles = String.Format("SELECT * FROM VWPMO_WD_DOC_SEARCH where ENTITY_ID = {0} ORDER BY DocID", ENTITY_ID) DT_FILES = clsDatabase.Return_Datatable(sqlfiles) If DD_Rights.ClassRights.Init(ENTITY_ID, chklogging.Checked, DT_FILES.Rows.Count) = False Then MsgBox("Could not init rights management. " & vbNewLine & "Check logfile", MsgBoxStyle.Critical) Exit Sub End If btncancel.Visible = True lblstate.Visible = True lblstate.Text = "Starting Background Worker...." countfiles = DT_FILES.Rows.Count - 1 WorkingFiles = 0 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 Dim state = "Working on file '" & WorkingFiles.ToString & "' of '" & countfiles.ToString & "'" lblstate.Text = state 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 'Jede Datei einzeln verarbeiten 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"), row.Item("ENTITY_ID")) = True Then WorkingFiles += 1 CURR_DOCID = row.Item("DocID") If DD_Rights.ClassRights.TransferRights2Service(row.Item("DocID"), row.Item("FULL_FILENAME")) Then If DD_Rights.ClassRights.MSG_RESULT <> "" Then righterrors = True End If Else _error = True End If Else _error = True End If BW_RightsEntity.ReportProgress(i) i += 1 End If Next DD_Rights.ClassRights.Finalize_SettingRights() 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 lblstate.Visible = False ProgressBar1.Visible = False If _error = False Then clsDatabase.Execute_non_Query("UPDATE TBPMO_SERVICE_RIGHT_CONFIG SET RUN_SERVICE = 1 WHERE GUID = 1") If righterrors = True Then MsgBox("All rights of files belonging to entity were checked and refreshed, " & vbNewLine & "BUT some Userrights could not be set. Check the logfile!", MsgBoxStyle.Exclamation, "Attention") Else MsgBox("All rights of files belonging to entity were queued for central rights service!" & vbNewLine & "Rights will be set within the next 5 minutes!", MsgBoxStyle.Information) End If Else MsgBox("Some errors occured while preparing and queuing rights...please check the log!" & vbNewLine & ">> " & ClassRights.COUNT_FILES.ToString & " files schould be worked." & _ ">> " & ClassRights.WORKED_FILES.ToString & " were worked successfully.", MsgBoxStyle.Exclamation) End If Catch ex As Exception End Try End Sub End Class