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

📄 admin.vb

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

            'Display a message that the record was deleted
            ToolStripStatus.Text = "Record Deleted"
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        End Try
    End Sub
#End Region

#Region " Projects Procedures "
    Private Sub LoadProjects()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Initialize a new instance of the business logic component
        Using objProjects As New WroxBusinessLogic.WBLProjects( _
            strCompany, strApplication)

            Try
                'Clear previous bindings
                lstProjects.DataSource = Nothing
                lstProjects.DisplayMember = String.Empty
                lstProjects.ValueMember = String.Empty

                'Get all projects in a DataSet object
                objProjectsDS = objProjects.GetProjects()

                'Clear previous list
                lvwProjects.Items.Clear()

                'Process all rows
                For intIndex = 0 To objProjectsDS.Tables("Projects").Rows.Count - 1
                    'Create a new listview item
                    objListViewItem = New ListViewItem
                    'Add the data to the listview item
                    objListViewItem.Text = objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectName")
                    objListViewItem.Tag = objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectID")
                    'Add the sub items to the listview item
                    objListViewItem.SubItems.Add(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectDescription"))
                    objListViewItem.SubItems.Add(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("SequenceNumber"))
                    objListViewItem.SubItems.Add(Format(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("LastUpdateDate"), "g"))
                    'Add the listview item to the listview control
                    lvwProjects.Items.Add(objListViewItem)
                Next

                'Rebind ListBox control
                lstProjects.DataSource = objProjectsDS.Tables("Projects")
                lstProjects.DisplayMember = "ProjectName"
                lstProjects.ValueMember = "ProjectID"
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using

        'Cleanup
        objListViewItem = Nothing

    End Sub

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

        'Initialize a new instance of the business logic component
        Using objProjects As New WroxBusinessLogic.WBLProjects( _
            strCompany, strApplication)

            Try
                'Get the specific project selected in the ListView control
                objDataSet = objProjects.GetProject( _
                    New Guid(lvwProjects.SelectedItems.Item(0).Tag.ToString))

                'Populate the Project Details section
                txtProjectID.Text = _
                    objDataSet.Tables("Project").Rows(0).Item( _
                    "ProjectID").ToString.ToUpper
                txtProjectName.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("ProjectName")
                txtProjectDescription.Text = _
                    objDataSet.Tables("Project").Rows(0).Item( _
                    "ProjectDescription")
                txtSequenceNumber.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("SequenceNumber")
                txtProjectUpdateDate.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("LastUpdateDate")

            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using
    End Sub

    Private Sub lstProjects_MouseDown(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles lstProjects.MouseDown

        If e.Button = MouseButtons.Left Then
            lstProjects.DoDragDrop(objProjectsDS.Tables("Projects").Rows( _
                lstProjects.SelectedIndex)("ProjectID").ToString, _
                DragDropEffects.Copy)
        End If
    End Sub

    Private Sub lstGroupProjects_DragEnter(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DragEventArgs) _
        Handles lstGroupProjects.DragEnter

        'Exit if nothing has been selected in the cboGroups ComboBox
        If cboGroups.SelectedIndex = -1 Then
            Exit Sub
        End If

        'Now ensure that the drag content is the correct type for this control
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            'If the item does not already exist then allow the copy
            Dim objDataView As Data.DataView = New _
                Data.DataView(objGroupProjectsDS.Tables("GroupProjects"))
            objDataView.Sort = "ProjectID"
            intIndex = objDataView.Find(e.Data.GetData(DataFormats.Text))
            If intIndex = -1 Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.None
            End If
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub lstGroupProjects_DragDrop(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DragEventArgs) _
        Handles lstGroupProjects.DragDrop

        Dim objDataRow As Data.DataRow
        Dim objDataView As Data.DataView = New _
            Data.DataView(objProjectsDS.Tables("Projects"))
        objDataView.Sort = "ProjectID"
        intIndex = objDataView.Find(e.Data.GetData(DataFormats.Text))
        objDataRow = objGroupProjectsDS.Tables("GroupProjects").NewRow
        objDataRow.Item("ProjectID") = New _
            Guid(e.Data.GetData(DataFormats.Text).ToString)
        objDataRow.Item("ProjectName") = _
            objDataView.Item(intIndex).Item("ProjectName")
        objGroupProjectsDS.Tables("GroupProjects").Rows.Add(objDataRow)
        objGroupProjectsDS.AcceptChanges()
    End Sub

    Private Sub lstGroupProjects_KeyUp(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles lstGroupProjects.KeyUp

        If e.KeyCode = Keys.Delete Then
            objGroupProjectsDS.Tables("GroupProjects").Rows.RemoveAt( _
                lstGroupProjects.SelectedIndex)
            objGroupProjectsDS.AcceptChanges()
        End If
    End Sub
#End Region

#Region " Groups Procedures "
    Private Sub LoadGroups()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Turn the loading flag on so no items are processed
        blnLoading = True

        'Initialize a new instance of the business logic component
        Using objGroups As New WroxBusinessLogic.WBLGroups( _
            strCompany, strApplication)

            Try
                'Clear previous data bindings
                cboGroups.DataSource = Nothing
                cboGroups.DisplayMember = String.Empty
                cboGroups.ValueMember = String.Empty

                'Get all groups in a DataSet object
                objGroupsDS = objGroups.GetGroups()

                'Clear previous list
                lvwGroups.Items.Clear()

                'Process all rows
                For intIndex = 0 To objGroupsDS.Tables("Groups").Rows.Count - 1

                    'Create a new listview item
                    objListViewItem = New ListViewItem

                    'Add the data to the listview item
                    objListViewItem.Text = _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupName")
                    objListViewItem.Tag = _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupID")

                    'Add the sub items to the listview item
                    objListViewItem.SubItems.Add( _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupDescription"))
                    objListViewItem.SubItems.Add( _
                        Format(objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "LastUpdateDate"), "g"))

                    'Add the listview item to the listview control
                    lvwGroups.Items.Add(objListViewItem)

                Next

                'Rebind ComboBox control
                cboGroups.DataSource = objGroupsDS.Tables("Groups")
                cboGroups.DisplayMember = "GroupName"
                cboGroups.ValueMember = "GroupID"

                'Reset the selected index
                cboGroups.SelectedIndex = -1
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using

        'Cleanup
        objListViewItem = Nothing

        'Turn off loading switch
        blnLoading = False
    End Sub

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

        'Initialize a new instance of the business logic component
        Using objGroups As New WroxBusinessLogic.WBLGroups( _
            strCompany, strApplication)

            Try
                'Get the specific Group selected in the ListView control
                objDataSet = objGroups.GetGroup( _
                    New Guid(lvwGroups.SelectedItems.Item(0).Tag.ToString))

                'Populate the Group Details section
                txtGroupID.Text = _
                    objDataSet.Tables("Group").Rows(0).Item( _
                    "GroupID").ToString.ToUpper
                txtGroupName.Text = _
                    objDataSet.Tables("Group").Rows(0).Item("GroupName")
                txtGroupDescription.Text = _
                    objDataSet.Tables("Group").Rows(0).Item("GroupDescription")
                txtGroupUpdateDate.Text = _
                    objDataSet.Tables("Group").Rows(0).Item("LastUpdateDate")
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using
    End Sub

    Private Sub cboGroups_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles cboGroups.SelectedIndexChanged

        'Don't process if the ComboBox is being loaded
        If blnLoading Then
            Exit Sub
        End If

        'Initialize a new instance of the business logic component
        Using objGroups As New WroxBusinessLogic.WBLGroups( _
            strCompany, strApplication)

            Try
                'Clear previous bindings
                lstGroupProjects.DataSource = Nothing
                lstGroupProjects.DisplayMember = String.Empty
                lstGroupProjects.ValueMember = String.Empty

                'Get the Group Projects
                objGroupProjectsDS = objGroups.GetGroupProjects( _
                    New Guid(cboGroups.SelectedItem.Item("GroupID").ToString))

                'Rebind ListBox control
                lstGroupProjects.DataSource = _
                    objGroupProjectsDS.Tables("GroupProjects")
                lstGroupProjects.DisplayMember = "ProjectName"
                lstGroupProjects.ValueMember = "ProjectID"
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using
    End Sub
#End Region
End Class

⌨️ 快捷键说明

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