wblroles.vb

来自「Beginning VB.NET DatabasesAll_Code.rar」· VB 代码 · 共 129 行

VB
129
字号
Public Class WBLRoles
    Implements IDisposable

#Region " Class Level Variables "
    Private objWDARoles As WroxDataAccess.WDARoles
#End Region

#Region " Constructor and Destructor "
    Public Sub New(ByVal Company As String, ByVal Application As String)
        objWDARoles = New WroxDataAccess.WDARoles(Company, Application)
    End Sub

    Public Sub Dispose() Implements System.IDisposable.Dispose
        objWDARoles.Dispose()
        objWDARoles = Nothing
    End Sub
#End Region

#Region " Public Role Functions "
    Public Function GetRoles() As DataSet
        Try
            'Call the data component to get all roles
            GetRoles = objWDARoles.GetRoles
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetRole(ByVal RoleID As Guid) As DataSet
        Try
            'Call the data component to get a specific role
            GetRole = objWDARoles.GetRole(RoleID)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetNewRoleDS() As DataSet
        Try
            'Return the Role schema as a DataSet
            GetNewRoleDS = New Role
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function AddRole(ByVal Role As DataSet) As Boolean
        Try
            'Validate the Name exists
            If Role.Tables("Role").Rows(0).Item( _
                "RoleName").ToString.Trim.Length = 0 Then
                Throw New System.Exception( _
                    "Role Name is a required field.")
            End If

            'Validate Description value
            If Not IsDBNull(Role.Tables("Role").Rows(0).Item( _
                "RoleDescription")) Then
                If Role.Tables("Role").Rows(0).Item( _
                    "RoleDescription") = String.Empty Or _
                    Role.Tables("Role").Rows(0).Item( _
                    "RoleDescription").ToString.Trim.Length = 0 Then
                    'Set it to a null value
                    Role.Tables("Role").Rows(0).Item( _
                        "RoleDescription") = DBNull.Value
                Else
                    'Trim spaces
                    Role.Tables("Role").Rows(0).Item("RoleDescription") = _
                        Role.Tables("Role").Rows(0).Item( _
                        "RoleDescription").ToString.Trim
                End If
            End If

            'Trim spaces
            Role.Tables("Role").Rows(0).Item("RoleName") = _
                Role.Tables("Role").Rows(0).Item("RoleName").ToString.Trim

            'Call the data component to add the new group
            Return objWDARoles.AddRole(Role)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function UpdateRole(ByVal Role As DataSet) As Boolean
        Try
            'Validate the Name exists
            If Role.Tables("Role").Rows(0).Item( _
                "RoleName").ToString.Trim.Length = 0 Then
                Throw New System.Exception( _
                    "Role Name is a required field.")
            End If

            'Validate Description value
            If Not IsDBNull(Role.Tables("Role").Rows(0).Item( _
                "RoleDescription")) Then
                If Role.Tables("Role").Rows(0).Item( _
                    "RoleDescription") = String.Empty Or _
                    Role.Tables("Role").Rows(0).Item( _
                    "RoleDescription").ToString.Trim.Length = 0 Then
                    'Set it to a null value
                    Role.Tables("Role").Rows(0).Item( _
                        "RoleDescription") = DBNull.Value
                Else
                    'Trim spaces
                    Role.Tables("Role").Rows(0).Item("RoleDescription") = _
                        Role.Tables("Role").Rows(0).Item( _
                        "RoleDescription").ToString.Trim
                End If
            End If

            'Trim spaces
            Role.Tables("Role").Rows(0).Item("RoleName") = _
                Role.Tables("Role").Rows(0).Item("RoleName").ToString.Trim

            'Call the data component to update the role
            Return objWDARoles.UpdateRole(Role)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
             ExceptionErr.InnerException)
        End Try
    End Function
#End Region
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?