⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wblusers.vb

📁 数据库学习的绝好例子简单的数据库经典入门
💻 VB
📖 第 1 页 / 共 2 页
字号:
Imports System.Text
Imports System.Security.Cryptography

Public Class WBLUsers
    Implements IDisposable

    'Private variables and objects
    Private objWDAUsers As WroxDataAccess.WDAUsers

    Private disposed As Boolean = False

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

    ' IDisposable
    Private Overloads Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposed Then
            If disposing Then
                ' TODO: put code to dispose managed resources
            End If

            objWDAUsers.Dispose()
            objWDAUsers = Nothing
        End If
        Me.disposed = True
    End Sub
#End Region

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Protected Overrides Sub Finalize()
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(False)
        MyBase.Finalize()
    End Sub
#End Region

#Region " Public User Functions "
    Public Function GetNewUserDS() As DataSet
        Try
            'Instantiate a new DataSet object
            GetNewUserDS = New DataSet

            'Create a DataTable object
            Dim objDataTable As DataTable = GetNewUserDS.Tables.Add("User")

            'Create a DataColumn object
            Dim objDataColumn As DataColumn

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("UserID", _
                Type.GetType("System.Guid"))
            objDataColumn.AllowDBNull = False

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("LoginName", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = False
            objDataColumn.MaxLength = 15

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("Password", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = True
            objDataColumn.MaxLength = 30

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("FirstName", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = False
            objDataColumn.MaxLength = 30

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("LastName", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = False
            objDataColumn.MaxLength = 30

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("Email", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = False
            objDataColumn.MaxLength = 50

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("Phone", _
                Type.GetType("System.String"))
            objDataColumn.AllowDBNull = False
            objDataColumn.MaxLength = 20

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("Status", _
                Type.GetType("System.Boolean"))
            objDataColumn.AllowDBNull = False

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("GroupID", _
                Type.GetType("System.Guid"))
            objDataColumn.AllowDBNull = False

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("RoleID", _
                Type.GetType("System.Guid"))
            objDataColumn.AllowDBNull = False

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)

            'Instantiate a new DataColumn and set its properties
            objDataColumn = New DataColumn("ManagerID", _
                Type.GetType("System.Guid"))
            objDataColumn.AllowDBNull = True

            'Add the column to the table
            objDataTable.Columns.Add(objDataColumn)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function AddUser(ByVal User As DataSet) As Boolean
        Try
            'Validate user data
            ValidateUserData(User)

            'Call the data component to add the new user
            Return objWDAUsers.AddUser(User)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetUsers() As DataSet
        Try
            'Call the data component to get all user
            GetUsers = objWDAUsers.GetUsers
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetUser(ByVal UserID As Guid) As DataSet
        Try
            'Call the data component to get a specific user
            GetUser = objWDAUsers.GetUser(UserID)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetManagers() As DataSet
        Try
            'Call the data component to get all user
            GetManagers = objWDAUsers.GetManagers
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

    Public Function GetManagerEmployees(ByVal ManagerID As Guid) As DataSet
        Try
            'Call the data component to get the manager's employees
            GetManagerEmployees = objWDAUsers.GetManagerEmployees(ManagerID)
        Catch ExceptionErr As Exception
            Throw New System.Exception(ExceptionErr.Message, _
                ExceptionErr.InnerException)
        End Try
    End Function

⌨️ 快捷键说明

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