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

📄 admin.vb

📁 数据库学习的绝好例子简单的数据库经典入门
💻 VB
📖 第 1 页 / 共 5 页
字号:
                        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

                    'Reload the Users list
                    LoadUsers()
            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"
                    '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") = New Guid(txtRoleID.Text)
                        objDataRow.Item("RoleName") = txtRoleName.Text
                        objDataRow.Item("RoleDescription") = _
                            txtRoleDescription.Text
                        objDataRow.Item("Ranking") = _
                            CType(txtRanking.Text, Byte)
                        'Add the DataRow to the DataSet
                        objDataSet.Tables("Role").Rows.Add(objDataRow)
                        'Update the Role in the database
                        If Not objRoles.UpdateRole(objDataSet) Then
                            Throw New Exception("Update 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

                    'Reload the Roles list
                    Call LoadRoles()

                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 Role DataSet
                        Dim objDataRow As Data.DataRow = _
                            objDataSet.Tables("User").NewRow
                        'Set the values in the DataRow
                        objDataRow.Item("UserID") = New Guid(txtUserID.Text)
                        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)
                        'Update the User in the database
                        If Not objUsers.UpdateUser(objDataSet) Then
                            Throw New Exception("Update 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
                    txtUserUpdateDate.Text = String.Empty


                    'Reload the Managers combo box
                    Call LoadManagers()

                    'Reload the Users list
                    Call LoadUsers()
                    cboUserGroup.SelectedIndex = -1
                    cboUserRole.SelectedIndex = -1
                    cboUserManager.SelectedIndex = -1
            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
                        If Not objGroups.DeleteGroup( _
                            New Guid(txtGroupID.Text)) Then
                            Throw New Exception("Delete 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"
                    'Initialize a new instance of the business logic component
                    Using objGroups As New WroxBusinessLogic.WBLGroups( _
                        strCompany, strApplication)
                        'Delete the group projects
                        objGroups.DeleteGroupProjects( _
                            New Guid( _
                            cboGroups.SelectedItem.Item("GroupID").ToString))
                    End Using

                    'Clear previous bindings
                    If Not blnLoading Then
                        lstGroupProjects.DataSource = Nothing
                        lstGroupProjects.DisplayMember = String.Empty
                        lstGroupProjects.ValueMember = String.Empty
                        lstGroupProjects.Items.Clear()
                        blnLoading = True
                        cboGroups.SelectedIndex = -1
                        blnLoading = False
                    End If

                Case "Roles"
                    'Initialize a new instance of the business logic component
                    Using objRoles As New WroxBusinessLogic.WBLRoles( _
                        strCompany, strApplication)
                        'Delete the role
                        If Not objRoles.DeleteRole( _
                            New Guid(txtRoleID.Text)) Then
                            Throw New Exception("Delete 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

                    'Reload the Roles list
                    Call LoadRoles()

                Case "Users"

⌨️ 快捷键说明

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