Public Class ClassRightManagement
    Public Shared Sub Check_Set_Rights(RECORD_ID As Integer, ENTITY_ID As Integer)
        Try
            Dim sw = New SW("Check_Set_Rights")
            RIGHT_EDIT_R = False
            RIGHT_ADD_R = False
            RIGHT_DELETE_R = False
            RIGHT_RECORD_AND_FILE_READ_ONLY = False

            RIGHT_ADD_DOC = False
            RIGHT_VIEW_DOC = True
            RIGHT_DELETE_DOC = False
            RIGHT_READ_ONLY_DOC = False
            ' Wenn Rechte pro Record defineirt wurden!!!
            If SQL_RECORD_AND_FILE_READ_ONLY <> "" Or SQL_DOC_READ_ONLY <> "" Then
                If SQL_RECORD_AND_FILE_READ_ONLY <> "" Then
                    RIGHT_RECORD_AND_FILE_READ_ONLY = ClassHelper.Check_Record_Read_only(RECORD_ID, ENTITY_ID)
                    If RIGHT_RECORD_AND_FILE_READ_ONLY = True Then
                        RIGHT_EDIT_R = False
                        RIGHT_ADD_R = False
                        RIGHT_DELETE_R = False
                    End If
                End If
                If SQL_DOC_READ_ONLY <> "" Then
                    RIGHT_READ_ONLY_DOC = ClassHelper.Check_File_Read_only(RECORD_ID, ENTITY_ID)
                    If RIGHT_READ_ONLY_DOC = True Then
                        RIGHT_ADD_DOC = False
                        RIGHT_DELETE_DOC = False
                    Else
                        RIGHT_ADD_DOC = True
                        RIGHT_DELETE_DOC = True
                    End If
                End If
            Else
                If DT_RIGHTS_USER Is Nothing Or DT_RIGHTS_GROUP Is Nothing Then
                    Dim Sql As String
                    Sql = String.Format("select * from TBPMO_RIGHT_USER WHERE USER_ID = {0} AND ENTITY_ID = {1}", USER_GUID, ENTITY_ID)
                    DT_RIGHTS_USER = MYDB_ECM.GetDatatable(sql)
                    Sql = String.Format("SELECT DISTINCT EDIT_REC,ADD_REC,DELETE_REC,ADD_DOC,VIEW_DOC,DELETE_DOC FROM TBPMO_RIGHT_GROUP WHERE ENTITY_ID = {0} AND GROUP_ID IN (SELECT GROUP_ID FROM TBDD_GROUPS_USER WHERE USER_ID = {1})", ENTITY_ID, USER_GUID)
                    DT_RIGHTS_GROUP = MYDB_ECM.GetDatatable(sql)
                End If

                'Definition der Rechte erfolgt über UserGroupstable......wenn gefüllt
                If DT_RIGHTS_GROUP.Rows.Count > 0 And DT_RIGHTS_USER.Rows.Count = 0 Then
                    For Each row As DataRow In DT_RIGHTS_GROUP.Rows
                        RIGHT_EDIT_R = CBool(DT_RIGHTS_GROUP.Rows(0).Item(0))
                        RIGHT_ADD_R = CBool(DT_RIGHTS_GROUP.Rows(0).Item(1))
                        RIGHT_DELETE_R = CBool(DT_RIGHTS_GROUP.Rows(0).Item(2))

                        RIGHT_ADD_DOC = CBool(DT_RIGHTS_GROUP.Rows(0).Item(3))
                        RIGHT_VIEW_DOC = CBool(DT_RIGHTS_GROUP.Rows(0).Item(4))
                        RIGHT_DELETE_DOC = CBool(DT_RIGHTS_GROUP.Rows(0).Item(5))
                        If RIGHT_ADD_DOC = False And RIGHT_DELETE_DOC = False Then
                            RIGHT_READ_ONLY_DOC = True
                        End If

                    Next
                Else
                    'Definition der Rechte erfolgt über UserRighttable
                    If DT_RIGHTS_USER.Rows.Count = 1 Then
                        RIGHT_EDIT_R = CBool(DT_RIGHTS_USER.Rows(0).Item("EDIT_REC"))
                        RIGHT_ADD_R = CBool(DT_RIGHTS_USER.Rows(0).Item("ADD_REC"))
                        RIGHT_DELETE_R = CBool(DT_RIGHTS_USER.Rows(0).Item("DELETE_REC"))

                        RIGHT_ADD_DOC = CBool(DT_RIGHTS_USER.Rows(0).Item("ADD_DOC"))
                        RIGHT_VIEW_DOC = CBool(DT_RIGHTS_USER.Rows(0).Item("FILES_VISIBLE"))
                        RIGHT_DELETE_DOC = CBool(DT_RIGHTS_USER.Rows(0).Item("DELETE_DOC"))
                        RIGHT_READ_ONLY_DOC = CBool(DT_RIGHTS_USER.Rows(0).Item("READ_ONLY_DOC"))
                    End If
                End If
            End If

            LOGGER.Debug("RIGHT_EDIT_R: " & RIGHT_EDIT_R.ToString)
                LOGGER.Debug("RIGHT_ADD_R: " & RIGHT_ADD_R.ToString)
                LOGGER.Debug("RIGHT_DELETE_R: " & RIGHT_DELETE_R.ToString)
                LOGGER.Debug("RIGHT_ADD_DOC: " & RIGHT_ADD_DOC.ToString)
                LOGGER.Debug("RIGHT_VIEW_DOC: " & RIGHT_VIEW_DOC.ToString)
                LOGGER.Debug("RIGHT_DELETE_DOC: " & RIGHT_DELETE_DOC.ToString)
                LOGGER.Debug("RIGHT_READ_ONLY_DOC: " & RIGHT_READ_ONLY_DOC.ToString)

            sw.Done()
        Catch ex As Exception
            ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Check_Set_Rights", ex.Message, ex.StackTrace)
        End Try
    End Sub
End Class
