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

📄 admin.vb

📁 数据库学习的绝好例子简单的数据库经典入门
💻 VB
📖 第 1 页 / 共 4 页
字号:
        objAbout = Nothing
    End Sub

    Private Sub newToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles newToolStripButton.Click

        FileNew()
    End Sub

    Private Sub cutToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles cutToolStripButton.Click

        EditCut()
    End Sub

    Private Sub copyToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles copyToolStripButton.Click

        EditCopy()
    End Sub

    Private Sub pasteToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles pasteToolStripButton.Click

        EditPaste()
    End Sub

    Private Sub UndoToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles UndoToolStripButton.Click

        EditUndo()
    End Sub

    Private Sub AddToolStripButton_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles AddToolStripButton.Click

        ActionAdd()
    End Sub

    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"
                Case "Users"
            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
                        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))

⌨️ 快捷键说明

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