📄 admin.vb
字号:
Private Sub UpdateToolStripButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles UpdateToolStripButton.Click
ActionUpdate()
End Sub
Private Sub DeleteToolStripButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles DeleteToolStripButton.Click
ActionDelete()
End Sub
#End Region
#Region " Add, Update and Delete Procedures "
Private Sub ActionAdd()
Try
'Add database row based on the active screen
Select Case strActiveScreen
Case "Projects"
'Initialize a new instance of the business logic component
Using objProjects As New WroxBusinessLogic.WBLProjects( _
strCompany, strApplication)
'Get a new Project DataSet
objDataSet = objProjects.GetNewProjectDS()
'Initialize a datarow object from the Project DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("Project").NewRow
'Set the values in the DataRow
objDataRow.Item("ProjectID") = Guid.NewGuid()
objDataRow.Item("ProjectName") = txtProjectName.Text
objDataRow.Item("ProjectDescription") = _
txtProjectDescription.Text
objDataRow.Item("SequenceNumber") = _
CType(txtSequenceNumber.Text, Byte)
'Add the DataRow to the DataSet
objDataSet.Tables("Project").Rows.Add(objDataRow)
'Add the Project
If Not objProjects.AddProject(objDataSet) Then
Throw New Exception("Insert Project Failed")
End If
End Using
'Clear the input fields
txtProjectName.Text = String.Empty
txtProjectDescription.Text = String.Empty
txtSequenceNumber.Text = String.Empty
'Reload the Projects list
LoadProjects()
Case "Groups"
'Initialize a new instance of the business logic component
Using objGroups As New WroxBusinessLogic.WBLGroups( _
strCompany, strApplication)
'Get a new Group DataSet
objDataSet = objGroups.GetNewGroupDS()
'Initialize a datarow object from the Group DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("Group").NewRow
'Set the values in the DataRow
objDataRow.Item("GroupID") = Guid.NewGuid()
objDataRow.Item("GroupName") = txtGroupName.Text
objDataRow.Item("GroupDescription") = _
txtGroupDescription.Text
'Add the DataRow to the DataSet
objDataSet.Tables("Group").Rows.Add(objDataRow)
'Add the Groups to the database
If Not objGroups.AddGroup(objDataSet) Then
Throw New Exception("Insert Group Failed")
End If
End Using
'Clear the input fields
txtGroupName.Text = String.Empty
txtGroupDescription.Text = String.Empty
'Reload the Groups list
LoadGroups()
Case "Group Projects"
'Turn the loading flag on so no items are processed
blnLoading = True
'Delete any previous projects
Call ActionDelete()
'Turn the loading flag off
blnLoading = False
'Initialize a new instance of the business logic component
Using objGroups As New WroxBusinessLogic.WBLGroups( _
strCompany, strApplication)
'Get a new GroupProjects DataSet
objDataSet = objGroups.GetNewGroupProjectsDS()
For intIndex = 0 To objGroupProjectsDS.Tables( _
"GroupProjects").Rows.Count - 1
'Initialize a datarow object from the
'GroupProjects(DataSet)
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("GroupProjects").NewRow
'Set the values in the DataRow
objDataRow.Item("GroupProjectID") = Guid.NewGuid()
objDataRow.Item("GroupID") = _
cboGroups.SelectedItem.Item("GroupID")
objDataRow.Item("ProjectID") = _
objGroupProjectsDS.Tables( _
"GroupProjects").Rows(intIndex).Item("ProjectID")
'Add the DataRow to the DataSet
objDataSet.Tables("GroupProjects").Rows.Add(objDataRow)
Next
'Add the GroupProjects to the database
If Not objGroups.AddGroupProjects(objDataSet) Then
Throw New Exception("Insert Group Failed")
End If
End Using
'Clear previous bindings
lstGroupProjects.DataSource = Nothing
lstGroupProjects.DisplayMember = String.Empty
lstGroupProjects.ValueMember = String.Empty
lstGroupProjects.Items.Clear()
'Turn the loading flag on so no items are processed
blnLoading = True
cboGroups.SelectedIndex = -1
'Turn the loading flag off
blnLoading = False
Case "Roles"
'Initialize a new instance of the business logic component
Using objRoles As New WroxBusinessLogic.WBLRoles( _
strCompany, strApplication)
'Get a new Role DataSet
objDataSet = objRoles.GetNewRoleDS()
'Initialize a datarow object from the Role DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("Role").NewRow
'Set the values in the DataRow
objDataRow.Item("RoleID") = Guid.NewGuid
objDataRow.Item("RoleName") = txtRoleName.Text
objDataRow.Item("RoleDescription") = _
txtRoleDescription.Text
If IsNumeric(txtRanking.Text) Then
objDataRow.Item("Ranking") = _
CType(txtRanking.Text, Byte)
Else
Throw New Exception( _
"Ranking must contain a numeric value.")
End If
'Add the DataRow to the DataSet
objDataSet.Tables("Role").Rows.Add(objDataRow)
'Add the Role to the database
If Not objRoles.AddRole(objDataSet) Then
Throw New Exception("Insert Role Failed")
End If
End Using
'Clear the input fields
txtRoleID.Text = String.Empty
txtRoleName.Text = String.Empty
txtRoleDescription.Text = String.Empty
txtRanking.Text = String.Empty
txtRoleUpdateDate.Text = String.Empty
Case "Users"
'Initialize a new instance of the business logic component
Using objUsers As New WroxBusinessLogic.WBLUsers( _
strCompany, strApplication)
'Get a new User DataSet
objDataSet = objUsers.GetNewUserDS()
'Initialize a datarow object from the User DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("User").NewRow
'Set the values in the DataRow
objDataRow.Item("UserID") = Guid.NewGuid
objDataRow.Item("LoginName") = txtLogin.Text
objDataRow.Item("Password") = txtPassword.Text
objDataRow.Item("FirstName") = txtFirstName.Text
objDataRow.Item("LastName") = txtLastName.Text
objDataRow.Item("Email") = txtEmail.Text
objDataRow.Item("Phone") = txtPhone.Text
objDataRow.Item("Status") = optStatusActive.Checked
objDataRow.Item("GroupID") = _
cboUserGroup.SelectedItem.Item("GroupID")
objDataRow.Item("RoleID") = _
cboUserRole.SelectedItem.Item("RoleID")
If cboUserManager.SelectedIndex <> -1 Then
objDataRow.Item("ManagerID") = _
cboUserManager.SelectedItem.item("ManagerID")
End If
'Add the DataRow to the DataSet
objDataSet.Tables("User").Rows.Add(objDataRow)
'Add the User to the database
If Not objUsers.AddUser(objDataSet) Then
Throw New Exception("Insert User Failed")
End If
End Using
'Clear the input fields
txtUserID.Text = String.Empty
txtLogin.Text = String.Empty
txtPassword.Text = String.Empty
txtFirstName.Text = String.Empty
txtLastName.Text = String.Empty
txtEmail.Text = String.Empty
txtPhone.Text = String.Empty
optStatusActive.Checked = True
cboUserGroup.SelectedIndex = -1
cboUserRole.SelectedIndex = -1
cboUserManager.SelectedIndex = -1
txtUserUpdateDate.Text = String.Empty
End Select
'Display a message that the record was added
ToolStripStatus.Text = "Record Added"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Sub
Private Sub ActionUpdate()
Try
'Update database row based on the active screen
Select Case strActiveScreen
Case "Projects"
'Initialize a new instance of the business logic component
Using objProjects As New WroxBusinessLogic.WBLProjects( _
strCompany, strApplication)
'Get a new Project DataSet
objDataSet = objProjects.GetNewProjectDS()
'Initialize a datarow object from the Project DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("Project").NewRow
'Set the values in the DataRow
objDataRow.Item("ProjectID") = New Guid(txtProjectID.Text)
objDataRow.Item("ProjectName") = txtProjectName.Text
objDataRow.Item("ProjectDescription") = _
txtProjectDescription.Text
objDataRow.Item("SequenceNumber") = _
CType(txtSequenceNumber.Text, Integer)
'Add the DataRow to the DataSet
objDataSet.Tables("Project").Rows.Add(objDataRow)
'Update the Project in the database
If Not objProjects.UpdateProject(objDataSet) Then
Throw New Exception("Update Project Failed")
End If
End Using
'Clear the input fields
txtProjectID.Text = String.Empty
txtProjectName.Text = String.Empty
txtProjectDescription.Text = String.Empty
txtSequenceNumber.Text = String.Empty
txtProjectUpdateDate.Text = String.Empty
'Reload the Projects list
LoadProjects()
Case "Groups"
'Initialize a new instance of the business logic component
Using objGroups As New WroxBusinessLogic.WBLGroups( _
strCompany, strApplication)
'Get a new Group DataSet
objDataSet = objGroups.GetNewGroupDS()
'Initialize a datarow object from the Group DataSet
Dim objDataRow As Data.DataRow = _
objDataSet.Tables("Group").NewRow
'Set the values in the DataRow
objDataRow.Item("GroupID") = New Guid(txtGroupID.Text)
objDataRow.Item("GroupName") = txtGroupName.Text
objDataRow.Item("GroupDescription") = _
txtGroupDescription.Text
'Add the DataRow to the DataSet
objDataSet.Tables("Group").Rows.Add(objDataRow)
'Add the Group to the database
If Not objGroups.UpdateGroup(objDataSet) Then
Throw New Exception("Update Group Failed")
End If
End Using
'Clear the input fields
txtGroupID.Text = String.Empty
txtGroupName.Text = String.Empty
txtGroupDescription.Text = String.Empty
txtGroupUpdateDate.Text = String.Empty
'Reload the Groups list
LoadGroups()
Case "Group Projects"
'Turn the loading flag on so no items are processed
blnLoading = True
Call ActionAdd()
Case "Roles"
Case "Users"
End Select
'Display a message that the record was update
ToolStripStatus.Text = "Record Updated"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Sub
Private Sub ActionDelete()
Try
'Delete database row based on the active screen
Select Case strActiveScreen
Case "Projects"
'Initialize a new instance of the business logic component
Using objProjects As New WroxBusinessLogic.WBLProjects( _
strCompany, strApplication)
'Delete the project
If Not objProjects.DeleteProject( _
New Guid(txtProjectID.Text)) Then
Throw New Exception("Delete Project Failed")
End If
End Using
'Clear the input fields
txtProjectID.Text = String.Empty
txtProjectName.Text = String.Empty
txtProjectDescription.Text = String.Empty
txtSequenceNumber.Text = String.Empty
txtProjectUpdateDate.Text = String.Empty
'Reload the Projects list
LoadProjects()
Case "Groups"
'Initialize a new instance of the business logic component
Using objGroups As New WroxBusinessLogic.WBLGroups( _
strCompany, strApplication)
'Delete the group
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -