📄 wblgroups.vb
字号:
Public Class WBLGroups
Implements IDisposable
'Private variables and objects
Private objWDAGroups As WroxDataAccess.WDAGroups
Private disposed As Boolean = False
#Region " Constructor and Destructor "
Public Sub New(ByVal Company As String, ByVal Application As String)
objWDAGroups = New WroxDataAccess.WDAGroups(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
objWDAGroups.Dispose()
objWDAGroups = 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 Group Functions "
Public Function GetGroups() As DataSet
Try
'Call the data component to get all groups
GetGroups = objWDAGroups.GetGroups
'Loop through the DataSet and convert all DBNull values
'to empty strings
For intindex As Integer = 0 To _
GetGroups.Tables("Groups").Rows.Count - 1
'If the column contains a null value...
If IsDBNull(GetGroups.Tables("Groups").Rows( _
intindex).Item("GroupDescription")) Then
'Convert it to an empty string
GetGroups.Tables("Groups").Rows( _
intindex).Item("GroupDescription") = String.Empty
End If
Next
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function GetGroup(ByVal GroupID As Guid) As DataSet
Try
'Call the data component to get a specific group
GetGroup = objWDAGroups.GetGroup(GroupID)
'If the column contains a null value...
If IsDBNull(GetGroup.Tables("Group").Rows(0).Item( _
"GroupDescription")) Then
'Convert it to an empty string
GetGroup.Tables("Group").Rows(0).Item( _
"GroupDescription") = String.Empty
End If
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function GetNewGroupDS() As DataSet
Try
'Instantiate a new DataSet object
GetNewGroupDS = New DataSet
'Create a DataTable object
Dim objDataTable As DataTable = GetNewGroupDS.Tables.Add("Group")
'Create a DataColumn object
Dim objDataColumn As DataColumn
'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("GroupName", _
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("GroupDescription", _
Type.GetType("System.String"))
'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 AddGroup(ByVal Group As DataSet) As Boolean
Try
'Validate group data
ValidateGroupData(Group)
'Call the data component to add the new group
Return objWDAGroups.AddGroup(Group)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function UpdateGroup(ByVal Group As DataSet) As Boolean
Try
'Validate group data
ValidateGroupData(Group)
'Call the data component to update the group
Return objWDAGroups.UpdateGroup(Group)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function DeleteGroup(ByVal GroupID As Guid) As Boolean
Try
'Call the data component to delete the group
Return objWDAGroups.DeleteGroup(GroupID)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
#End Region
#Region " Public Group Projects Functions "
Public Function GetGroupProjects(ByVal GroupID As Guid) As DataSet
Try
'Call the data component to get all group projects
GetGroupProjects = objWDAGroups.GetGroupProjects(GroupID)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function GetNewGroupProjectsDS() As DataSet
Try
'Instantiate a new DataSet object
GetNewGroupProjectsDS = New DataSet
'Create a DataTable object
Dim objDataTable As DataTable = _
GetNewGroupProjectsDS.Tables.Add("GroupProjects")
'Create a DataColumn object
Dim objDataColumn As DataColumn
'Instantiate a new DataColumn and set its properties
objDataColumn = New DataColumn("GroupProjectID", _
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("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("ProjectID", _
Type.GetType("System.Guid"))
objDataColumn.AllowDBNull = False
'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 AddGroupProjects(ByVal GroupProjects As DataSet) As Boolean
Try
'Call the data component to add the group projects
Return objWDAGroups.AddGroupProjects(GroupProjects)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function DeleteGroupProjects(ByVal GroupID As Guid) As Boolean
Try
'Call the data component to delete the group projects
Return objWDAGroups.DeleteGroupProjects(GroupID)
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
#End Region
#Region " Private Validation Functions "
Private Sub ValidateGroupData(ByRef Group As DataSet)
'Validate the Name exists
If Group.Tables("Group").Rows(0).Item( _
"GroupName").ToString.Trim.Length = 0 Then
Throw New System.Exception( _
"Group Name is a required field.")
End If
'Validate Description value
If Not IsDBNull(Group.Tables("Group").Rows(0).Item( _
"GroupDescription")) Then
If Group.Tables("Group").Rows(0).Item( _
"GroupDescription") = String.Empty Or _
Group.Tables("Group").Rows(0).Item( _
"GroupDescription").ToString.Trim.Length = 0 Then
'Set it to a null value
Group.Tables("Group").Rows(0).Item( _
"GroupDescription") = DBNull.Value
Else
'Trim spaces
Group.Tables("Group").Rows(0).Item("GroupDescription") = _
Group.Tables("Group").Rows(0).Item( _
"GroupDescription").ToString.Trim
End If
End If
'Trim spaces
Group.Tables("Group").Rows(0).Item("GroupName") = _
Group.Tables("Group").Rows(0).Item("GroupName").ToString.Trim
End Sub
#End Region
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -